如何使用Laravel Cashier交换计划并创建发票而无需立即付款

时间:2015-12-09 22:45:15

标签: php laravel-4 laravel-5 stripe-payments laravel-cashier

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

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

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

如果我只使用->swap(),则根本不会创建发票,而只是创建等待添加到下一张发票的订单项。我们对此表示赞赏。

1 个答案:

答案 0 :(得分: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;
    }
}