如何解决Stripe:在向现有订阅中添加subscriptionItem时立即向客户收费/计费?
我正在为在线课程提供者工作。这是客户流:
student subscribe to teacherA | this creates a monthly Stripe subscription | student is billed student subscribe to teacherB | this adds a subscriptionItem to the subscription | student is not billed
问题在于,当我创建subscriptionItem时,不会立即向客户计费,并开始免费访问高级内容。
根据我在文档中提到的内容,创建的订阅很多,而学生订阅的老师却是一个糟糕的设计(无论如何,他们将单个客户的订阅限制为25个)。
然后我认为创建很多subscriptionItems是个好主意,如果我错了,请纠正我。
我正在寻找一种实现这种流程的方法:
订阅价格为每位老师$ 5
01/01 | studentA subscribe to teacherA at | billed $5 01/15 | studentA subscribe to teacherB at | billed $2.5 # half of remaining month 02/01 | subscription auto invoice | billed $10
您是否了解如何实现这一目标?
解决方法
为学生想要订阅的其他教师创建额外的subscriptionItem是正确的举动。但是,正如您注意到的那样,在订阅上创建订阅项目时,不会立即向学生收费。默认情况下,Stripe为按比例分配的新添加的订阅项目创建待处理的发票项目(例如,在您的示例中为2.5美元)。如果您只留下按比例分配的发票项目,它们将被捆绑到学生的下一张发票中,总计为12.5美元:
- teacherB $2.5 (proration charges from last month)
- teacherA $5
- teacherB $5
- total next month: $12.5
如果您不想等待下个月的学生付款,则可以在添加新的订购项目后立即创建并支付发票来立即为学生计费。
在节点中,它类似于:
// Add the new subscription item for Teacher B
await stripe.subscriptionItems.create({
subscription: 'sub_xyz',// The subscription ID
price: 'price_teacher_b_price',// The price for teacher B
});
// At this point,Stripe would have created pending invoice items.
// Pending invoice items would by default be included in the next month's
// invoice,but you can pull them into a new invoice immediately:
const invoice = await stripe.invoices.create({
customer: 'cus_xyz',// The customer/student
});
// At this point,the invoice items have been pulled into a new invoice.
// To charge the student you need to finalize and pay the invoice. You
// can do this in one step:
await stripe.invoices.pay(invoice.id);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。