【问题标题】:Stripe: charge/bill customer immediately when adding a subscriptionItem to an already existing subscription?条纹:将订阅项添加到现有订阅时立即向客户收费/账单?
【发布时间】:2020-12-26 05:14:52
【问题描述】:

我正在为一家在线课程提供商工作。这是客户流:

学生订阅老师A |这将创建每月的 Stripe 订阅 |学生被计费 学生订阅老师B |这会在订阅中添加一个 subscriptionItem |学生不收费

问题是,当我创建 subscriptionItem 时,客户没有立即计费,而是开始免费访问高级内容。

根据我在文档中的红色,创建有很多订阅让学生订阅教师是一个糟糕的设计(无论如何,他们将单个客户的订阅限制为 25 个)。

然后我认为创建有很多订阅项是个好主意,如果我错了,请纠正我。


我正在寻找一种方法来实现这样的流程:

每位教师的订阅价格为 5 美元

01/01 |学生A 订阅老师A 在|收费 5 美元 01/15 |学生A订阅老师B |计费 $2.5 # 剩余月份的一半 02/01 |订阅自动发票 |收费 10 美元

您知道如何实现这一目标吗?

【问题讨论】:

    标签: javascript node.js stripe-payments


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-26
      • 2017-11-09
      • 1970-01-01
      • 2022-10-21
      • 2021-02-18
      • 2021-04-01
      • 2015-11-12
      相关资源
      最近更新 更多