GatewaysKhalti
Payment Verification
Verify Khalti payments
Payment Verification
The verify() method confirms whether a payment was completed.
Basic Usage
import { khalti } from "@paybridgejs/khalti";
const khaltiClient = new khalti({
secretKey: process.env.KHALTI_SECRET_KEY!,
});
const result = await khaltiClient.verify({
pidx: "payment_id_from_initiation",
});
if (result.status === "Completed") {
console.log("✅ Payment successful!");
console.log("Transaction ID:", result.transaction_id);
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
pidx | string | ✅ | Payment ID from initiation |
Response
{
pidx: "payment_id",
transaction_id: "TXN-123456",
status: "Completed",
total_amount: 10000,
mobile: "9841234567",
fee: 300,
purchase_order_id: "ORDER-123",
purchase_order_name: "Product",
created_at: "2024-01-01T10:00:00Z"
}Payment Statuses
| Status | Meaning | Action |
|---|---|---|
Completed | Payment successful | Deliver product/service |
Pending | Payment processing | Wait and retry |
Expired | Payment link expired | Ask user to try again |
User cancelled | User cancelled | Let user retry |
Handling Different Statuses
const result = await khaltiClient.verify({ pidx });
if (result.status === "Completed") {
// Update database with successful payment
await db.payments.update(pidx, {
status: "completed",
transactionId: result.transaction_id,
});
} else if (result.status === "Pending") {
// Retry later
console.log("Payment still processing...");
} else {
// Payment failed or cancelled
console.log("Payment not completed");
}Best Practices
✅ Always verify on your backend
✅ Store transaction IDs for records
✅ Implement retry logic for pending payments
✅ Update order status after verification
Need help? See Error Handling for troubleshooting.