fix coinify callback

This commit is contained in:
Thomas Steen Rasmussen 2016-05-31 21:19:31 +02:00
parent 9e31be2f11
commit d57e89b5ae

View file

@ -100,6 +100,7 @@ class EnsureOrderHasProductsMixin(SingleObjectMixin):
request, *args, **kwargs request, *args, **kwargs
) )
class EnsureOrderHasInvoicePDFMixin(SingleObjectMixin): class EnsureOrderHasInvoicePDFMixin(SingleObjectMixin):
model = Order model = Order
@ -456,13 +457,15 @@ class CoinifyCallbackView(SingleObjectMixin, View):
# parse json # parse json
callbackjson = json.loads(request.body) callbackjson = json.loads(request.body)
if callbackjson['event'] == 'invoice_state_change' or callbackjson['event'] == 'invoice_manual_resend': if callbackjson['event'] == 'invoice_state_change' or callbackjson['event'] == 'invoice_manual_resend':
# get invoice from db # find coinify invoice in db
try: try:
invoice = CoinifyAPIInvoice.objects.get(id=callbackjson['data']['id']) coinifyinvoice = CoinifyAPIInvoice.objects.get(invoicejson__id=['data']['id'])
except CoinifyAPIInvoice.DoesNotExist: 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 # save new invoice payload
invoice = coinifyinvoice.order.invoice
invoice.payload = callbackjson['data'] invoice.payload = callbackjson['data']
invoice.save() invoice.save()