条带订阅checkout.session.completed资源丢失invalid_request_error类型的错误



我试图理解为什么checkout.session.completed的webhook在使用Stripe CLI进行本地测试时崩溃。我正在使用djstripe。我的customer.subscription.created网络挂钩成功了。使用CLI时,stripe trigger checkout.session.completed命令出现以下错误:

Request failed, status=404, body={
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_page: 'ppage_1Il33eAyVjQjzOsRERzYQSbK'",
"param": "payment_page",
"type": "invalid_request_error"
}

成功的url路由有问题吗?views.py

def create_checkout_session(request):
"""Create a checkout session for Stripe."""
data = json.loads(request.body)
priceId = data.get("priceId")
if not Price.objects.filter(id=priceId).exists():
messages.add_message(request, messages.ERROR,
"That plan price is not available. Please contact support for help.", )
return HttpResponseRedirect(reverse("users:index"))
request.account = OrgMembership.objects.filter(my_identity=request.user).first()
sessionId = stripegateway.create_checkout_session(priceId, request)
return JsonResponse({"sessionId": sessionId})

stripegateway.py

class StripeGateway:
"""Gateway interacts with the APIs required by Stripe. Credit: Matt Layman"""
def create_checkout_session(self, priceId, request):
"""Create a checkout session based on the subscription price."""
site = Site.objects.get_current()
subscription_success = reverse("users:success")
stripe_cancel = reverse("users:stripe_cancel")
request.account = OrgMembership.objects.get(my_identity=request.user.id)
request.org = request.account.my_org
# session_parameters = {
#     "customer_email": request.org.billing_email,
#     "success_url": f"http://{site}{subscription_success}",
#     "cancel_url": f"https://{site}{stripe_cancel}",
#     "payment_method_types": ["card"],
#     "mode": "subscription",
#     "line_items": [{"price": priceId, "quantity": 1}],
#     "client_reference_id": str(request.account.id),
# }
# checkout_session = stripe.checkout.Session.create(**session_parameters)
# return checkout_session["id"]
checkout_session = stripe.checkout.Session.create(
customer_email = request.org.billing_email,
client_reference_id = str(request.account.id),
payment_method_types=['card'],
line_items=[{
'price': priceId,
'quantity': 1,
}],
mode='subscription',
success_url=request.build_absolute_uri(reverse('users:success')) + '?session_id={CHECKOUT_SESSION_ID}',
cancel_url=request.build_absolute_uri(reverse('users:index')),
)
return checkout_session["id"]

注释掉的部分是使用的原始代码,然后尝试其他方法来解决问题。非常感谢任何指导。

我也遇到了同样的问题。stripe trigger checkout.session.completed将返回以下内容:

Trigger failed: Request failed, status=404, body={
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_page: 'ppage_1IryQdFE8p8XoGx4OJLXOv4p'",
"param": "payment_page",
"type": "invalid_request_error"
}
}

我通过将stripe CLI版本从v1.5.4更新到v1.5.14来修复此错误。

确保将webhook事件转发到正确且有效的端点。

使用forward-to命令行参数将stripe cli指向您的开发服务器:

stripe listen 
--skip-verify 
--forward-to https://localhost:8000/payments/webhook/ 
--log-level debug

使用HTTPS端点时,自签名或无效证书需要skip-verify。Django也很挑剔在URL末尾加一个斜杠。

相关内容

最新更新