我应该在哪个数据条事件中更新数据库以授予订阅者访问权限 [英] At which stripe event should I update my db to grant subscriber access

查看:26
本文介绍了我应该在哪个数据条事件中更新数据库以授予订阅者访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SaaS MERN应用程序,该应用程序使用Stripe进行订阅.我正在使用Stripe的新结帐功能来处理所有付款.我安装了条纹CLI,以查看进行订阅时发生的事件.我对带状Webhook中发出的事件以及如何处理这些事件有一些疑问.

I have a SaaS MERN app which is using Stripe for subscriptions. I'm using the new checkout feature of Stripe to handle all the payments. I have the stripe CLI installed to see the events that occur when a subscription is made. I have a few questions regarding the events that are emitted and how to handle them in my stripe webhook.

  1. 以下哪个事件表明付款成功,所以我可以更新数据库.

  1. Which event below indicate that the payment was successful so that I can update my database.

为什么 payment_intent.succeed 发生在 payment_intent.created 之前.

为什么发生 customer.subscription.updated 事件(我假设它应该只是应该在以下时间发生的 customer.subscription.created 事件首次购买)

Why is a customer.subscription.updated event happening (I'm assuming it should just be the customer.subscription.created event that should occur on first purchase)

我在Webhook中使用了 customer.subscription.updated 事件,以允许客户打开和关闭自动续订.由于 customer.subscription.updated 事件在订阅时也会在初始付款时被触发,因此在两种情况下都会触发同一事件,因此我该如何区分该怎么办.

I use the customer.subscription.updated event in my webhook to allow customers to turn autoRenewal on and off. Because the customer.subscription.updated event is also shot off at initial payment when subscribing, how can I differentiate what to do as the same event is fired off in both cases.

这并不重要,但是如果有人知道底部的 POST 错误是什么,我将不胜感激.我通过将我的 res.status(200).json({received:true})进一步移到我的代码上来解决此问题.最初,它被放置在我的网络挂钩的最后,所以我认为它已经超时了.

This is not as important, but if anyone knows what that POST error is at the bottom, I would appreciate some insight. I fixed this by moving my res.status(200).json({received: true}) further up my code. Initially it was placed at the very end of my webhook, so I think it was timing out.

谢谢:)

推荐答案

  1. 如果您特别想在成功付款时配置订阅,则应收听 payment_intent.succeeded

条带不能保证Webhook事件的顺序,可能会无序接收它们:

Stripe doesn't guarantee the order of webhook events, it's possible to receive them out of order: https://stripe.com/docs/webhooks/best-practices#event-ordering

订阅的状态将被更新,以显示最新的发票已成功支付,从而触发并更新事件

The subscription's status would be updated to show that the latest invoice was successfully paid, which triggers and update event

您可能想改用 invoice.upcoming :您必须对此进行调试才能查看其来源.看起来您的本地服务器可能没有运行,因此Stripe CLI无法在webhook事件上转发.

You'd have to debug this on your end to see where it came from. Looks like perhaps your local server wasn't running and so the Stripe CLI couldn't forward on the webhook event.

这篇关于我应该在哪个数据条事件中更新数据库以授予订阅者访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆