Paybridge
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 verification

Parameters

ParameterTypeRequiredDescription
amountnumberAmount in paisa (1 NPR = 100 paisa)
purchase_order_idstringUnique order ID
purchase_order_namestringProduct/service name
return_urlstringRedirect after payment
website_urlstringYour 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

On this page