Skip to content
CodexPal
Developer Guides · Beginner · 3 min read

Plan a Khalti checkout: initiation, return and lookup

Prepare the server-side boundaries and failure tests for KPG-2 without mistaking a browser return for final payment evidence.

By CodexPal Editorial3 min read
A server records an initiated payment reference before performing a lookup and fulfilling an order.

A checkout integration should preserve your own order state even when a customer closes a tab, a network request times out or the provider result arrives later. This guide reviews KPG-2 documentation and proposes an implementation plan, not a tested production Node.js example.

Keep initiation and lookup server-side

Khalti’s reviewed KPG-2 documentation describes server-side initiation, a pidx identifier, a browser return and a lookup operation. It uses paisa for the documented amount field and identifies a successful completed result as Completed.

Use the credentials and environment supplied for your merchant account. Avoid mixing a legacy SDK’s fields with the current web-checkout contract. Keep keys out of browser code and never copy a documentation sample key into a production deployment.

Persist the payment attempt before redirecting

Store your order, exact expected amount, merchant context and provider reference together with the attempt’s state. If initiation fails, retain enough information to explain the failure without recording a successful payment.

A second checkout attempt should not silently replace the evidence from the first. Link both attempts to the order and define what happens if results arrive out of order.

Treat returns and lookups as separate evidence

Validate incoming return data and use the documented authoritative verification flow. Match the result to your stored attempt before changing the order. A status in a query string is not an adequate basis for dispatch.

Keep all provider states explicit in your adapter. A refund, pending result or expiry should not fall through a generic truthy check into the same branch as successful fulfilment.

Test caseExpected application behaviour
Repeated verified resultOne fulfilment event
Mismatched amount or referenceNo automatic fulfilment; review the mismatch
Pending or unavailable lookupPreserve pending/review state
Refund or reversalKeep the original payment evidence and link the correction

Make the operating handover part of the work

Write down where staff find the provider reference and how to investigate an unmatched order. Log references and decisions without exposing keys or unnecessary customer data.

Run your test matrix in the approved sandbox and complete the merchant’s production approval process. The flow described here was checked against public documentation; no live or sandbox transaction is claimed.

Design a reviewable reconciliation workflow →

The takeaway

Keep a durable payment-attempt record, verify through the documented lookup contract and make fulfilment idempotent. Treat operating procedures as part of the integration.

Go to the source

Sources & further reading

Primary references checked on October 18, 2026. Examples and diagrams are illustrative unless stated otherwise.

  1. Khalti — KPG-2 web checkout
Found this useful? Pass it along.