unable to read POST parameters sent by payment gateway

59 views
Skip to first unread message

Sreekanth

unread,
Mar 9, 2020, 4:23:24 PM3/9/20
to Django users

I am unable to read POST parameters sent by payment gateway after payment was processed. Payment gateway redirects to returnUrl (I pass this to payment gateway before payment was processed) with some parameters by POST request.

In url.py

path('cashfreeresponse/',views.cashfree_response, name='cashfree_response'),

in views.py

@csrf_exempt
@login_required
def cashfree_response(request):
    print(request.method)
    if request.method == "POST":
        print('inside post method')
        print(request.POST.get('cf_subReferenceId'))
    if request.method == "GET":
        print('inside get method')
        print(request.GET.get('cf_subReferenceId'))

print(request.method) is showing as GET but it was supposed be POST method also print(request.GET.get('cf_subReferenceId')) and print(request.POST.get('cf_subReferenceId')) are showing as None.

But it looks like payment gateway sending parameters as POST method. When I pass returnUrl as http://127.0.0.1:8000/cashfreeresponse instead of http://127.0.0.1:8000/cashfreeresponse/ ('/' is missing in the first one) then I am getting error as

You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/cashfreeresponse/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.

but I see in my google chrome page that payment gateway sending parameters with POST request. Below image shows parameters sent by payment gateway by POST request

enter image description here

If I change urls.py to

path('cashfreeresponse',views.cashfree_response, name='cashfree_response'),

in settings.py to

APPEND_SLASH = False

and returnUrl to http://127.0.0.1:8000/cashfreeresponse then I am not getting any error but still not receiving any parameters. How do I read those parameters sent by payment gateway by POST request? Here is the documentation for payment gateway.

Naveen Arora

unread,
Mar 12, 2020, 2:39:38 AM3/12/20
to Django users
There is something wrong with URL, you are pushing, try using some other url, append slash, etc.
That may help you :)

Cheers

sercan t.

unread,
Mar 13, 2020, 7:30:51 AM3/13/20
to Django users
Don't send POST to http://127.0.0.1:8000/cashfreeresponse,
Check your views and urls.py or redirect mechanism. Try to send like this ==> http://127.0.0.1:8000/cashfreeresponse/

I simulate on my machine this. I got error like you when send POST request without '/' at the end.


9 Mart 2020 Pazartesi 23:23:24 UTC+3 tarihinde Sreekanth yazdı:
Reply all
Reply to author
Forward
0 new messages