【问题标题】:How to swap plans and create invoice WITHOUT immediate payment using Laravel Cashier如何使用 Laravel Cashier 在不立即付款的情况下交换计划并创建发票
【发布时间】:2016-03-15 09:53:51
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    自从发布这个问题以来,我实际上已经向 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 2015-02-08
      • 2019-03-18
      • 2021-02-27
      • 2022-08-03
      • 2015-01-04
      • 2014-08-19
      • 2016-09-03
      • 2019-10-22
      相关资源
      最近更新 更多