没有这样的计划:每月;存在一个名为monthly,但它的ID是primary Laravel Cashier

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40274681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:39:57  来源:igfitidea点击:

No such plan: monthly; one exists with a name of monthly, but its ID is primary Laravel Cashier

laravellaravel-5laravel-cashier

提问by user3489502

Getting this problem in Stripe test. Everything used to work in test, but when I created a new plan in Stripe, and deleted the original one, I now get the following error:

在条纹测试中遇到这个问题。过去一切都在测试中工作,但是当我在 Stripe 中创建一个新计划并删除原始计划时,我现在收到以下错误:

No such plan: monthly; one exists with a name of monthly, but its ID is primary.

Controller

控制器

$user->newSubscription('primary', 'monthly')->create($token, [ ]);

Plan details

计划详情

ID: primary
Name: monthly
Price: .99 USD/month
Trial period: No trial

php artisan config:clear doesn't help. I'm using Laravel 5.2 and Cashier 6.0.

php artisan config:clear 没有帮助。我正在使用 Laravel 5.2 和 Cashier 6.0。

.env file

.env 文件

STRIPE_KEY=pk_test_...
STRIPE_SECRET=sk_test_....

config/services.php

配置/services.php

'stripe' => [
    'model'  => App\User::class,
    'key'    => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
],

采纳答案by user3489502

Use this instead :

改用这个:

$user->newSubscription('primary', 'primary')->create($token, [ ]);

From documentation :

从文档:

The first argument passed to the newSubscription method should be the name of the subscription. The second argument is the specific Stripe plan the user is subscribing to. This value should correspond to the plan's identifier in Stripe.

传递给 newSubscription 方法的第一个参数应该是订阅的名称。第二个参数是用户订阅的特定 Stripe 计划。此值应对应于 Stripe 中的计划标识符。

So the second argument must be equal to the ID value from my Stripe plan! In this case, that value is primary, not monthly.

所以第二个参数必须等于我的条纹计划中的 ID 值!在这种情况下,该值是primary,而不是monthly

回答by Peter

It is important to differentiate between a Product identifier and a Plan identifier. Perhaps stripe has changed since many of the tutorials were written. It took me a few hours of searching to recognize this. As I'm new to stripe, it was easy to find the Product and Product Id, but the Plan Id was harder to find. In fact I had to "export plans" to a CSV from the product page to even get the ID for plan Id.

区分产品标识符和计划标识符很重要。也许自从编写了许多教程以来,stripe 已经发生了变化。我花了几个小时的搜索才认识到这一点。由于我是 Stripe 的新手,因此很容易找到产品和产品 ID,但更难找到计划 ID。事实上,我必须从产品页面将计划“导出”到 CSV 文件才能获得计划 ID 的 ID。

Hopefully this helps someone who was lost like I was

希望这能帮助像我一样迷路的人

回答by Waleed

the main issue is that your are passing plan name instead of plan id in second parameter of newSubscription(). it should be like this

主要问题是您在 newSubscription() 的第二个参数中传递计划名称而不是计划 ID。应该是这样的

$user->newSubscription('main' , 'plan_GNxxxxxxx')->create($request->stripeToken,[ ]);

$user->newSubscription('main', 'plan_GNxxxxxxx')->create($request->stripeToken,[ ]);