Integrating eSewa, Khalti & Dynamic FonePay QR in .NET

Integrating eSewa, Khalti & Dynamic FonePay QR in .NET

Complete guide to integrating eSewa, Khalti and FonePay Dynamic QR in .NET with code examples.

October 16, 2025 · 10 min read

My phone buzzed. It was my brother — CSIT student, second year.

"Dai, 3 days bhayo. Khalti integrate hunna. Project submission Monday ho."

I knew that panic. That specific brand of developer anxiety when the deadline is breathing down your neck and the documentation makes sense… until it doesn't.

The Problem

His screen was a beautiful disaster: 23 Brave tabs open (12 of them AI), Rider with more red squiggles than actual code.

"Dai, documentation ma yo lekheko cha. Tara mildai milena."

I smiled. Not because it was funny. But because I'd been there. We've ALL been there.

The Solution: Nepal.Payments.Gateways

I built a unified payment gateway package that works the same for ALL gateways:

C#
// Step 1: Initialize (same for ALL gateways)
var paymentManager = new PaymentManager(
    paymentMethod: PaymentMethod.Khalti,  // or Esewa, or Fonepay
    paymentVersion: PaymentVersion.V2,
    paymentMode: PaymentMode.Sandbox,
    secretKey: _khaltiSecretKey
);

// Step 2: Create request
var request = new PaymentRequest()
{
    Amount = 1300,
    PurchaseOrderId = "order_" + DateTime.Now.Ticks,
    CustomerInfo = new CustomerInfo
    {
        Name = "Your Customer",
        Email = "customer@email.com",
        Phone = "98XXXXXXXX"
    }
};

// Step 3: Get payment URL and redirect
var response = await paymentManager.InitiatePaymentAsync<dynamic>(request);
return Redirect(response.Data.PaymentUrl);

That's it. Three steps.

Verification? Even Simpler

C#
var response = await paymentManager.VerifyPaymentAsync<dynamic>(pidx);

if (response?.Data is PaymentResponse v)
{
    Console.WriteLine($"Paid: Rs. {v.TotalAmount}");
}

Test Credentials

eSewa Test:

  • Username: 9806800001 (or 2/3/4/5)
  • Password: Nepal@123
  • Token: 123456

Khalti Test:

  • Mobile: 9800000001 (or 2/3/4/5)
  • PIN: 1111
  • OTP: 987654

Get Started

Terminal
dotnet add package Nepal.Payments.Gateways

Visit NuGet to get the package.

If this package saves you even one hour debugging session, if it helps you ship your project on time… Then it was worth rebuilding.

eSewaFonepayKhaltiNepalPayment Gateway
Continues in the chat

Subscribe to Newsletter

Get notified about new articles