【问题标题】:Laravel Cashier 10 - Errors trying to show a Stripe elementLaravel Cashier 10 - 尝试显示条纹元素时出错
【发布时间】: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


    【解决方案1】:

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

    要调试的东西很少:

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

    【讨论】:

    • 您更新的问题是一个非常不同的问题(可能模型/模式+需要调用->createAsStripeCustomer()而不是您最初提出的问题。
    猜你喜欢
    • 2020-03-26
    • 2018-07-26
    • 2020-11-08
    • 2016-01-02
    • 1970-01-01
    • 2019-07-04
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多