Stripe订阅计划事件异常:仅单用户触发支付相关事件
互助基金系统Stripe订阅计划事件异常排查
我正在开发互助基金(chit fund)系统,使用Stripe Subscription Schedule为用户创建订阅,已保存支付详情实现自动扣费。批量为3-4名用户创建按日启动的4天期订阅计划,所有订阅均成功创建,但仅一名用户的invoice.payment_succeeded或invoice.payment_failed事件出现在Stripe开发者后台事件日志中,其他用户无相关日志。
已配置Webhook端点监听subscription_schedule.completed等事件,但未触发该类事件。期望通过subscription_schedule相关事件更新数据库订阅状态,却无法获取所有用户的订阅成功事件响应。以下是相关代码:
// 创建SetupIntent const setupIntent = await stripe.setupIntents.create({ customer: user.customerId, usage: "off_session", automatic_payment_methods: { allow_redirects: "never", enabled: true, }, }); // 设置默认支付方式 const paymentMethods = await stripe.customers.update(customerId, { invoice_settings: { default_payment_method: paymentMethodId, }, }); // 创建订阅计划 const subscription = await stripe.subscriptionSchedules.create({ customer: customerId, start_date: unixTimestampSeconds, end_behavior: "release", phases: [ { items: [ { price: priceId, quantity: quantity, }, ], iterations: iteration, }, ], }); // 保存订阅到数据库 const subs = await Subscription.create({ subscriptionId: subscription?.id, userId: userId, programId: programId, status: subscription.status, startDate: start_date, endDate: end_date, }); // Stripe Webhook处理逻辑 case "subscription_schedule.released": const subscriptionScheduleReleased = event.data.object; let user = User.findOne({ where: { customerId: subscriptionScheduleReleased.customer }, }); const subscriptionSchedule = await stripe.subscriptionSchedules.retrieve( subscriptionScheduleReleased.id ); let newsubscription = subscriptionSchedule.subscription || subscriptionSchedule.released_subscription; const subscription = await stripe.subscriptions.retrieve(newsubscription); const datasubscription = await Subscription.findOne({ where: { subscriptionId: subscriptionScheduleReleased.id }, }); datasubscription.status = subscription.status; console.log(subscriptionScheduleReleased, "subscription released"); // 此处需定义并调用处理subscription_schedule.released事件的函数 break;
已监听的Stripe事件包括:
- subscription_schedule.aborted
- subscription_schedule.canceled
- subscription_schedule.completed
- subscription_schedule.created
- subscription_schedule.expiring
- subscription_schedule.released
- subscription_schedule.updated
内容的提问来源于stack exchange,提问作者Abaid Ullah
相关产品推荐
相关产品推荐

