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

SteamDiesel's avatar

(SOLVED) Stripe Error with Spark - did not set a valid publishable key

Hey Team,

When I enter a credit card number (both test and my own) and try to submit for a subscription, using both the test API keys and my live API keys, in both my homestead and on the live forge server, I get the following error in my console:

js.stripe.com/:3 Uncaught Error: You did not set a valid publishable key. Call Stripe.setPublishableKey() with your publishable key. For more info, see https://stripe.com/docs/stripe.js

    at Function.Stripe.isDoubleLoaded.Stripe.utils.b.validateKey (js.stripe.com/:3)

    at Function.Stripe.token.b.create (js.stripe.com/:2)

    at Function.Stripe.card.c.createToken (js.stripe.com/:2)

    at o.subscribe (app.js:27)

    at Proxy.n (app.js:67)

    at click (eval at Ci (app.js:67), <anonymous>:2:25288)

    at HTMLButtonElement.t (app.js:67)

I have set my keys in the .env and config/services.php with both pk_live and sk_live set correctly. I thought the spark app was supposed to reference these values, so I don't know where it would be looking. all plans have been established in both the app/providers/SparkServiceProvider.php and the stripe plans panel. ID and name are the same, prices are the same. I have a coupon for 99% off, which I have been using, but that doesn't seem to be related. here's my SparkServiceProvider

namespace App\Providers;

use Carbon\Carbon;
use Laravel\Cashier\Cashier;
use Laravel\Spark\Spark;
use Laravel\Spark\Providers\AppServiceProvider as ServiceProvider;

class SparkServiceProvider extends ServiceProvider
{
    /**
     * Your application and company details.
     *
     * @var array
     */
    protected $details = [
        'vendor' => 'xxxxxxxxxx',
        'product' => 'xxxxxxxxxxx',
        'street' => 'xxxxxxxxx',
        'location' => 'xxxxxxxxxx',
        'phone' => 'xxxxxxxxxx',
    ];

    /**
     * The address where customer support e-mails should be sent.
     *
     * @var string
     */
    protected $sendSupportEmailsTo = '[email protected]';

    /**
     * All of the application developer e-mail addresses.
     *
     * @var array
     */
    protected $developers = [
        //
        '[email protected]'
    ];

    /**
     * Indicates if the application will expose an API.
     *
     * @var bool
     */
    protected $usesApi = false;

    /**
     * Finish configuring Spark for the application.
     *
     * @return void
     */
    public function booted()
    {
        Cashier::useCurrency('aud', '$');

        Spark::useStripe()->noCardUpFront()->teamTrialDays(10);

        //disabled so users can hot switch teams through native spark dashboard.
//        Spark::identifyTeamsByPath();

        Spark::useRoles([
            'fb' => 'User',
            'sales' => 'Sales',

        ]);

        Spark::useTwoFactorAuth();


        Spark::teamPlan('Beta 3', 'BETA3')
            ->price(149)
            ->maxTeamMembers(3)
            ->features([
                '3 team members',
                'Price fixed for 3 years (Beta plans only)',
                'all future features and upgrades'
            ]);

        Spark::teamPlan('Beta 5', 'BETA5')
            ->price(249)
            ->maxTeamMembers(5)
            ->features([
                '5 team members',
                'Price fixed for 3 years (Beta plans only)',
                'all future features and upgrades'
            ]);

        Spark::teamPlan('Beta 7', 'BETA7')
            ->price(349)
            ->maxTeamMembers(7)
            ->features([
                '7 team members',
                'Price fixed for 3 years (Beta plans only)',
                'all future features and upgrades'
            ]);

        Spark::teamPlan('Beta 10', 'BETA10')
            ->price(499)
            ->maxTeamMembers(10)
            ->features([
                '10 team members',
                'Price fixed for 3 years (Beta plans only)',
                'all future features and upgrades'
            ]);



    }
}

Attempted solutions: log out, restarted server, log back in.

I haven't touched the js that runs Spark, I didn't think I should need to. I've just deployed to AWS through Forge. I'm based in Australia. I'm using Stripe for payments with the native spark setup, Stripe account is activated. Laravel 5.4

Is there an undocumented step I should be following after adding the API keys to ensure the js for spark and stripe get my keys?

0 likes
1 reply
SteamDiesel's avatar
SteamDiesel
OP
Best Answer
Level 6

I've found a solution. I have my services.php stripe section setup with hard-coded stripe keys instead of referencing the .env file.

config/services Before Fix:

    'stripe' => [
        'model'  => App\User::class,
        'key'    => env('pk_test_xxxxxxxxxxxxx'),
        'secret' => env('sk_test_xxxxxxxxxxxxx'),
    ],

config/services After Fix:

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

I have no idea why I did this, but I recall following some instructions somewhere that told to hardcode the values. Which, now that I know more than I did a few days ago, would be terrible for security.

Please or to participate in this conversation.