How to Integrate Razorpay Payment Gateway in Website

Integrating Payment Gateway in website is a typical stuff and may cause some serious issue if not done in secure manner. When i was doing this , I have no idea and also there is no one to help me out. So, I decided that this thing will not happen to you.

SOURCE CODE

CHECKOUT PAGE [DESIGN PAGE]

<form action="RazorpayCallBack.aspx" method="post">
        <script
            src="https://checkout.razorpay.com/v1/checkout.js"
            data-key="key"
            data-amount="<%=amount%>"
            data-name="<%=name%>"
            data-description="<%=product%>"
            data-order_id="<%=orderId%>"
            data-image="https://razorpay.com/favicon.png"
            data-buttontext="Pay with Razorpay"
            data-prefill.name="<%=name%>"
            data-prefill.email="<%=email%>"
            data-prefill.contact="<%=contact%>"
            data-theme.color="#F37254">
        </script>
    </form>

CHECKOUT PAGE

using Razorpay.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RazorpayCheckout : System.Web.UI.Page
{
	public string orderId;
	public string amount;
	public string contact;
	public string name;
	public string product;
	public string email;

	protected void Page_Load(object sender, EventArgs e)
	{
		amount = (Convert.ToInt32(Request.QueryString["Amount"]) * 100).ToString();
		contact = Request.QueryString["Contact"].ToString();
		name = Request.QueryString["Name"].ToString();
		product = Request.QueryString["Product"].ToString();
		email = Request.QueryString["Email"].ToString();

		Dictionary<string, object> input = new Dictionary<string, object>();
		input.Add("amount", amount);
		input.Add("currency", "INR");
		input.Add("payment_capture", 1);

		string key = "key";
		string secret = "secret";

		RazorpayClient client = new RazorpayClient(key, secret);

		Razorpay.Api.Order order = client.Order.Create(input);
		orderId = order["id"].ToString();

	}
}

CALLBACK PAGE

using Razorpay.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RazorpayCallBack : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		try
		{
			string paymentId = Request.Form["razorpay_payment_id"];
			string orderId = Request.Form["razorpay_order_id"];
			string signature = Request.Form["razorpay_signature"];

			string key = "key";
			string secret = "secret";

			RazorpayClient client = new RazorpayClient(key, secret);

			Dictionary<string, string> attributes = new Dictionary<string, string>();

			attributes.Add("razorpay_payment_id", paymentId);
			attributes.Add("razorpay_order_id", orderId);
			attributes.Add("razorpay_signature", signature);

			Utils.verifyPaymentSignature(attributes);
			pTxnId.InnerText = paymentId;
			pOrderId.InnerText = orderId;
			h1Message.InnerText = "Transaction Successfull";
		}
		catch (Exception)
		{
			h1Message.InnerText = "Transaction Unsuccessfull";
		}
	}
}

SOURCE VIDEO

Leave a Reply

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

Back To Top