Stripe支付网关错误$config必须是字符串或数组

问题描述 投票:0回答:1

我尝试从 .env 文件访问 api 密钥时遇到错误。我已经尝试了互联网上的几个页面来解决问题,但它没有给我任何解决方案。我尝试将服务添加到 services.php 但没有成功。我也尝试过 php artisan config:cache 并尝试添加到 config/services.php

'stripe' => [
        'stripe_key' => env('STRIPE_KEY'),
        'secret_key' => env('STRIPE_SECRET'),
        ]
    ],

StripePaymentController.php

<?php

namespace App\Http\Controllers;

use Stripe;
use Illuminate\View\View;
use Illuminate\Http\Request;

class StripePaymentController extends Controller
{
    //
    public function stripe():View {
        return view('stripe');
    }

    public function stripeCheckout(Request $request){
        $stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));

        $redirectUrl = route('stripe.checkout.success').'?session_id={CHECKOUT_SESSION_ID}';

        $response = $stripe->checkout->sessions->create([
            'success_url' => $redirectUrl,

            'customer_email' => '[email protected]',

            'payment_method_type' => ['link','card'],

            'lne_items' => [
                [
                    'price_data' => [
                        'product_data' => [
                            'name' => $request->product,
                        ],
                    'unit_price' => 100 * $request->price,
                    'currency' => 'NZD',
                    ],
                    'quantity' => 1,
                ],

            ],
            'mode' => 'payment',
            'allow_promotion_codes' => true,
        ]);
        return redirect($response['url']);
    }

    public function stripeCheckoutSuccess(Request $request){
        $stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));

        $response = $stripe->checkout->sessions->retrieve($request->session_id);

        return redirect()->route('stripe.index')->with('success','Payment Successful.');
    }
}

enter image description here

laravel eloquent stripe-payments
1个回答
-2
投票

将此行

new \Stripe\StripeClient(env('STRIPE_SECRET'));
更改为
Stripe::setApiKey(env('STRIPE_SECRET'));

© www.soinside.com 2019 - 2024. All rights reserved.