KiraPay API with Next.js
A simple guide to integrate KiraPay API into your Next.js application.
1. Setup Next.js Project
npx create-next-app@latest kirapay-api
cd kirapay-apiWhen prompted, select: ✅ TypeScript ✅ Tailwind CSS ✅ App Router
2. 🔑 API Key Configuration
Create a .env.local file in your project root:
NEXT_PUBLIC_KIRAPAY_API_KEY=your_api_key_hereYou can get your API key from the KiraPay Dashboard.
3. 📦 Create Type Definitions
Create a new file:
src/types/kirapay.ts
export interface CreateLinkRequest {
currency: string;
receiver: string;
price: number;
name: string;
redirectUrl?: string;
}
export interface CreateLinkResponse {
message: string;
data: {
url: string;
};
}
export interface PaymentLink {
_id: string;
code: string;
price: number;
name: string;
url: string;
receiver: string;
createdAt: string;
}
export interface GetLinksResponse {
message: string;
data: {
links: PaymentLink[];
total: number;
page: number;
totalPages: number;
};
}
export interface GetLinkByCodeResponse {
message: string;
data: PaymentLink;
}
export interface Transaction {
_id: string;
transaction_hash: string;
status: "PENDING" | "COMPLETED" | "FAILED" | "CANCELLED";
amount: number;
createdAt: string;
}
export interface GetTransactionsResponse {
message: string;
data: {
transactions: Transaction[];
total: number;
};
}4. ⚙️ API Functions
Create a new file:
src/lib/kirapay-api.ts
🔹 Create Payment Link
Endpoint: POST /link/generate
Authentication: Required (x-api-key header)
Description: Creates a new payment link for accepting crypto payments.
Required Fields:
price: Amount to be paidcurrency: Token symbol (e.g.,USDC,USDT)receiver: Wallet address to receive paymentname: Description or name for the payment link
Optional Field:
redirectUrl: URL to redirect after successful payment
🔹 Get All Payment Links
Endpoint: GET /link
Authentication: Required
Description: Retrieves all payment links created by your account with pagination.
Query Parameters:
page— Page number (default: 1)limit— Items per page (default: 10)
🔹 Get Payment Link by Code
Endpoint: GET /link/{code}
Authentication: ❌ Not required (Public endpoint)
Description: Fetches payment link details using its unique code.
Use Case: Display payment details to customers before they pay.
🔹 Get Transactions
Endpoint: GET /wallet/transactions
Authentication: Required (x-api-key header)
Description: Retrieves all transaction history including blockchain details and status.
✅ Complete API File
5. 💻 Create Simple UI
Create: src/app/page.tsx
6. ▶️ Run the Application
Visit 👉 http://localhost:3000 Click the Create Payment Link button to test.
📘 API Endpoints Summary
/link/generate
POST
✅ Yes
Create new payment link
/link
GET
✅ Yes
Get all payment links with pagination
/link/{code}
GET
❌ No
Get payment link details by code
/wallet/transactions
GET
✅ Yes
Get wallet transaction history
Please refer to the API Documentation for more details.
Last updated
Was this helpful?