def result request if request POST punter Punter objects get pk reques

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def result(request):
if request.POST:
punter = Punter.objects.get(pk=request.POST['punter_id'])
recipient_purse = request.POST['LMI_PAYEE_PURSE']
sender_keeper, created = Keeper.objects.get_or_create(wmid=request.POST['LMI_PAYER_WM'], punter=punter)
sender_purse, created = Purse.objects.get_or_create(number=request.POST['LMI_PAYER_PURSE'], keeper=sender_keeper)
amount = Decimal(request.POST['LMI_PAYMENT_AMOUNT'])
payment_number = int(request.POST['LMI_PAYMENT_NO'])
mode = int(request.POST['LMI_MODE'])
wm_invoice_number = int(request.POST['LMI_SYS_INVS_NO'])
wm_payment_number = int(request.POST['LMI_SYS_TRANS_NO'])
wm_hash = request.POST['LMI_HASH']
date = datetime.strptime(request.POST['LMI_SYS_TRANS_DATE'], "%Y%m%d %H:%M:%S")
key = "%s%s%s%s%s%s%s%s%s%s" % (recipient_purse, amount, payment_number, mode, wm_invoice_number,
wm_payment_number, request.POST['LMI_SYS_TRANS_DATE'], STORE_SECRET_KEY,
request.POST['LMI_PAYER_PURSE'], request.POST['LMI_PAYER_WM'])
if md5.new(key).hexdigest().upper() == wm_hash:
payment = Payment(
recipient_purse=recipient_purse, sender_purse=sender_purse, sender_keeper=sender_keeper,
amount=amount, payment_number=payment_number, mode=mode, wm_invoice_number=wm_invoice_number,
wm_payment_number=wm_payment_number, wm_hash=wm_hash, date = date
)
payment.save()
return HttpResponse("OK")