Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralphmrivera's avatar

Stripe API Key Error - Laravel 5.1.34 / Cashier 6.0.14

Hi,

I'm having trouble getting Cashier to work. Specifically, I'm getting the following error:

The second argument to Stripe API method calls is
 an optional per-request apiKey, which must be a string,
or per-request options, which must be an array.
(HINT: you can set a global apiKey by "Stripe::setApiKey(<apiKey>)")

I'm using:

laravel/framework v5.1.34

laravel/cashier v6.0.14

I have the following in my config:

    'stripe' => [
        'model'  => app\User::class,
        'secret' => 'sk_test_[hidden],
        'key'   => 'pk_test_[hidden],
    ],

This is where I get the error:

$subscribe = User::where('id', $id)->first();
$subscribe
    ->newSubscription($input['p'], $input['p'])
    ->create($input['stripeToken'],
    [
        'email' => $email,
        'description' => $description
    ]);

I've checked all of the values in each variable and they are correct.

0 likes
2 replies
ralphmrivera's avatar

I got it working.

Put the stipe key in the .env file, like this:

STRIPE_SECRET=sk_test_*****
STRIPE_KEY=pk_test_*****

Then I set up services.php like this:

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

This got everything working properly because everything that needed the API keys was able to grab it as a env() value.

However, I ended up dropping Cashier and using Cartalyst's Stripe-Billing-Laravel which I found far more flexible, easy to use and feature rich.

Please or to participate in this conversation.