
eSewa and Khalti Payment Integration for Your Website (2026): Merchant Setup, API Steps, Test Keys & Code
Last checked: 24 November 2026 against eSewa ePay v2 and Khalti KPG-2 developer documentation.
If your Nepali website still says "send a screenshot after payment", you are losing orders at night, on weekends and every time a customer gets bored waiting for you to reply. eSewa and Khalti payment integration fixes that: the customer pays inside the wallet, your server checks the payment with eSewa or Khalti, and the order confirms itself.
This guide covers the whole job, not just the code. You will see the merchant documents each wallet asks for, the new e-commerce listing rule, the exact API fields, sandbox test accounts, working code in PHP and Node.js, the no-code WordPress route, and the mistakes that cause most failed integrations.
Quick answer
- Open a merchant account with each wallet (business registration, PAN/VAT and tax clearance are the core documents).
- eSewa (ePay v2): your page POSTs a signed HTML form to eSewa. The signature is an HMAC-SHA256 of
total_amount,transaction_uuidandproduct_code. - Khalti (KPG-2): your server POSTs JSON to the initiate API with your secret key, gets a
payment_url, and redirects the customer there. Amounts are in paisa. - After the customer returns, always confirm the payment with the eSewa status API or the Khalti lookup API before you mark the order paid.
- On WordPress/WooCommerce you can skip coding and use a plugin, but you still need your own merchant accounts.
In this guide
- eSewa vs Khalti integration at a glance
- Before you start: the legal checklist
- Getting a merchant account (documents)
- How the payment flow works
- eSewa ePay v2 integration, step by step
- Khalti KPG-2 integration, step by step
- Sandbox test credentials
- WordPress and WooCommerce: the no-code route
- Fees and what integration costs
- Common errors and how to fix them
- Go-live checklist
- FAQs
eSewa vs Khalti Integration at a Glance
Both wallets use a redirect flow: the customer leaves your site, pays on the wallet’s hosted page and comes back. The way you start the payment is different, and that difference shapes your code.
| Item | eSewa (ePay v2) | Khalti (KPG-2) |
|---|---|---|
| How payment starts | Browser POSTs an HTML form to eSewa | Server POSTs JSON to the initiate API, then redirects to payment_url |
| Security | HMAC-SHA256 signature, Base64 encoded | Authorization: Key <secret_key> header |
| Amount unit | Rupees | Paisa (Rs. 1 = 100 paisa) |
| Minimum amount | Not stated in the docs | Rs. 10 (1000 paisa) |
| Return data | Base64 JSON in a data parameter on your success URL | Query parameters on your return_url (GET) |
| Verification | Transaction status API (GET) | Lookup API (POST with pidx) |
| Only safe success state | COMPLETE | Completed |
| Payment link life | Not stated in the docs | 60 minutes in production by default |
| Public sandbox | Yes, shared code EPAYTEST | Yes, your own test key from test-admin.khalti.com |
If you are still deciding which wallet your customers prefer, our eSewa vs Khalti vs IME Pay comparison covers user fees and limits. For most shops the practical answer is to offer both: the extra work after the first one is small.
Before You Start: The Legal Checklist Most Guides Skip
Code is the easy part. Most delays come from paperwork, and since 2026 there is one more rule to follow.
- Register the business. Both wallets need a registered business before they release live keys or let you withdraw money. A sole proprietorship is the fastest route; our sole proprietorship vs private limited guide explains both.
- Get PAN/VAT. A PAN certificate is on every document list. See how to register for PAN online.
- List your site on the e-commerce portal. The Department of Commerce, Supply and Consumer Protection has told businesses selling online to register their platforms with it, following the E-Commerce Act 2081 and the E-Commerce Directive 2082.
- Use an approved gateway. Under the directive, online businesses must use digital payment gateways approved by Nepal Rastra Bank for commercial transactions. Personal wallet QR codes for a business are the thing to move away from.
- Issue proper bills. A paid order still needs a valid invoice. If you are VAT-registered, read the Nepal VAT e-billing guide.
Tip: start the merchant application the same week you start building the checkout. Approval can take days or weeks, and a finished checkout that waits for live keys earns nothing.
Step 1: Get an eSewa and a Khalti Merchant Account
You can start eSewa onboarding online at merchant.esewa.com.np or visit the eSewa head office. Khalti merchant sign-up is self-service at khalti.com/merchant, where you fill the business KYC in the merchant dashboard.
| Business type | eSewa asks for | Khalti asks for |
|---|---|---|
| Sole proprietorship (Rs. 1 lakh+ a year) | Firm registration, PAN/VAT, business licence if any, proprietor’s citizenship, latest tax clearance | Banijya/Udhyog registration certificate, PAN/VAT |
| Small sole proprietor (under Rs. 1 lakh a year) | Registration if any, ward office or local authority letter confirming the business, citizenship, personal PAN | Same as above |
| Partnership firm | Partnership certificate and deed, firm PAN, partners’ citizenship, tax clearance, address proof, KYM form | Registration certificate, PAN/VAT |
| Private or public limited | Incorporation certificate, PAN/VAT, MOA/AOA, board minute, directors’ citizenship, tax clearance, KYM form | Company registration, PAN/VAT, MOA/AOA, latest tax clearance, shareholders’ ID, board consent letter |
Khalti lets you integrate and test before your documents are approved, but you cannot withdraw collected money to your bank until every document is uploaded. eSewa says its list is a general reference and may ask for more depending on your category.
How the Payment Flow Works
Every safe wallet integration in Nepal follows the same five steps. The fifth one is the step people skip, and it is the one that stops fraud.
Figure 1: The redirect-and-verify flow used by both eSewa and Khalti.
Why step 5 matters: a redirect is just a URL in the customer’s browser. Anyone can type your success URL with made-up values. Khalti says plainly that the callback is not final proof of payment and that it is not liable for losses if you provide the service without checking the lookup status.
eSewa Payment Integration (ePay v2), Step by Step
Endpoints
| Purpose | Test (sandbox) | Production |
|---|---|---|
| Payment form (POST) | https://rc-epay.esewa.com.np/api/epay/main/v2/form | https://epay.esewa.com.np/api/epay/main/v2/form |
| Status check (GET) | https://rc.esewa.com.np/api/epay/transaction/status/ (older docs show uat.esewa.com.np) | https://epay.esewa.com.np/api/epay/transaction/status/ |
Form fields
| Field | What to send |
|---|---|
amount | Product price |
tax_amount | Tax on the product (0 if none) |
product_service_charge | Your service charge (0 if none) |
product_delivery_charge | Delivery charge (0 if none) |
total_amount | amount + tax_amount + product_service_charge + product_delivery_charge |
transaction_uuid | Your unique order ID. Keep it to letters, numbers and hyphens |
product_code | Merchant code from eSewa (EPAYTEST in sandbox) |
success_url / failure_url | Absolute URLs on your site |
signed_field_names | total_amount,transaction_uuid,product_code |
signature | Base64 HMAC-SHA256 of the signed fields, made with your secret key |
Generate the signature on your server
Join the signed fields in the same order as signed_field_names, as name=value pairs separated by commas, with no spaces. Then HMAC-SHA256 that string with your secret key and Base64-encode the raw result.
// PHP
$secret = getenv('ESEWA_SECRET_KEY'); // sandbox: 8gBm/:&EnhH.1/q
$total = '110';
$uuid = 'ORD-1042-' . time();
$code = 'EPAYTEST';
$message = "total_amount={$total},transaction_uuid={$uuid},product_code={$code}";
$signature = base64_encode(hash_hmac('sha256', $message, $secret, true));
// Node.js
const crypto = require('crypto');
const message = `total_amount=${total},transaction_uuid=${uuid},product_code=${code}`;
const signature = crypto
.createHmac('sha256', process.env.ESEWA_SECRET_KEY)
.update(message)
.digest('base64');Send the customer to eSewa
Print a form with hidden fields and submit it, either on a button click or automatically.
<form action="https://rc-epay.esewa.com.np/api/epay/main/v2/form" method="POST"> <input type="hidden" name="amount" value="100"> <input type="hidden" name="tax_amount" value="10"> <input type="hidden" name="product_service_charge" value="0"> <input type="hidden" name="product_delivery_charge" value="0"> <input type="hidden" name="total_amount" value="110"> <input type="hidden" name="transaction_uuid" value="ORD-1042-1795491075"> <input type="hidden" name="product_code" value="EPAYTEST"> <input type="hidden" name="success_url" value="https://yoursite.com/esewa/success"> <input type="hidden" name="failure_url" value="https://yoursite.com/esewa/failure"> <input type="hidden" name="signed_field_names" value="total_amount,transaction_uuid,product_code"> <input type="hidden" name="signature" value="SIGNATURE_FROM_SERVER"> <button type="submit">Pay with eSewa</button> </form>
Handle the success redirect
After payment, eSewa sends the customer to your success_url with a data parameter. It is Base64-encoded JSON containing transaction_code, status, total_amount, transaction_uuid, product_code, signed_field_names and signature.
// Node.js (Express)
app.get('/esewa/success', async (req, res) => {
const d = JSON.parse(Buffer.from(req.query.data, 'base64').toString('utf8'));
// 1. Rebuild the message from the fields eSewa says it signed
const msg = d.signed_field_names.split(',')
.map(f => `${f}=${d[f]}`).join(',');
const expected = crypto.createHmac('sha256', process.env.ESEWA_SECRET_KEY)
.update(msg).digest('base64');
if (expected !== d.signature) return res.status(400).send('Bad signature');
// 2. Never trust the redirect alone: ask eSewa (step below)
// 3. Compare amount and uuid with YOUR order record, then mark paid
});Verify with the status API
Call the status endpoint with product_code, total_amount and transaction_uuid. Use the amount from your own database, not from the redirect.
GET https://rc.esewa.com.np/api/epay/transaction/status/?product_code=EPAYTEST&total_amount=110&transaction_uuid=ORD-1042-1795491075
{ "product_code": "EPAYTEST", "transaction_uuid": "ORD-1042-1795491075",
"total_amount": 110.0, "status": "COMPLETE", "ref_id": "0001TS9" }| eSewa status | Meaning | What your site should do |
|---|---|---|
COMPLETE | Paid | Mark paid, deliver |
PENDING | Started, not finished | Hold, check again later |
AMBIGUOUS | Unclear state | Hold, contact eSewa |
FULL_REFUND / PARTIAL_REFUND | Money returned | Do not deliver; update order |
NOT_FOUND / CANCELED | No valid payment | Mark failed |
Khalti Payment Integration (KPG-2), Step by Step
Khalti’s web checkout needs no SDK. It is two server-side POST requests: one to start the payment and one to confirm it. Use the secret key from test-admin.khalti.com for sandbox and from admin.khalti.com for production.
| API | Sandbox | Production |
|---|---|---|
| Initiate (POST) | https://dev.khalti.com/api/v2/epayment/initiate/ | https://khalti.com/api/v2/epayment/initiate/ |
| Lookup (POST) | https://dev.khalti.com/api/v2/epayment/lookup/ | https://khalti.com/api/v2/epayment/lookup/ |
1. Initiate the payment
Required fields are return_url, website_url, amount (in paisa), purchase_order_id and purchase_order_name. You can also send customer_info, an amount_breakdown that must add up to amount, and product_details.
// Node.js 18+
const r = await fetch('https://dev.khalti.com/api/v2/epayment/initiate/', {
method: 'POST',
headers: {
'Authorization': 'Key ' + process.env.KHALTI_SECRET_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
return_url: 'https://yoursite.com/khalti/return',
website_url: 'https://yoursite.com',
amount: 110 * 100, // Rs. 110 = 11000 paisa
purchase_order_id: 'ORD-1042',
purchase_order_name: 'Order 1042',
customer_info: { name: 'Ram Sharma', phone: '9800000001' }
})
});
const { pidx, payment_url } = await r.json();
// save pidx against the order, then redirect the customer to payment_url
// PHP (cURL)
$ch = curl_init('https://dev.khalti.com/api/v2/epayment/initiate/');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Key ' . getenv('KHALTI_SECRET_KEY'),
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'return_url' => 'https://yoursite.com/khalti/return',
'website_url' => 'https://yoursite.com',
'amount' => 11000,
'purchase_order_id' => 'ORD-1042',
'purchase_order_name' => 'Order 1042'
])
]);
$res = json_decode(curl_exec($ch), true);
header('Location: ' . $res['payment_url']);2. Read the return URL
Khalti redirects to your return_url with a GET request carrying pidx, status, transaction_id, amount, mobile, purchase_order_id and purchase_order_name. A cancelled payment may arrive with an empty transaction_id and mobile. Treat all of this as a hint only.
3. Confirm with the lookup API
POST https://dev.khalti.com/api/v2/epayment/lookup/
Authorization: Key YOUR_SECRET_KEY
Content-Type: application/json
{ "pidx": "bZQLD9wRVWo4CdESSfuSsB" }
// response includes: pidx, total_amount, status, transaction_id, fee, refunded
// deliver only if status === "Completed" AND total_amount === your order amount in paisa| Khalti status | HTTP | What your site should do |
|---|---|---|
Completed | 200 | Mark paid, deliver |
Pending / Initiated | 200 | Hold, contact Khalti |
Partially Refunded | 200 | Hold, contact Khalti |
Refunded | 200 | Do not deliver |
Expired / User canceled | 400 | Mark failed |
Sandbox Test Credentials
These are the public test accounts published for developers. They only work on the sandbox URLs above and move no real money.
eSewa sandbox
- eSewa ID: 9806800001 to 9806800005
- Password: Nepal@123
- MPIN: 1122 (mobile app only)
- Token/OTP: 123456
- Product code: EPAYTEST
- Secret key: 8gBm/:&EnhH.1/q
Khalti sandbox
- Khalti ID: 9800000000 to 9800000005
- MPIN: 1111
- OTP: 987654
- Merchant sign-up OTP (test-admin): 987654
- Secret key: your own, from test-admin.khalti.com
WordPress and WooCommerce: The No-Code Route
If your shop runs on WooCommerce, a plugin does all of the above for you. You paste your merchant code and keys, switch off sandbox mode and you are live.
- Nepal Payments for WooCommerce (free): adds eSewa ePay v2, Khalti KPG-2, connectIPS and NIC Asia cards in one plugin. It verifies payments server-side, puts orders on hold if the amount does not match, and supports the Blocks checkout and HPOS. It is new and has few installs, so test it well. Your store currency must be NPR for the gateways to show.
- The eSewa plugin on WordPress.org: a single-gateway option where you add your live merchant code and secret key, or the test code for sandbox.
- Refunds: plugins usually do not push refunds through the wallet APIs. You refund from the eSewa or Khalti merchant dashboard.
Whichever plugin you pick, check its last update date, read its support threads and do a full test order (including a cancelled one) before going live. A plugin is only as safe as its verification step. Good hosting also matters, since a slow or timing-out server can leave orders stuck in "pending"; see our web hosting price guide for Nepal.
Fees and What Integration Costs
Neither wallet publishes a standard merchant commission rate. The rate is set in your merchant agreement and depends on your business category and volume. What we could confirm:
- Khalti: its merchant terms mention a one-time API fee at signing and an annual account maintenance charge from the second year. The transaction fee is deducted from your merchant balance in real time.
- eSewa: payments land in a merchant wallet, and you are notified by email or SMS for each successful transaction. Ask for the commission and settlement terms in writing before you sign.
- Sandbox testing costs nothing on either wallet.
- Developer cost: one Kathmandu agency quotes about Rs. 15,000 to 35,000 per gateway to add eSewa or Khalti to an existing WordPress site. Custom checkouts cost more. For context on rates, see hiring a freelance web developer in Nepal and website design cost in Nepal.
Questions to ask before you sign the merchant agreement
Common Errors and How to Fix Them
These are the problems that come up again and again in developer forums and support threads for both gateways.
| Problem | Likely cause | Fix |
|---|---|---|
| eSewa: invalid signature | Field order, spaces, or a value in the message that differs from the form (110 vs 110.00) | Sign exactly the strings you post, in the order of signed_field_names |
| eSewa: response signature never matches | Reformatting the returned amount (it can arrive as "1,000.0") | Use each value exactly as decoded; do not convert to a number first |
| eSewa: total rejected | total_amount is not the sum of the four parts | Calculate the total on the server from the parts |
| Khalti: 401 "Authentication credentials were not provided" | Header missing the Key prefix | Send Authorization: Key your_secret |
| Khalti: 401 "Invalid token" | Test key on live URL, or the reverse | Match test-admin keys with dev.khalti.com, admin keys with khalti.com |
| Khalti: validation_error on amount | Sent rupees, a decimal, or less than Rs. 10 | Send a whole number in paisa, 1000 or more |
| Duplicate orders or double delivery | Customer refreshes the success page | Make the handler idempotent: if the order is already paid, just show the receipt |
| Paid in wallet, order still pending | Customer closed the tab before the redirect | Run a scheduled job that re-checks pending orders with the status or lookup API |
Security rules that are not optional
- Keep secret keys on the server in environment variables, never in JavaScript, never in Git.
- Never trust the amount or status in the redirect. Compare against your own order record.
- Use HTTPS on every success, failure and return URL.
- Log every request and response so you can settle disputes later.
Go-Live Checklist
Paperwork
- Merchant KYC approved on both wallets
- Live merchant code and secret keys received
- Site listed on the e-commerce portal
- Refund and contact policy pages published
Testing
- Successful payment marks order paid
- Cancelled payment marks order failed
- Edited success URL is rejected
- Refresh does not deliver twice
Switch to live
- Swap sandbox URLs for production
- Swap test keys for live keys
- Make one small real payment and refund it
- Check the money shows in the merchant dashboard
Accepting payments from customers abroad is a different problem; eSewa and Khalti mainly serve Nepali wallet holders. For overseas clients, read freelance payments to Nepal and PayPal in Nepal. For more business setup guides, visit our Business in Nepal hub.
Frequently Asked Questions
Can I integrate eSewa or Khalti without a registered business?
You can build and test with sandbox credentials without one. To go live, both wallets ask for business documents. Khalti lets you collect test payments but blocks bank withdrawals until your documents are uploaded. eSewa has a lighter list for very small sole proprietors under Rs. 1 lakh a year, which uses a ward office letter and personal PAN.
Is Khalti integration easier than eSewa?
Most developers find Khalti simpler because it is plain JSON with an API key and no signature to build. eSewa needs a correctly built HMAC signature, which is where most first attempts fail.
Why does Khalti want the amount in paisa?
Khalti’s API counts money in paisa so it never deals with decimals. Multiply rupees by 100: Rs. 110 becomes 11000. The minimum is 1000 paisa (Rs. 10).
Do I need to verify the payment if the customer reached my success page?
Yes. The success page is only a browser redirect and can be faked. Always call the eSewa status API or the Khalti lookup API from your server and deliver only on COMPLETE (eSewa) or Completed (Khalti).
How much commission do eSewa and Khalti charge merchants?
There is no public standard rate. It is agreed in your merchant contract based on your category and volume. Khalti’s terms also mention a one-time API fee and a yearly maintenance charge from year two. Get the full fee list in writing before signing.
Can I add eSewa and Khalti to WooCommerce without coding?
Yes. Plugins such as Nepal Payments for WooCommerce add both wallets. You still need your own merchant accounts and keys, and your store currency must be NPR.
How do refunds work?
You issue refunds from the eSewa or Khalti merchant dashboard. Refunded payments then show as FULL_REFUND or PARTIAL_REFUND on eSewa, and Refunded or Partially Refunded on Khalti.
Can I use eSewa and Khalti in a mobile app?
Yes. The same flows work inside an app’s web view, and both wallets have mobile SDK options. The verification step still has to run on your server.
Sources checked
eSewa developer documentation (ePay v2) and eSewa merchant document list; Khalti developer documentation (Web Checkout KPG-2), Khalti merchant terms and payment gateway pages; Department of Commerce, Supply and Consumer Protection notices on the E-Commerce Act 2081 and Directive 2082. API details change, so always confirm against the live developer docs before you launch.