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): class CoinifyCallback(CreatedUpdatedModel):
headers = JSONField()
payload = JSONField() payload = JSONField()
order = models.ForeignKey('shop.Order') order = models.ForeignKey('shop.Order')
valid = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return 'callback at %s' % self.created return 'callback at %s' % self.created

View file

@ -368,12 +368,22 @@ class CoinifyCallbackView(SingleObjectMixin, View):
settings.COINIFY_API_SECRET settings.COINIFY_API_SECRET
) )
# 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): if sdk.validate_callback(request.body, signature):
# callback is valid, save it to db # mark callback as valid in db
callbackobject = CoinifyCallback.objects.create( callbackobject.valid=True
payload=request.body, callbackobject.save()
order=self.get_object()
)
# parse json # parse json
callbackjson = json.loads(request.body) callbackjson = json.loads(request.body)
@ -394,6 +404,7 @@ class CoinifyCallbackView(SingleObjectMixin, View):
else: else:
HttpResponseBadRequest('unsupported event') HttpResponseBadRequest('unsupported event')
else: else:
print "invalid callback detected"
HttpResponseBadRequest('something is fucky') HttpResponseBadRequest('something is fucky')