gpt4 book ai didi

python - strip 订阅 checkout.session.completed 资源丢失 invalid_request_error 类型的错误

转载 作者:行者123 更新时间:2023-12-02 02:15:04 24 4
gpt4 key购买 nike

我试图理解为什么在使用 Stripe CLI 在本地测试时 checkout.session.completed 的 webhook 会崩溃。我正在使用 djstripe。我的 customer.subscription.created webhook 成功了。使用 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"]

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

最佳答案

我遇到了同样的问题。 strip 触发器 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 来修复错误。

关于python - strip 订阅 checkout.session.completed 资源丢失 invalid_request_error 类型的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67293102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com