Open guruprasadc6 opened 5 years ago
i had the same error , though you can fix this by sending the recieved data by POST to another view and saving in that view. I have done the same in this https://github.com/jaswal72/upes-fipi-jigyasa/tree/master/payments
Thanks for the suggestion
On Thu, 21 Mar 2019, 12:31 p.m. Shubham Jaswal, notifications@github.com wrote:
i had the same error , though you can fix this by sending the recieved data by POST to another view and saving in that view. I have done the same in this https://github.com/jaswal72/upes-fipi-jigyasa/tree/master/payments
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/harishbisht/paytm-django/issues/12#issuecomment-475129259, or mute the thread https://github.com/notifications/unsubscribe-auth/AeYIkYQri8_tCkHK0wyrQKEDddC6n2Dwks5vYy4ugaJpZM4cAzjN .
happy 2 help, for any errors feel free to contact.
Yeah sure. Thank you
On Thu, 21 Mar 2019, 12:38 p.m. Shubham Jaswal, notifications@github.com wrote:
happy 2 help, for any errors feel free to contact.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/harishbisht/paytm-django/issues/12#issuecomment-475130510, or mute the thread https://github.com/notifications/unsubscribe-auth/AeYIkT-WV09Lk8OZjhp6pcpI9CSTWc9xks5vYy_0gaJpZM4cAzjN .
Hi I'm facing the same Anonymous User Issue. I'm using social-auth-django to use Google email login in my web app. In the payment view request.user prints correctly the user email ID, but once I get a response from paytm in the response view request.user prints Anonymous User after that I'm sending the received data to another view(add_to_database in my case) as POST (as you suggested). But still, request.user is giving Anonymous User
paytm/views.py
def payment(request): MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY MERCHANT_ID = settings.PAYTM_MERCHANT_ID get_lang = "/" + get_language() if get_language() else ''
CALLBACK_URL = settings.HOST_URL + settings.PAYTM_CALLBACK_URL
order_id = Checksum.__id_generator__()
print('in payment')
print(request.user) #*outputs user emil ID*
if 'amt' in request.session:
bill_amount = request.session['amt']
else:
bill_amount='1'
request.session['amt'] = bill_amount
if bill_amount:
data_dict = {
'MID':MERCHANT_ID,
'ORDER_ID':order_id,
'TXN_AMOUNT': bill_amount,
'CUST_ID':'1111',
'INDUSTRY_TYPE_ID':'Retail',
'WEBSITE': settings.PAYTM_WEBSITE,
'CHANNEL_ID':'WEB',
'CALLBACK_URL':CALLBACK_URL,
}
param_dict = data_dict
param_dict['CHECKSUMHASH'] =
Checksum.generate_checksum(data_dict, MERCHANT_KEY) print(os.getcwd()) user = request.user return render(request,"payment.html",{'paytmdict':param_dict ,'user': user})
return HttpResponse("Bill Amount Could not find. ?bill_amount=10")
@csrf_exempt def add_to_database(request): data_dict = {} if request.method == "POST": print('in recipt') print(request.user) #outputs Anonymous User
data_dict = dict(request.POST.items())
print(data_dict)
#add transaction to database
PaytmHistory.objects.create(user=request.user, **data_dict)
# user = request.user
status = False
# if Paytm_history.objects.filter(user=user, STATUS = 'TXN_SUCCESS'):
# status = True
for key,value in data_dict.items():
if key == 'STATUS' and value == 'TXN_SUCCESS':
status = True
#add order to database
return render(request, "recipt.html", {"paytm": data_dict,
'title': 'Recipt', "status": status})
@csrf_exempt def response(request): print(1) print('in response') print(request.user) #outputs Anonymous User if request.method == "POST": MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY data_dict = {} for key in request.POST: data_dict[key] = request.POST[key] print(data_dict)
verify = Checksum.verify_checksum(data_dict, MERCHANT_KEY,
data_dict['CHECKSUMHASH']) if verify: print(2) print(request) print(request.user)
return render(request,"response.html",{"paytm":data_dict})
else:
return HttpResponse("checksum verify failed")
return HttpResponse(status=200)
response.html
In the above view, adding the user object foreign key to PaymentHistory model is giving an error because request.user becomes anonymous in this view although admin is logged in.