我有一个关于条纹订阅的问题。我有一个订阅计划,客户每月都会收到账单。这个订阅对象有一个属性CurrntEndoPixEnter,它显示了我们每个月计费周期结束的时间。
我目前正在写一个webhook,它会在成功付款后被解雇。我想知道我是否必须在我的应用程序的Web挂钩端点中手动编辑此订阅的当前属性,或者stripe是否自动更新此订阅?
这是我的web应用程序后端处理成功付款的webhook端点。我有一个MongoDB文档,我想在其中更新billing.current_period_end属性。现在,这显示了上一个条带计费周期的结束,但因为我有一个成功的付款,我想改变它。为此,我使用subscription.current_period_end,但我不确定srtripe是否在成功付款后自动更新了stripe suscription current_period_end属性,或者这是否是我必须手动执行的操作?
const paymentSuccessful = async (req, res) => {
try {
// get the Stripe customer
const customer = await stripe.customers.retrieve('cus_EOfhqjsUvzUkiJ');
// get the subscription of the customer
const subscription = await stripe.customers.retrieve(customer.subscriptions.data[0].id);
// add it to the billing.failed_payments property of the workspace
const workspace = await Workspace.findOneAndUpdate(
{ _id: customer.metadata.workspace_id },
{
$addToSet: {
'billing.success_payments': req.body
},
$set: {
'billing.current_period_end': subscription.current_period_end
}
}, {
new: true
}
).lean();
// send mail to user (still to be added)
res.status(200).json({
message: 'Success'
});
} catch (err) {
return sendErr(res, err);
}
};
MongoDB文档示例工作区