From ff6af58eda118a9006331e437ad8d77007e848b7 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Tue, 17 May 2016 07:59:42 +0200 Subject: [PATCH] more work on epay callback - add md5valid field to callback model --- shop/models.py | 1 + shop/views.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/shop/models.py b/shop/models.py index 8c6368d0..cbdfb97d 100644 --- a/shop/models.py +++ b/shop/models.py @@ -175,6 +175,7 @@ class EpayCallback(CreatedUpdatedModel, UUIDModel): verbose_name_plural = 'Epay Callbacks' payload = JSONField() + md5valid = models.BooleanField(default=False) class EpayPayment(CreatedUpdatedModel, UUIDModel): diff --git a/shop/views.py b/shop/views.py index 4cea9b5e..f9889102 100644 --- a/shop/views.py +++ b/shop/views.py @@ -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) - - EpayPayment.objects.create( - order=order, - callback=callback, - txnid=query.get('txnid'), - ) + + ### 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)