Create plan on stripe through laravel

醉酒当歌 提交于 2019-12-03 13:47:43

laravel/cashier just doesn't have this functionality baked in. You aren't out of luck though as it is easy to just use Stripe's API which should be downloaded as a dependency in your vendor folder. If not you can just download it with composer.

composer require stripe/stripe-php 2.*

You can use it with

use \Stripe\Plan;

Plan::create(array(
  "amount" => 2000,
  "interval" => "month",
  "name" => "Amazing Gold Plan",
  "currency" => "usd",
  "id" => "gold")
);

You can read more here - https://stripe.com/docs/api#create_plan

Thanks so much. I learned lots of things by this thread. But for latest cashier and stripe-php versions few thing need to be changed.

My cashier version is 7.0 ("laravel/cashier": "~7.0") and it automatically installs stripe-php 5. But some parameters has changed from stripe api. So this code will be working,

\Stripe\Stripe::setApiKey("sk_test_your_key");

\Stripe\Plan::create(array(
  "amount" => 5000,
  "interval" => "month",
  "product" => array(
    "name" => "Bronze standard"
  ),
  "currency" => "eur",
  "id" => "bronze-standard"
));

And you can read more in PHP section of stripe api docs... (https://stripe.com/docs/api/php#create_plan)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!