为了账号安全,请及时绑定邮箱和手机立即绑定

Stripe:在向现有订阅添加 subscriptionItem 时立即向客户收费/开具账单?

Stripe:在向现有订阅添加 subscriptionItem 时立即向客户收费/开具账单?

慕森王 2023-02-17 10:21:31
我在一家在线课程提供商工作。这是客户流程:student subscribe to teacherA | this creates a monthly Stripe subscription       | student is billedstudent 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 $501/15 | studentA subscribe to teacherB at | billed $2.5 # half of remaining month02/01 | subscription auto invoice         | billed $10您知道如何实现这一目标吗?
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

为学生想要订阅的其他教师创建额外的 subscriptionItems 是正确的做法。但是,正如您注意到的那样,当您在订阅上创建订阅项目时,不会立即向学生收费。默认情况下,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);


查看完整回答
反对 回复 2023-02-17
  • 1 回答
  • 0 关注
  • 112 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信