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

maaz's avatar
Level 2

Stripe : You did not set a valid publishable key.

i am using laravel stripe but it gives me an error "you did not set a valid publishable key". it was working fine like an hour ago. is it some kind of a server problem or what?

 <script
                                        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                                        data-key="{{ env('STRIPE_PUB_KEY') }}"
                                        data-name="The NosoSailing"
                                        data-description="Online course about integrating Stripe"
                                        data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
                                        data-locale="auto"
                                        data-currency="eur">
                                </script>
0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

What is actually going on with that script element; you have class and data- attributes on it, why? This is not what script elements are for; are you missing a button element?

 <script src="https://checkout.stripe.com/checkout.js"></script>

<button class="stripe-button"
	data-key="{{ env('STRIPE_PUB_KEY') }}"
	data-name="The NosoSailing"
	data-description="Online course about integrating Stripe"
	data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
	data-locale="auto"
	data-currency="eur"
>
	Pay now
</button>

Also, do not use the env() helper method except in config files; we read environment variables into config (which is cached). Generally, we use the config/services.php config file for Stripe keys:

// config/services.php

return [

	// ... other services credentials

	'stripe' => [
		'secret_key' => env('STRIPE_SECRET_KEY'),
		'publishable_key' => env('STRIPE_PUB_KEY'),
	]

];
1 like

Please or to participate in this conversation.