Integrating eSewa, Khalti Payment & Dynamic Fonepay QR Gateways in .NET Applications
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:
// 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: <em>khaltiSecretKey
);</p><p>// Step 2: Create request
var request = new PaymentRequest()
{
Amount = 1300,
PurchaseOrderId = "order</em>" + DateTime.Now.Ticks,
CustomerInfo = new CustomerInfo
{
Name = "Your Customer",
Email = "customer@email.com",
Phone = "98XXXXXXXX"
}
};</p><p>// 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
var response = await paymentManager.VerifyPaymentAsync<dynamic>(pidx);</p><p>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
- Mobile:
9800000001(or 2/3/4/5) - PIN:
1111 - OTP:
987654
Get Started
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.
Tags
Subscribe to Newsletter
Get notified about new articles