Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cartalyst/stripe-laravel returns Error "The Stripe API key is not defined!" when making a new Stripe Instance

I want to dive into stripe and find out how to make payments.

I am using the cartalyst/stripe-laravel package to instantiate a new Stripe object like explained here.

Code should look like this:

$stripe = Stripe::make('your-stripe-api-key', 'your-stripe-api-version');

And indeed my code is the same:

public function chargeStripe()
{
    // dd(Input::all());
    // return env('STRIPE_PUBLIC_KEY');

    // this is not my real secret test key
    $stripe = Stripe::make('sk_test_IfJ649nAzKif3iOk0jj3XO5T', 'Version 101');


    dd($stripe);

}

When die and dumping I get the error

RuntimeException in Config.php line 43:
The Stripe API key is not defined!

And this is what this Config.php says:

class Config extends Collection implements ConfigInterface
{
    /**
     * Constructor.
     *
     * @param  string  $version
     * @param  string  $apiKey
     * @param  string  $apiVersion
     * @return void
     * @throws \RuntimeException
     */
    public function __construct($version, $apiKey, $apiVersion)
    {
        $api_key = $apiKey ?: getenv('STRIPE_API_KEY');

        $api_version = $apiVersion ?: getenv('STRIPE_API_VERSION') ?: '2015-03-24';

        if ( ! $api_key) {
            throw new \RuntimeException('The Stripe API key is not defined!');
        }

        parent::__construct(compact('version', 'api_key', 'api_version'));
    }
}

For some reason this method does not accept my arguments. Would be great if someone could give me a hint, what I am doing wrong. Thank you in advance.

like image 633
LoveAndHappiness Avatar asked Oct 14 '25 14:10

LoveAndHappiness


2 Answers

I just got it working by naming my secret key STRIPE_API_KEY in the .env file. I guess that this stripe package gets the API key from the env vars directly and doesn't use the config/services.php (at least for me). It seems to be working now.

like image 124
jeff Avatar answered Oct 17 '25 04:10

jeff


Just in case Anyone faces this issue, I came across this same issue when I transfered my site from localhost(Development) to online-site host (Production), and after running a lot of SSH command , no one seems to be working(e.g php artisan route:clear, config:clear, config:cache etc.), what i did was to

Goto app > bootstrap > cache and i renamed config.php to config_old.php (or something else), this would do away with your old config file and create a new one, laravels php artisan config:clear should have done same thing, but didnt work, this was what worked for me

like image 31
Neon Emmanuel Avatar answered Oct 17 '25 04:10

Neon Emmanuel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!