Back to BlogTutorial

Complete Guide to eSewa & Khalti Integration

Step-by-step guide to integrating Nepal's most popular payment gateways into your web or mobile application.

Rajesh Kumar Yadav

Lead Developer, Tech Procod

Nov 28, 2024 10 min read

Payment gateway integration is one of the most common requirements for Nepali web and mobile applications. This guide covers everything you need to know about integrating eSewa and Khalti.

eSewa Integration

eSewa is Nepal's most popular digital wallet with over 7 million users. Their API supports both web and mobile integrations.

Getting Started with eSewa

First, register as a merchant at merchant.esewa.com.np. You'll receive a merchant code and secret key. For testing, use the sandbox environment at uat.esewa.com.np.

The basic flow is: your server creates a payment request, the user is redirected to eSewa, they authenticate and confirm payment, eSewa redirects back to your success/failure URL, and your server verifies the payment.

eSewa API Implementation

The payment initiation requires a form POST to eSewa's endpoint with parameters including amount, tax amount, total amount, transaction UUID, product code, and HMAC signature. The HMAC signature is crucial for security — it prevents tampering with payment amounts.

After payment, eSewa sends a callback to your server. Always verify the payment server-side using eSewa's verification API before fulfilling the order.

Khalti Integration

Khalti offers a cleaner API experience with better documentation. Their Khalti Checkout v2 is the recommended integration method.

Khalti Setup

Register at admin.khalti.com and get your public and secret keys. Khalti's test credentials are well-documented and easy to use.

The Khalti flow is similar to eSewa but uses a JavaScript SDK for the frontend. Initialize the Khalti checkout with your public key and payment details, handle the success callback, and verify server-side.

Best Practices

Always verify payments server-side — never trust client-side callbacks alone. Store transaction IDs and verify them before fulfilling orders. Implement idempotency to prevent double-charging. Log all payment events for debugging and reconciliation.

Testing

Both eSewa and Khalti provide sandbox environments. Use test credentials extensively before going live. Test failure scenarios as much as success scenarios.

Share this article

Rajesh Kumar Yadav

Lead Developer, Tech Procod

The team at Tech Procod Pvt Ltd builds digital solutions for businesses across Nepal. We specialize in web development, mobile apps, e-commerce, and AI integration.