[Django]-Razorpay django integration

3👍

There two way to create the checkout form. Automatic and Manual. I always prefer Manual.U will have more control. The checkout javascript hands over the payment details to a javascript handler function (handler). You can then use the payment id, send it to your back-end & verify the payment as you wish and redirect to what page you want, mostly done by ajax call.

<button id="rzp-button1">Pay</button>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
var options = {
    "key": "YOUR_KEY_ID",
    "amount": "2000", // 2000 paise = INR 20
    "name": "Merchant Name",
    "description": "Purchase Description",
    "image": "/your_logo.png",
    "handler": function (response){
        alert(response.razorpay_payment_id);
        // do an ajax call to backend and capture and verify the payment then 
          //redirect to payment success page.
    },
    "prefill": {
        "name": "Harshil Mathur",
        "email": "harshil@razorpay.com"
    },
    "notes": {
        "address": "Hello World"
    },
    "theme": {
        "color": "#F37254"
    }
};
var rzp1 = new Razorpay(options);

document.getElementById('rzp-button1').onclick = function(e){
    rzp1.open();
    e.preventDefault();
}
</script>

source : Razorpay Docs

2👍

Instead of using default value in form tag in form tag action=”/purchase”

add your custom url in action like, action=”http://{yoururl}”

hope this works for you.

👤mano

0👍

I just started using razorpay, And according to me, what you are asking is redirecting to a specific url after successful payment. You can add a webhook in razorpay, in which razorpay will send you the status and details of the payment, and after checking the status of the response in the given url in webhook, you can then redirect user wherever you want from your function. if this is what you were asking and still have a doubt, feel free to ask.

👤Piyush

0👍

You can achieve in two ways

  1. Add window.location = "URL" in your options code
var options = {
    ....
    "handler": function (response){
        alert(response.razorpay_payment_id);
        alert(response.razorpay_order_id);
        alert(response.razorpay_signature);
        window.location = "URL"

    },
    ...
};
  1. You can add a call back url in the options

*> var options = { ….

           "callback_url":"https://eneqd3r9zrjok.x.pipedream.net/",
      ....      };*

For More check this documentation [https://razorpay.com/docs/payments/server-integration/python/payment-gateway/build-integration/#code-to-add-pay-button][1]

Leave a comment