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 Settings → API Keys → Generate Key to generate the key for the selected mode.
Key Id and
Key Secret appear in a pop-out window as shown below:
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
- Contact Number
- 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
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.
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.