GatewaysKhalti
Payment Initiation
Initiate Khalti payments
Payment Initiation
The initiate() method creates a new payment session and returns a payment URL.
Basic Usage
import { khalti } from "@paybridgejs/khalti";
const khaltiClient = new khalti({
secretKey: process.env.KHALTI_SECRET_KEY!,
});
const payment = await khaltiClient.initiate({
amount: 10000, // NPR 100 (in paisa)
purchase_order_id: "ORDER-123",
purchase_order_name: "Product Name",
return_url: "https://myapp.com/success",
website_url: "https://myapp.com",
});
console.log(payment.payment_url); // Share with customer
console.log(payment.pidx); // Store for verificationParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
amount | number | ✅ | Amount in paisa (1 NPR = 100 paisa) |
purchase_order_id | string | ✅ | Unique order ID |
purchase_order_name | string | ✅ | Product/service name |
return_url | string | ✅ | Redirect after payment |
website_url | string | ✅ | Your website URL |
Response
{
pidx: "payment_id",
payment_url: "https://khalti.com/checkout/...",
expires_at: "2024-01-01T10:00:00Z",
expires_in: 1800
}Important Notes
- Amount: Always use paisa (NPR 100 = 10,000 paisa)
- Order ID: Must be unique per transaction
- Payment Expiry: Payments expire after 30 minutes
- Backend Only: Always initiate from your backend, never expose the secret key
- Store pidx: Save the payment ID for later verification
Next: Verify Payment - Confirm payment status