【发布时间】:2020-08-29 02:33:20
【问题描述】:
我正在尝试将 Coinbase Commerce Webhook API 集成到我的 Django 应用程序中;但它似乎以正确的方式做事。我已经在网上搜索了超过 2 天,但没有可用的解决方案。 Coinbase 商业官方文档没有提供将其集成到 Django 中的方法。请您的帮助将不胜感激。这是我尝试过的;但继续抛出错误。
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
from coinbase_commerce.error import WebhookInvalidPayload, SignatureVerificationError
from coinbase_commerce.webhook import Webhook
from django.http import HttpResponse
import json
WEBHOOK_SECRET = settings.COINBASE_SECRET
@csrf_exempt
def payment_webhook(request):
request_data = request.data.decode('utf-8')
request_sig = request.headers.get('X-CC-Webhook-Signature', None)
try:
event = Webhook.construct_event(request_data, request_sig, WEBHOOK_SECRET)
except (WebhookInvalidPayload, SignatureVerificationError) as e:
return HttpResponse(e, status=400)
print("Received event: id={id}, type={type}".format(id=event.id, type=event.type))
return HttpResponse('ok', status=200)
【问题讨论】:
-
“但继续抛出错误”:错误是什么?
-
错误请求:/"POST / HTTP/1.1" 400 53
-
错误响应中是否有额外的信息?
-
你找到解决办法了吗?
标签: python django api webhooks coinbase-api