php - Laravel Cashier 10 - 尝试显示 Stripe 元素时出错

标签 php laravel stripe-payments laravel-cashier

我正在使用本教程使用 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 key。

如果新客户还不是 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.

最佳答案

Cashier 10 对配置进行了一些更改,包括设置 cashier.php 配置文件。 upgrade guide详细说明如何,这pull request commit显示文件。

调试这个的几件事:

  • 确保您已正确设置收银员 10 的配置。
  • 确保配置 key cashier.key 可用(例如 ddd(config('cashier.key'));
  • 仔细检查您的 .env 变量是否为 stripe 的 API key 正确设置

关于php - Laravel Cashier 10 - 尝试显示 Stripe 元素时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59120863/

相关文章:

php - 查询错误: where is the error?

php - woocommerce 中有条件地未设置结帐字段

javascript - 在 <tr> 悬停时从数据库获取详细值

php - Laravel 5.2 $errors 未出现在 Blade 中

laravel - 如何在开发模式下禁用模板缓存?

stripe-payments - Stripe 卡 token 的有效期是多久?

ruby-on-rails - 无法使用 Stripe 保存或取消订阅

php - 根据项目自定义字段最高值在购物车和结帐页面上添加通知

基于对象类型的 PHP 操作最佳实践

javascript - Stripe 连接: What's the difference between Customers and Accounts?