more work on epay callback - add md5valid field to callback model

This commit is contained in:
Thomas Steen Rasmussen 2016-05-17 07:59:42 +02:00
parent 1aec9bc4b6
commit ff6af58eda
2 changed files with 17 additions and 7 deletions

View file

@ -175,6 +175,7 @@ class EpayCallback(CreatedUpdatedModel, UUIDModel):
verbose_name_plural = 'Epay Callbacks'
payload = JSONField()
md5valid = models.BooleanField(default=False)
class EpayPayment(CreatedUpdatedModel, UUIDModel):

View file

@ -280,15 +280,24 @@ class EpayCallbackView(View):
)
order = get_object_or_404(Order, pk=query.get('orderid'))
if not validate_epay_callback(query):
if validate_epay_callback(query):
callback.md5valid=True
callback.save()
else:
print "bad epay callback!"
return HttpResponse(status=400)
### epay callback is valid - if the order been paid in full,
### create an EpayPayment object linking the callback to the order
if query['amount'] == order.total * 100:
EpayPayment.objects.create(
order=order,
callback=callback,
txnid=query.get('txnid'),
)
### and mark order as paid
order.paid=True
order.save()
else:
return HttpResponse(status=400)