我一整天都在阅读文档,如果可能的话,我很难理解。
我想要的是为用户订阅多个计划,并在一张发票上收费,从最初对发票开具账单时起每月定期付款。
在文档中它说:
“请注意,客户的多个订阅会导致每个订阅的计费周期、发票和费用不同,即使这些计划具有相同的计费间隔并且订阅是同时创建的。”
哪个没有前途
但是随后 api 明确允许通过 InvoiceItems api 创建具有多个项目的发票。似乎这主要是针对客户的自定义/独特操作,例如在常规订阅周期之外应用折扣或一次性收费。
我想我可以手动跟踪计费周期并手动创建多项目发票,但我更愿意通过 Stripe 实现自动化。
这可能吗?
Stripe API 现在支持您所描述的内容:https ://stripe.com/docs/subscriptions/multiplan 。这个想法是将多个计划添加到订阅中,但限制是所有计划必须共享相同的间隔。
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("xxxxxxxxxxxxxxx");
stripe.subscriptions.create({
customer: "cus_91elFtZU3tt11g",
items: [
{
plan: "basic-monthly",
},
{
plan: "additional-license",
quantity: 2,
},
]
}, function(err, subscription) {
// asynchronously called
});
Run Code Online (Sandbox Code Playgroud)
现在,处理该场景的推荐工作流程是:
product并prices代替planssubscription(带有price)subscriptionItem根据需要添加尽可能多的内容subscription您的客户可以根据需要获得所需的数量subscriptionItems。他将定期收到一次账单subscription,并且只有一张发票。subscriptionItem如果您在月中添加,它也可以处理。
stripe 文档:具有多个产品的订阅
Stripe API 参考
// add item to existing subscription
await stripe.subscriptionItems.create({
subscription: subscriptionId,
price: priceId,
quantity,
});
Run Code Online (Sandbox Code Playgroud)