4

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.

2
  • It looks like your version may be wrong ... Looking at the Stripe API (stripe.com/docs/api#versioning) it says the current version is "2015-04-07." Not sure if that matches up with your Version 101.
    – cfkane
    Apr 21, 2015 at 20:12
  • Unfortunately that is not the solution, just tried it but it failed with the same error. Point is that it does not even require the "version", only the API, which is a random string. I really don't get it. Might just uninstall cartalyst and do It manually, but I would really appreciate continueing with their package. Apr 21, 2015 at 21:34

3 Answers 3

3

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.

3

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

1
  • Why not just use Laravel Cashier? The package used in this question hasn't been updated in two years.
    – kemp
    Oct 12, 2018 at 1:57
0

In your config/services.php you need to include also the secret key. It is explained in the docs, yet I don't know why I overlooked this.

'stripe' => [
    'key'   => env('STRIPE_PUBLIC_KEY'),
    'secret' => env('STRIPE_SECRET_KEY'),
],
2
  • 2
    Are you using Laravel 5? It seems like the package is ignoring my services.php. The documentation only shows the secret key, which I provided, and adding the public key makes no difference. What am I missing?
    – NightMICU
    Jun 5, 2015 at 15:38
  • For what it is worth, I am having a similar problem where this error seems to be coming from the fact that the services.php file cannot be read. Ironically, this is happening on a live clone of a dev box, where the dev box works and the live does not.
    – CopyJosh
    Mar 11, 2016 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.