So basically, razorpay popup is opening, payment being success but the callback url isn't getting called:
var options = {
"key": data.razorpay_key,
"amount": data.amount,
"currency": data.currency,
"name": "BusinessCard4U",
"image": "{{websitelogo.image.url}}",
"description": "Payment for digital card subscription",
"order_id": data.razorpay_order_id,
"callback_url": "{% url 'PaymentSuccess' %}",
"handler": function (response){
// Handle Razorpay success callback
},
"theme": {
"color": "#5EB9F0"
},
};
This is data i am passing... it has callback url as you can see... but neither anything is getting printed, nor it's being called. I tried using redirect: true variable to see if that works but that made the payment failed.
Thank You!
As per my knowledge {% url 'PaymentSuccess' %}
template tag in Django generates a relative URL, and in callback_url of Razor Pay you need an Absolute URL, URL something like this(change as per your configuration) "http://127.0.0.1:8000/razorpay/success/".
So, First, try it by providing a static Absolute URL("callback_url": "http://127.0.0.1:8000/razorpay/success/"
) and test the payment process whether it works as you expected If it works you can create the dynamic callback_url.
your views must be look something like below:
Also, make sure that you have handled the POST request method. as Razor Pay call back URL has it's method and parameters as shown in documentation(https://razorpay.com/docs/payments/payment-gateway/callback-url/)
try like below:
var options = {
... // existing options
callback_url: 'http://127.0.0.1:8000/payment-success/' // adjust URL as per your configuration,
redirect: true
}
Cross-verify that your view looks like something.
@csrf_exempt
def callback(request):
if "razorpay_signature" in request.POST:
# If payment is successful
payment_id = request.POST.get("razorpay_payment_id", "")
provider_order_id = request.POST.get("razorpay_order_id", "")
signature_id = request.POST.get("razorpay_signature", "")
# your further code
return render("#your page redirect")
else:
payment_id = json.loads(request.POST.get("error[metadata]")).get("payment_id")
# your further code
return render("#your page redirect")