Razorpay Payment Gateway for ASP.NET

Secure  •  Scalable  •  Production-Ready Payment Integration

Server-Side Verification Signature Validation Database Logging Email Notifications
Get Source Code

Product Overview

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.

Functional Aspects – Payment Workflow

This section explains what happens during a payment, from initiation to final confirmation.

Application Preview
1. Payment Initiation

User clicks the Pay Now button.

2. Order Creation

Server generates Razorpay Order ID.

3. Razorpay Checkout

Hosted secure payment UI opens.

4. Payment Completion

User completes payment.

5. Signature Verification

Server verifies payment authenticity.

6. Final Confirmation

Database update and email notification.

Security & Reliability

Technical Aspects – End-to-End Integration Guide

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.


Step 1: Create Razorpay Account

The first step is to create a Razorpay account. This account is used to manage payments, view transactions, and generate API credentials.

  1. Sign up at https://razorpay.com
  2. Log in to the Razorpay Dashboard
  3. Enable Test Mode for development

Test Mode allows you to simulate payments without real money.


Step 2: Generate API Keys

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.


Step 3: Configure API Keys in Web.config

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.


Step 4: Install Razorpay NuGet Package

Razorpay provides an official .NET SDK to simplify API communication.

  1. Open NuGet Package Manager
  2. Search for Razorpay.Api
  3. Install the package

This SDK is used for order creation and server-side verification.


Step 5: Generate Razorpay Order ID (Server-Side)

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.


Step 6: Open Razorpay Checkout (Client-Side)

Razorpay Checkout is opened using Razorpay’s hosted UI. This UI securely handles card, UPI, and wallet details.

Your application:


Step 7: Verify Payment Signature (Server-Side)

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.


Step 8: Save Transaction & Send Emails

Only after successful verification:

If verification fails:

This guarantees consistency between: Razorpay → Application → Database → Email.

Need Help or Customization?

Dedicated support is available for setup, configuration, and integration.