← Back to BlogWeb Development

Khalti and eSewa Test Credentials (2026): Sandbox Setup with Working Code

Aryan Pariyar•November 29, 2026•9 min read
Khalti and eSewa Test Credentials (2026): Sandbox Setup with Working Code
Share

Quick answer: Khalti's sandbox uses the test Khalti IDs 9800000000 to 9800000005 with MPIN 1111 and OTP 987654, and your test secret key comes from test-admin.khalti.com. eSewa's ePay v2 sandbox uses the eSewa IDs 9711111111, 9711111112 or 9711111113 with password Nepal@123, token 123456, product code EPAYTEST and secret key 8gBm/:&EnhH.1/q. Full table, working code and the errors you will hit are below.

I'm Aryan Pariyar, a web developer in Nepal, and I wire these two gateways into client checkouts. I checked every value here against Khalti's ePayment docs and eSewa's test credentials page on 29 November 2026, and sent real requests to both sandboxes. One thing changed recently: eSewa's test IDs are now 9711111111/2/3. Older guides, including an earlier version of mine, list 9806800001 to 9806800005, and those no longer match the docs.

Khalti and eSewa test credentials at a glance

Khalti (ePayment, KPG-2)eSewa (ePay v2)
Test wallet IDs9800000000, 9800000001, 9800000002, 9800000003, 9800000004, 98000000059711111111, 9711111112, 9711111113
PasswordNone neededNepal@123
MPIN11111122 (eSewa app only)
OTP or token987654123456
Merchant keylive_secret_key from test-admin.khalti.com (login OTP 987654)Product code EPAYTEST, secret key 8gBm/:&EnhH.1/q
Amount unitPaisa (Rs. 10 = 1000)Rupees

Sandbox endpoints:

  • Khalti, start a payment: POST https://dev.khalti.com/api/v2/epayment/initiate/
  • Khalti, verify: POST https://dev.khalti.com/api/v2/epayment/lookup/ (live base: https://khalti.com/api/v2/)
  • eSewa, payment form: POST https://rc-epay.esewa.com.np/api/epay/main/v2/form (live: epay.esewa.com.np)
  • eSewa, status check: GET https://rc.esewa.com.np/api/epay/transaction/status/ (live: esewa.com.np)

These are public test values, published by Khalti and eSewa for everyone. Your live keys are different and belong on your server only, never in browser code or a Git repository.

Khalti sandbox: step by step

1. Get a test secret key

Sign up as a merchant at test-admin.khalti.com. When it asks for a login OTP, use 987654. Inside the test dashboard, copy the key labelled live_secret_key. The name is confusing, but Khalti's docs say to use the live_secret_key from test-admin for the sandbox, and the live_secret_key from admin.khalti.com for production.

2. Start the payment on your server

Send the order to the initiate endpoint with your key in the Authorization header. The amount is in paisa, and Khalti rejects anything under Rs. 10 (1000 paisa).

// app/api/pay/khalti/route.ts (Next.js), or any Node server
const KHALTI = "https://dev.khalti.com/api/v2"; // https://khalti.com/api/v2 when live

export async function POST(req: Request) {
  const order = await getOrder(req); // your own lookup, never trust a price from the browser

  const res = await fetch(`${KHALTI}/epayment/initiate/`, {
    method: "POST",
    headers: {
      Authorization: `Key ${process.env.KHALTI_SECRET_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      return_url: "https://yoursite.com/payment/khalti",
      website_url: "https://yoursite.com",
      amount: order.total * 100, // rupees to paisa
      purchase_order_id: order.id,
      purchase_order_name: order.title,
    }),
  });
  const data = await res.json();
  if (!res.ok) return Response.json(data, { status: 400 });

  await savePidx(order.id, data.pidx); // you need it to verify later
  return Response.json({ url: data.payment_url }); // send the customer here
}

Khalti answers with a pidx (the payment's ID) and a payment_url. In the sandbox the payment page is on test-pay.khalti.com. Log in there with one of the test Khalti IDs, MPIN 1111 and OTP 987654.

3. Verify with lookup before you mark the order paid

After payment, Khalti sends the customer to your return_url with pidx, status, transaction_id, amount and purchase_order_id in the query string. Treat those as a hint, not proof, since anyone can type that URL. Khalti's own docs say to use the lookup API for the final check:

const res = await fetch(`${KHALTI}/epayment/lookup/`, {
  method: "POST",
  headers: {
    Authorization: `Key ${process.env.KHALTI_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ pidx }),
});
const payment = await res.json();

const order = await getOrderByPidx(pidx);
if (payment.status === "Completed" && payment.total_amount === order.total * 100) {
  await markPaid(order.id, payment.transaction_id);
}
Lookup statusWhat to do
CompletedPaid. Deliver the order.
PendingHold. Don't deliver, check again or contact Khalti.
InitiatedThe customer hasn't paid yet.
ExpiredThe payment link ran out. Start a new payment.
User canceledThe customer backed out. Don't deliver.
Refunded, Partially RefundedMoney went back. Don't deliver.

Only Completed means paid. Khalti's sample response gives the link 1800 seconds, and the docs say links expire after 60 minutes in production by default, so read expires_in from the response rather than hard-coding a time.

eSewa ePay v2 sandbox: step by step

1. Sign the payment

eSewa doesn't have an initiate API for web checkout. You build a form and post it from the customer's browser to eSewa, with an HMAC SHA256 signature of three fields, in this exact order: total_amount, transaction_uuid, product_code. Make the signature on your server, because the secret key must never reach the browser.

import crypto from "node:crypto";

const sign = (message: string) =>
  crypto.createHmac("sha256", process.env.ESEWA_SECRET_KEY!).update(message).digest("base64");
// sandbox key: 8gBm/:&EnhH.1/q

const fields = {
  amount: "100",
  tax_amount: "0",
  product_service_charge: "0",
  product_delivery_charge: "0",
  total_amount: "100", // amount + tax + service charge + delivery charge
  transaction_uuid: order.id, // unique every time, letters, numbers and hyphens only
  product_code: "EPAYTEST",
  success_url: "https://yoursite.com/payment/esewa/success",
  failure_url: "https://yoursite.com/payment/esewa/failure",
  signed_field_names: "total_amount,transaction_uuid,product_code",
};
const signature = sign(
  `total_amount=${fields.total_amount},transaction_uuid=${fields.transaction_uuid},product_code=${fields.product_code}`
);
// Render a form with these fields plus "signature", method POST,
// action https://rc-epay.esewa.com.np/api/epay/main/v2/form, and submit it.

Every field is required. If you don't charge tax, service or delivery, send 0 for each, and make sure total_amount is exactly the sum. On eSewa's login page use 9711111111, password Nepal@123 and token 123456.

A tip that saves an afternoon: the example signatures printed in eSewa's docs don't match their own test key when you compute them, so don't use those examples to check your code. Post a real form to the sandbox instead. A correct signature redirects to eSewa's login page. A wrong one comes back as {"code":"ES104","message":"Invalid payload signature."}.

2. Check the response signature

After a successful payment, eSewa redirects to your success_url with the result as Base64 encoded JSON, usually in a data query parameter. Decode it and check its signature the same way, using the fields listed in its own signed_field_names. Use the values exactly as received: eSewa can send amounts like "1,000.0", and reformatting them breaks the signature.

const raw = new URL(req.url).searchParams.get("data")!;
const data = JSON.parse(Buffer.from(raw, "base64").toString("utf8"));

const message = data.signed_field_names
  .split(",")
  .map((f: string) => `${f}=${data[f]}`)
  .join(",");
if (sign(message) !== data.signature || data.status !== "COMPLETE") {
  throw new Error("Not a valid eSewa payment");
}

3. Confirm with the status API

The redirect can be faked, so confirm on your server before marking the order paid. Note the host: the status check lives on rc.esewa.com.np in the sandbox, not on rc-epay like the form. Mixing them up is the most common reason this step fails.

const url =
  "https://rc.esewa.com.np/api/epay/transaction/status/" + // https://esewa.com.np/... when live
  `?product_code=EPAYTEST&total_amount=${order.total}&transaction_uuid=${order.id}`;
const status = await fetch(url).then((r) => r.json());

if (status.status === "COMPLETE") await markPaid(order.id, status.ref_id);
StatusMeaning
COMPLETEPaid. Deliver the order.
PENDINGStarted but not finished yet.
AMBIGUOUSStuck in between. Hold and check again.
NOT_FOUNDThe session expired at eSewa.
CANCELEDCancelled or reversed by eSewa.
FULL_REFUND, PARTIAL_REFUNDMoney went back to the customer.

eSewa also says that if you don't get a response within five minutes, you should use the status check, and that a customer who doesn't pay within 15 minutes of logging in has to start again. A small scheduled job that re-checks unfinished orders catches the customers who close the tab before the redirect.

eSewa Intent, the newer app option

eSewa's docs now mark a second method, Intent, as recommended. Your server books the payment, gets a deeplink, and the customer pays inside the eSewa app with their MPIN, so it suits mobile apps and phone-first checkouts. In the sandbox it uses product code INTENT with its own test key, which is on the test credentials page, and the endpoints are on rc-checkout.esewa.com.np. For a normal website checkout, ePay v2 above is still the simpler start.

Errors you will probably hit

ErrorCause and fix
Khalti 401, "Authentication credentials were not provided."The Authorization header is missing or has no Key prefix.
Khalti 401, "Invalid token."Wrong key, or a test key sent to the live API (or the other way round).
Khalti "Amount should be greater than Rs. 10"You sent rupees instead of paisa, or a test amount under 1000 paisa.
Khalti "Amount Breakdown mismatch."The amount_breakdown lines don't add up to amount.
eSewa ES104, "Invalid payload signature."Wrong field order in the message, a changed amount after signing, or the wrong secret key.
eSewa test login failsYou're using the old 98068000xx IDs. Use 9711111111/2/3.
eSewa status check returns nothing usefulYou called rc-epay instead of rc.esewa.com.np, or the total_amount or transaction_uuid differs from what you signed.

Going live

  • Khalti: get your merchant account approved at admin.khalti.com, switch the base URL to khalti.com/api/v2 and use the live_secret_key from the live dashboard.
  • eSewa: eSewa issues your live product code and secret key after your test transactions succeed. Switch the form to epay.esewa.com.np and the status check to esewa.com.np. Payments then show up in your merchant wallet at merchant.esewa.com.np.
  • Keep test and live keys in separate environment variables, so a test key can't end up in the live checkout.
  • Run one small real payment on each gateway after the switch, and refund it.

If you're a business owner rather than a developer, my guide to eSewa and Khalti payment integration covers merchant accounts, fees and what to ask your developer. And if you'd rather have it done, I build checkouts with server-side verification as part of website development in Nepal and mobile app development.

Frequently asked questions

What are the Khalti test credentials?

Use any test Khalti ID from 9800000000 to 9800000005, MPIN 1111 and OTP 987654. Your test secret key is the live_secret_key in your sandbox dashboard at test-admin.khalti.com, where the login OTP is also 987654.

What are the eSewa test credentials?

eSewa ID 9711111111, 9711111112 or 9711111113, password Nepal@123, token 123456 and MPIN 1122 for the app. For ePay v2 the test product code is EPAYTEST and the secret key is 8gBm/:&EnhH.1/q.

What is the Khalti sandbox URL?

The sandbox API base is https://dev.khalti.com/api/v2/, with payments started at /epayment/initiate/ and verified at /epayment/lookup/. The live base is https://khalti.com/api/v2/.

What is the eSewa test URL?

In the sandbox, the payment form posts to rc-epay.esewa.com.np at /api/epay/main/v2/form, and the status check is on rc.esewa.com.np at /api/epay/transaction/status/. Live, the hosts are epay.esewa.com.np and esewa.com.np.

Why is my eSewa signature invalid?

The signed message must list total_amount, transaction_uuid and product_code in that order, each as name=value, joined by commas with no spaces, then signed with HMAC SHA256 and Base64 encoded. Any change to the amount after signing, or the wrong key, gives error ES104.

Is Khalti's amount in rupees or paisa?

Paisa. Multiply rupees by 100, so Rs. 100 is 10000. Khalti rejects amounts under Rs. 10 (1000 paisa). eSewa uses rupees.

Aryan Pariyar

Aryan Pariyar

Web developer in Nepal, working with global companies across the Netherlands, UK and Australia. 100+ websites shipped, AI ad creatives generating thousands of sales, and 1,000+ students trained.

More about me →
Share

Have a project in mind?

Let's turn your idea into something premium.

Aryan Pariyar

Let's build it together!

Contact Now

Not sure where to start?

Tell me about your project and I'll get back within 24 hours.

Enjoyed the read?

Let's work together on your next project.