Secure • Scalable • Production-Ready Payment Integration
This solution provides a complete Razorpay payment gateway integration for ASP.NET applications using C#. It follows Razorpay’s official architecture and is designed for real-world production systems.
This section explains what happens during a payment, from initiation to final confirmation.
User clicks the Pay Now button.
Server generates Razorpay Order ID.
Hosted secure payment UI opens.
User completes payment.
Server verifies payment authenticity.
Database update and email notification.
This section explains how an end user (developer) can integrate Razorpay payments into an ASP.NET project from start to finish. It describes what happens at each stage and why each step is required.
The integration strictly follows Razorpay’s recommended server-side payment architecture to ensure security, reliability, and compliance.
The first step is to create a Razorpay account. This account is used to manage payments, view transactions, and generate API credentials.
Test Mode allows you to simulate payments without real money.
Razorpay provides two credentials: Key ID and Key Secret. These are used by your ASP.NET server to communicate securely with Razorpay APIs.
Important: API keys must never be exposed in client-side JavaScript.
Store Razorpay credentials securely in the
Web.config file.
This ensures keys are accessible only to server-side code.
<appSettings>
<add key="RazorpayKeyId" value="rzp_test_xxxxx" />
<add key="RazorpayKeySecret" value="xxxxxx" />
</appSettings>
Your ASP.NET code reads these values at runtime.
Razorpay provides an official .NET SDK to simplify API communication.
This SDK is used for order creation and server-side verification.
Order ID generation is the most important step. Every payment must be associated with a unique Razorpay Order.
The order is created on the server because:
// Create Razorpay Order (Server-side)
RazorpayClient client = new RazorpayClient(keyId, keySecret);
var options = new Dictionary<string, object>
{
{ "amount", amountInPaise }, // Example: 50000 = ₹500
{ "currency", "INR" },
{ "receipt", "order_rcpt_001" }
};
Order order = client.Order.Create(options);
string razorpayOrderId = order["id"].ToString();
The generated Order ID is sent to the client to initiate payment.
Razorpay Checkout is opened using Razorpay’s hosted UI. This UI securely handles card, UPI, and wallet details.
Your application:
After payment completion, Razorpay returns:
The server must verify the signature using HMAC SHA256. This ensures the payment response is authentic.
Payments must never be marked successful without signature verification.
Only after successful verification:
If verification fails:
This guarantees consistency between: Razorpay → Application → Database → Email.
Dedicated support is available for setup, configuration, and integration.