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)