Stripe webhook 事件,customer.subscription.created 和 customer.subscription.updated 同时触发

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

我正在使用nextjs 13 api和stripe,创建客户订阅后,同时触发两个事件,customer.subscription.created和customer.subscription.updated。 我需要一个事件 customer.subscription.created 因为我正在创建订阅。

 event = stripe.webhooks.constructEvent(buf, sig, webhookSecret) switch (event.type) {case 'customer.subscription.created': console.log('subscription created');break  case 'customer.subscription.updated': console.log('subscription updated');break default:console.warn(
未处理的事件类型:${event.type}
);break} 

我同时收到两个事件 我只需要一个事件 customer.subscription.created,而不是在创建订阅时同时更新和创建

next.js stripe-payments webhooks
1个回答
0
投票

当您的 Stripe 账户中发生事情时,就会生成事件。您没有分享太多细节,但您可能有代码首先创建订阅,然后对其执行某些操作,例如确认 PaymentIntent。例如,后一步会将订阅的

status
incomplete
移动到
active
,这将触发
customer.subscription.updated
事件。

总体而言,您的代码必须能够适应经常出现的多个无序事件。 Stripe 的文档这里对此进行了介绍。 您可能应该查看事件的顺序以及

previous_attributes
中发生的变化,以了解导致此问题的原因,然后在代码中找到一种方法来处理此问题。

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