1

Laravel Cashier 让交换计划变得非常简单:

$user->subscription('premium')
     ->swapAndInvoice();

此功能也很棒,因为它会立即向用户开具发票,但是,它也迫使用户立即付款,而不是像通常那样等待一个小时。这似乎妨碍了我的invoice.createdwebhook,因为一旦swapAndInvoice发生,我似乎无法对发票进行进一步更改。

如果我只使用->swap(),它似乎根本不会创建发票,而只是创建等待添加到下一张发票的行项目。想法受到赞赏。

4

1 回答 1

0

自从发布这个问题以来,我实际上已经向 Laravel Cashier 存储库提交了一个拉取请求,以在StripeGateway.php文件中添加一个可以执行此类功能的方法。

/**
 * Invoice the billable entity outside of regular billing cycle without charging the user immediately.
 *
 * @return bool
 */
public function invoiceWithoutImmediateCharge()
{
    try
    {
        $customer = $this->getStripeCustomer();

        // Removed this because it immediately charges the user which doesn't allow the invoice to be modified by webhooks
        //Stripe_Invoice::create(['customer' => $customer->id], $this->getStripeKey())->pay();
        Stripe_Invoice::create(['customer' => $customer->id], $this->getStripeKey());

        return true;
    }
    catch (\Stripe_InvalidRequestError $e)
    {
        return false;
    }
}
于 2015-12-12T17:05:26.063 回答