save all coinify callbacks, even the invalid ones; also save headers
This commit is contained in:
parent
2e40dfb1d1
commit
131aa96690
|
@ -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
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue