save all coinify callbacks, even the invalid ones; also save headers

This commit is contained in:
Thomas Steen Rasmussen 2016-05-29 13:20:51 +02:00
parent 2e40dfb1d1
commit 131aa96690
2 changed files with 18 additions and 5 deletions

View file

@ -244,8 +244,10 @@ class CoinifyAPIInvoice(CreatedUpdatedModel):
class CoinifyCallback(CreatedUpdatedModel):
headers = JSONField()
payload = JSONField()
order = models.ForeignKey('shop.Order')
valid = models.BooleanField(default=False)
def __str__(self):
return 'callback at %s' % self.created

View file

@ -368,12 +368,22 @@ class CoinifyCallbackView(SingleObjectMixin, View):
settings.COINIFY_API_SECRET
)
if sdk.validate_callback(request.body, signature):
# callback is valid, save it to db
# make a dict with all HTTP_ headers
headerdict = {}
for key, value in request.META.iteritems():
if key[:5] == 'HTTP_':
headerdict[key[5:]] = value
# save callback to db
callbackobject = CoinifyCallback.objects.create(
headers=json.dumps(headerdict),
payload=request.body,
order=self.get_object()
)
if sdk.validate_callback(request.body, signature):
# mark callback as valid in db
callbackobject.valid=True
callbackobject.save()
# parse json
callbackjson = json.loads(request.body)
@ -394,6 +404,7 @@ class CoinifyCallbackView(SingleObjectMixin, View):
else:
HttpResponseBadRequest('unsupported event')
else:
print "invalid callback detected"
HttpResponseBadRequest('something is fucky')