From d57e89b5aefbca109a06eb0e9b3850578b15aa25 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Tue, 31 May 2016 21:19:31 +0200 Subject: [PATCH] fix coinify callback --- shop/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shop/views.py b/shop/views.py index e0b1c22f..262c3eed 100644 --- a/shop/views.py +++ b/shop/views.py @@ -100,6 +100,7 @@ class EnsureOrderHasProductsMixin(SingleObjectMixin): request, *args, **kwargs ) + class EnsureOrderHasInvoicePDFMixin(SingleObjectMixin): model = Order @@ -456,16 +457,18 @@ class CoinifyCallbackView(SingleObjectMixin, View): # parse json callbackjson = json.loads(request.body) if callbackjson['event'] == 'invoice_state_change' or callbackjson['event'] == 'invoice_manual_resend': - # get invoice from db + # find coinify invoice in db try: - invoice = CoinifyAPIInvoice.objects.get(id=callbackjson['data']['id']) + coinifyinvoice = CoinifyAPIInvoice.objects.get(invoicejson__id=['data']['id']) except CoinifyAPIInvoice.DoesNotExist: - return HttpResponseBadRequest('bad invoice id') + print "unable to find CoinifyAPIInvoice with id %s" % ['data']['id'] + return HttpResponseBadRequest('bad coinifyinvoice id') # save new invoice payload + invoice = coinifyinvoice.order.invoice invoice.payload = callbackjson['data'] invoice.save() - + # so, is the invoice paid now? if callbackjson['data']['state'] == 'complete': invoice.order.mark_as_paid()