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

RomainB's avatar
Level 13

Why am I forced to manually set the Stripe key in my App Provider?

Hi! I am dealing with stripe through cashier in my app for a quite long time now. I recently updated my whole app to L11 but I am unsure the issue I am meeting is due to the upgrade but here it is.

My STRIPE_KEY, STRIPE_SECRET and STRIPE_WEBHOOK_SECRET are correctly filled inside my .env file. My config/cashier.php file is as default, meaning it correctly proxies the env variables.

But this code fails, throwing me a missing API key:

$stripe = Cashier::stripe();

// This stripe api call is ok
$session = $stripe->checkout->sessions->retrieve($checkoutSessionId);

// This one fails
$soldProductId = $session->allLineItems($checkoutSessionId)['data'][0]['price']['product'];

This exception is thrown directly from the Stripe class (not the StripeClient one or Cashier):

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 [email protected] if you have any questions.

I solved it by manually setting the Stripe key from my AppServiceProvider:

Stripe::setApiKey(config('cashier.secret'));

But the question is: Why?! I am sure that this code worked earlier and I don't see anything in both L11 ou Cashier 15 upgrade guide who mention anything relative to this.

0 likes
0 replies

Please or to participate in this conversation.