向订阅添加经常性和一次性费用

Add a recurring and one-time fee to a subscription

我们的用户需要能够在他们的帐户上激活插件,这将花费 1 次安装费(比如 100 美元),然后是之后的经常性月费(比如 10 美元)。我可以通过转到 Stripe 仪表板、找到订阅并添加这两项(一次性 100 美元和经常性 10 美元)并单击“更新”来手动执行此操作。但是,当我更改代码时:

    $subscription->swapAndInvoice([
        'site-membership', // all users already have this plan

        '10-monthly-fee',  // this is the addon being added
        '100-one-time-fee' // one-time addon fee
    ]);

我收到一个错误:

Stripe\Exception\InvalidRequestException: You passed a non-recurring price but this field only accepts recurring prices.

如果我不能使用 swap,有没有其他方法可以一次完成所有这些操作?我知道我可以为一次性费用开具独立发票,但我不希望我们的客户收到两张单独的发票,因为他们只能以 110 美元的价格开具一次发票。这可能使用 Cashier 吗?

Cashier 中没有直接的方法,但我找到了一种通过将值传递给 Stripe 来实现此目的的方法。 (Stripe docs)

    $subscription->swapAndInvoice([
        'site-membership',
        '10-monthly-fee'
    ], [
        'add_invoice_items' => [
            [ 'price' => '100-one-time-fee' ]
        ]
    ]);