【发布时间】:2020-03-26 00:00:09
【问题描述】:
我正在使用本教程使用 Cashier 将 Stripe 集成到我的 Laravel 网站中: https://appdividend.com/2018/12/05/laravel-stripe-payment-gateway-integration-tutorial-with-example/
本教程是为 Cashier 9 编写的,因此它不适用于 Cashier 10。但是,它确实可以在这个 SO 答案中进行调整:https://stackoverflow.com/a/57812759/2002457
除了,它仅适用于现有的 Stripe 客户。当我注册一个全新的用户并尝试查看一个计划时,它给出了这个错误:User is not a Stripe customer. See the createAsStripeCustomer method.
所以,我尝试这样做:
public function show(Plan $plan, Request $request)
{
if($request->user()->stripe_id === null)
{
$request->user()->createAsStripeCustomer();
}
$paymentMethods = $request->user()->paymentMethods();
$intent = $request->user()->createSetupIntent();
return view('plans.show', compact('plan', 'intent'));
}
产生此错误:No API key provided. (HINT: set your API key using "Stripe::setApiKey(<API-KEY>)". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.
这个 SO 答案解决了这个问题:https://stackoverflow.com/a/34508056/2002457
但该解决方案仅适用于 Cashier 9,因为 Billable 发生了变化,所以不清楚如何设置 API 密钥。
如果他们还不是 Stripe 客户,我在创建新客户时做错了什么?
编辑 - 我正在使用默认的收银员配置,并且我已经确认它指向 .env 变量。
我输入了
dd(config('cashier.key'));以确认配置正在运行我删除了旧的 services.php 配置部分
环境变量设置正确
这里是显示方法:
public function show(Plan $plan, Request $request)
{
$paymentMethods = $request->user()->paymentMethods();
$intent = $request->user()->createSetupIntent();
return view('plans.show', compact('plan', 'intent'));
}
现在是错误:User is not a Stripe customer. See the createAsStripeCustomer method.
【问题讨论】:
标签: php laravel stripe-payments laravel-cashier