【问题标题】:Laravel cashier - add invoice item to subscriptionLaravel 收银员 - 将发票项目添加到订阅
【发布时间】:2020-09-03 00:37:52
【问题描述】:

我使用 Laravel's Stripe integration 每月向客户收费。

是否可以在我的订阅中添加发票项目,以便我的客户按月为他/她在此期间使用的许多项目计费?

This question suggests that it is possible

并且Laravel's 文档涵盖creating an invoice,但不添加发票项目。

有谁知道添加发票项目是否有Laravel 方法?如果没有,如何添加发票项目?

【问题讨论】:

    标签: php laravel-5 stripe-payments


    【解决方案1】:

    我知道这是一个老问题,但由于我在任何地方都没有找到答案,所以我将分享我的发现:

    使用收银员创建新订阅时,您可以传递订阅的其他选项。 感兴趣的参数是“add_invoice_items”,它允许您将一次性付款附加到订阅的第一张发票上。

    $user->newSubscription('default', 'basic')
        ->create($paymentMethod, [
            'name' => 'customer name',
            // other customer data
        ],[
           'add_invoice_items' => [
              [
                 'price' => 'your_stripe_price_id',
                 'quantity' => 1
              ]
          ],
          // Any other subscription ot
    ]);
    

    查看订阅选项https://stripe.com/docs/api/subscriptions/create 查看客户选项https://stripe.com/docs/api/customers/create

    【讨论】:

      【解决方案2】:

      我认为使用 Laravel 5.4 会更容易,但由于在撰写本文时它还没有发布,因此您必须手动设置它。

      在 Laravel 5.4 中(假设这个函数可以使用)

      $user->invoiceForUpcoming('One-time charge', 1000);
      

      手动方式(确保您已安装 Cashier 等):

      use Stripe\InvoiceItem as StripeInvoiceItem;
      

      在您的控制器中或任何有意义的地方:

      $options = [
        'customer' => $user->stripe_id,
        'amount' => 1000,
        'currency' => 'usd',
        'description' => 'One-time fee',
      ];
      $response = StripeInvoiceItem::create(
        $options, ['api_key' => config('services.stripe.secret')]
      );
      

      【讨论】:

      • 对于任何查看该功能的人都可以使用,但名称不同。 $user->tab('一次性收费', 1000);
      猜你喜欢
      • 2020-11-03
      • 2018-05-31
      • 1970-01-01
      • 2021-04-28
      • 2017-09-09
      • 2021-12-06
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多