stripe dashbaord 显示 400,尽管 stripe Listen cli 正在重新调整 200

问题描述 投票:0回答:1

作为健全性检查,我立即返回状态 200。正如您在下面的屏幕截图中看到的,我的 cli 表示一切正常,并返回 200 回到条带,但在我的仪表板中我得到状态 400。这是一个 Django 应用程序。如果 cli 正在接收仪表板响应,那么仪表板响应是否重要? 我们已经构建了偶数

@method_decorator(csrf_exempt, name='dispatch')
class StripeWebhook(APIView):
    def post(self, request, *args, **kwargs):
        return HttpResponse({status: "success"},status=200)
        #all the code below is our normal logic. we are just trying to do a sanity test
        #to see if the dashboard picks up the 200
        print('received payment. in webhook')
        stripe.api_key = settings.STRIPE_TEST_SECRET
        event = None
        payload = request.body        
        sig_header = request.META["HTTP_STRIPE_SIGNATURE"]
        try:
            event = stripe.Webhook.construct_event(
                payload, sig_header, 'settings.WEBHOOK_SECRET'
            )
        except ValueError as e: 
            print("aaa")
            print(e)
            return HttpResponse(status=400)
        except stripe.error.SignatureVerificationError as e:
            print('bbb')
            print(e)
            return HttpResponse(status=400)
        
        
        if event['type'] == 'checkout.session.completed':
            print('payment success')
        elif event['type'] == 'payment_intent.payment_failed':
            # Handle failed payment intent event
            print('payment failed')
            return HttpResponse('something went wrong', status=400)
        return HttpResponse({'status': 'success'})


(https://i.sstatic.net/BUgJsnzu.png)#stipe cli 日志

https://i.sstatic.net/itoTZ4bj.png)#stipe 仪表板

我们尝试立即向 stripe 返回 200 状态。

django stripe-payments
1个回答
0
投票

每当您成功收到 Webhook 时,您都应该向 Stripe 返回 200。这表明已收到 HTTP 请求,而不是解析 Webhook 本身时出现错误。返回 200 后,您需要处理的任何错误都应在 Webhook 处理程序中处理。

© www.soinside.com 2019 - 2024. All rights reserved.