from django.http import HttpResponse,HttpResponseRedirect
from django.template.loader import get_template
from django.template import Context, Template,RequestContext
import datetime
import hashlib
from random import randint
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.views.decorators import csrf
def payment(request):
MERCHANT_KEY = "xxxx"
key="xxxx"
SALT = "xxxx"
PAYU_BASE_URL = "https://sandboxsecure.payu.in/_payment"
action = ''
posted={}
# Merchant Key and Salt provided y the PayU.
for i in request.POST:
posted[i]=request.POST[i]
hash_object = hashlib.sha256(b'randint(0,20)')
txnid=hash_object.hexdigest()[0:20]
hashh = ''
posted['txnid']=txnid
hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10"
posted['key']=key
hash_string=''
hashVarsSeq=hashSequence.split('|')
for i in hashVarsSeq:
try:
hash_string+=str(posted[i])
except Exception:
hash_string+=''
hash_string+='|'
hash_string+=SALT
hashh=hashlib.sha512(hash_string.encode('utf-8')).hexdigest().lower()
action =PAYU_BASE_URL
if(posted.get("key")!=None and posted.get("txnid")!=None and posted.get("productinfo")!=None and posted.get("firstname")!=None and posted.get("email")!=None):
return render_to_response('paymant/payment_form.html',RequestContext(request,{"posted":posted,"hashh":hashh,"MERCHANT_KEY":MERCHANT_KEY,"txnid":txnid,"hash_string":hash_string,"action":"https://test.payu.in/_payment" }))
else:
return render_to_response('paymant/payment_form.html',RequestContext(request,{"posted":posted,"hashh":hashh,"MERCHANT_KEY":MERCHANT_KEY,"txnid":txnid,"hash_string":hash_string,"action":"." }))
@csrf_protect
@csrf_exempt
def payment_success(request):
c = {}
c.update(csrf(request))
status=request.POST["status"]
firstname=request.POST["firstname"]
amount=request.POST["amount"]
txnid=request.POST["txnid"]
posted_hash=request.POST["hash"]
key=request.POST["key"]
productinfo=request.POST["productinfo"]
email=request.POST["email"]
salt="XXXXX"
try:
additionalCharges=request.POST["additionalCharges"]
retHashSeq=additionalCharges+'|'+salt+'|'+status+'|||||||||||'+email+'|'+firstname+'|'+productinfo+'|'+amount+'|'+txnid+'|'+key
except Exception:
retHashSeq = salt+'|'+status+'|||||||||||'+email+'|'+firstname+'|'+productinfo+'|'+amount+'|'+txnid+'|'+key
hashh=hashlib.sha512(retHashSeq).hexdigest().lower()
if(hashh !=posted_hash):
print("Invalid Transaction. Please try again")
else:
print("Thank You. Your order status is ", status)
print("Your Transaction ID for this transaction is ",txnid)
print("We have received a payment of Rs. ", amount ,". Your order will soon be shipped.")
return render_to_response('sucess.html',RequestContext(request,{"txnid":txnid,"status":status,"amount":amount}))
@csrf_protect
@csrf_exempt
def payment_failure(request):
c = {}
c.update(csrf(request))
status=request.POST["status"]
firstname=request.POST["firstname"]
amount=request.POST["amount"]
txnid=request.POST["txnid"]
posted_hash=request.POST["hash"]
key=request.POST["key"]
productinfo=request.POST["productinfo"]
email=request.POST["email"]
salt="XXXX"
try:
additionalCharges=request.POST["additionalCharges"]
retHashSeq=additionalCharges+'|'+salt+'|'+status+'|||||||||||'+email+'|'+firstname+'|'+productinfo+'|'+amount+'|'+txnid+'|'+key
except Exception:
retHashSeq = salt+'|'+status+'|||||||||||'+email+'|'+firstname+'|'+productinfo+'|'+amount+'|'+txnid+'|'+key
hashh=hashlib.sha512(retHashSeq).hexdigest().lower()
if(hashh !=posted_hash):
print("Invalid Transaction. Please try again")
else:
print("Thank You. Your order status is ", status)
print("Your Transaction ID for this transaction is ",txnid)
print("We have received a payment of Rs. ", amount ,". Your order will soon be shipped.")
return render_to_response("Failure.html",RequestContext(request,c))
Hi Folks,
-- I'm using django 1.11 for this project I'm implementing payment gateway of PayuMoney but I'm getting thios error:
context must be a dict rather than RequestContext.
I alreday attach the source code,please let me know what i missed in this code.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6Wb82bGpky2zsUpG2SKcnaaJ7dXeaNafuYKpD0QwF6m6Kw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment