【问题标题】:Creating One time Plan using Stripe/Plan Facade使用 Stripe/Plan Facade 创建一次性计划
【发布时间】:2021-04-01 21:27:21
【问题描述】:

我想使用 Laravel/Plan Facade 创建一次性付款计划。我可以创建月度、年度计划,但我不知道如何实现一次性付款计划,因为我们可以在条纹仪表板上创建产品时创建一次性付款计划。下面是我创建每月、每年、每周或每天但不是终身/一次性付款的代码。

$monthlyPlan = Stripe\Plan::create([
        "product" => $stripeProduct->id,
        "amount" => $request->input('amount_month'),
        "interval" => 'month',
        "currency" => $request->input('currency')
    ]);

    $yearlyPlan = Stripe\Plan::create([
        "product" => $stripeProduct->id,
        "amount" => $request->input('amount_year'),
        "interval" => 'year',
        "currency" => $request->input('currency')
    ]);

【问题讨论】:

  • 对于lifetime,您创建自己的计划并使用条纹来收取该金额。这些计费计划,例如订阅
  • 我怎样才能像上面的代码一样创建这个计划?
  • 不要在stripe中创建计划,在你自己的数据库中创建
  • 我可以通过代码创建它吗?或者它应该只在条纹仪表板上,在条纹仪表板上我可以创建一个时间计划,但我想通过条纹 api 创建它

标签: laravel stripe-payments laravel-cashier


【解决方案1】:

您应该使用新的价格 API 来模拟您的定期付款和一次性付款:https://stripe.com/docs/billing/migration/migrating-prices

价格将允许您创建定期付款,例如:

$monthlyPrice = $stripe->prices->create([
  'unit_amount' => $request->input('amount_month'),
  'currency' => request->input('currency'),
  'recurring' => ['interval' => 'month'],
  'product' => $stripeProduct->id,,
]);

并创建一个折扣价格:

$oneOffPrice = $stripe->prices->create([
  'unit_amount' => $request->input('amount_month'),
  'currency' => request->input('currency'),
  'product' => $stripeProduct->id,,
]);

【讨论】:

  • 我正在使用“laravel/cashier”:“^12.0”,可以吗?
  • 它是说调用一个成员函数在 null 上创建
  • $stripeProduct = Stripe\Product::create([ "name" => $request->input('name'), "type" => 'service' ]); $monthlyPlan = $stripeProduct->prices->create([ 'unit_amount' => $request->input('amount_month'), 'currency' => $request->input('currency'), 'recurring' => ['interval' => 'month'], 'product' => $stripeProduct->id, ]);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-04
  • 2018-02-04
  • 1970-01-01
  • 1970-01-01
  • 2013-02-07
相关资源
最近更新 更多