Categories
ASP.NET MVC Payment Gateway

Razorpay integration in ASP.NET MVC

In this blog, We will see how can we add Razorpay payment gateway in the ASP.NET MVC website.

What is a Payment Gateway

An online payment gateway (PG) is a tunnel that connects your bank account to the platform where you need to transfer your money. A PG is a software that authorizes you to conduct an online transaction through different payment modes like net banking, credit card, debit card, UPI, or the many online wallets that are available these days.

How Razorpay works ?

Razorpay Payment gateway has a very straightforward way of accepting payments and getting paid. It is one of the easiest payment gateway available out there to integrate into your website.

Razorpay integration steps

1 . Generate API Keys

Log into your Dashboard with appropriate credentials. Select the mode (Test or Live) for which you want to generate the API key.

Navigate to SettingsAPI Keys → Generate Key to generate the key for the selected mode.

The Key Id and Key Secret appear in a pop-out window as shown below:

generate-api-keys

2 . Install Razorpay Nuget package

Open the Nuget package manager in your project and type Razorpay. You can see the Razorpay package available for download. Install the latest version.

3 . Creating an order

When users try to do a payment on your website. You have to create an order to do a payment. For creating order in Razorpay, there are some required details you have to provide for creating order and those are:-

  • Name of the customer
  • Email
  • Contact Number
  • Address
  • Total Amount
  • Receipt Number (will be a unique id which you have to create for every order)

Create an order using below code :

4 . Create a View for payment

In this payment view page, We attach the checkout SDK of Razorpay and then provide the order details to SDK. When this page-load we have to give order details and then automatically click the button for payment initiate. We use javascript for click the button automatically. When Payment done response will come inside the response handler. In the response, we got Razorpay payment Id and Order Id (which we provide in creating order). You can copy the below code :

5 . Creating a Complete Transaction Controller function

After Payment made successfully, our hidden form in the payment page sends payment response on this function. We have to fetch the payment details from the Razorpay server using payment Id. Check the payment status is a success or failure and then redirect the user according to the payment status. Use the below code to verify the payment.

In this tutorial, I send the user to success or failure page according to Transaction status. You can change it according to your need.

Conclusion

I hope, now you can integrate the Razorpay into your project easily. If you don’t understand something in this blog or you got an error in code, You can watch a Razorpay integration video tutorial which will help you.

You can download code from here – click here

I would like to hear your thoughts or suggestions in the comment section.

2 replies on “Razorpay integration in ASP.NET MVC”

Hi,

Can you please share github URL for complete source code.
Seems you forget to create link to below text on your blog, which is not working.

Thanks in advance.

You can download code from here – click here

Leave a Reply

Your email address will not be published. Required fields are marked *