Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Stripe No API key provided. (HINT: set your API key using Stripe::setApiKey()

Yes, I know, there is an exact same question there but the "solution" is not approved nor specified as it should.

So: 1) I installed the stripe library v.3.0 by php composer.phar require stripe/etc

and it installed ok, (otherwise I wouldn't have actually received that error)

2) I have the public test key in the blade Form in the Head section alright

3) Then at the controller I included inside the public function that receives the data from the Form the following: (no problem not my real secret key)

$token = Input::get('stripeToken');
Stripe::setApiKey("sk_test_1VJeJsdfsdgdgVbJODDDD");

3) I also put it in the .env file as

STRIPE_API_SECRET='sk_test_1VJeJsvj7l2ft2eXXsevDD'

and made a call from the config/services.php as

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

but I keep getting that error.

The other same question at SO says that it has "solved" it by:

the solution was to put the stripe api key into AppServiceProvider, into register() class.

That is completely vague, inaccurate and don't know what he is talking about.

Anyone knows? thank you very much

like image 466
patricio Avatar asked Sep 13 '15 17:09

patricio


People also ask

How do I get the API key of Stripe?

Stripe APIs use your secret key to authenticate requests from your server. To find your API secret key for test mode: Open the API keys page. Under Standard keys, in the Secret key row, click Reveal test key and save the value.

What is publishable key in Stripe?

Publishable API keys are meant solely to identify your account with Stripe, they aren't secret. Publishable keys only have the power to create tokens. Secret API keys should be kept confidential and only stored on your own account. Your account's secret API key can perform any API request to Stripe without restriction.

Do Stripe API keys expire?

Stripe CLI keys expire in 60 or 90 days, so you have to refresh them.


1 Answers

If you look at the Billable code:

/**
 * Get the Stripe API key.
 *
 * @return string
 */
public static function getStripeKey()
{
    return static::$stripeKey ?: getenv('STRIPE_SECRET');
}

/**
 * Set the Stripe API key.
 *
 * @param  string  $key
 * @return void
 */
public static function setStripeKey($key)
{
    static::$stripeKey = $key;
}

It wants either the static variable or the STRIPE_SECRET environment variable to be defined.

The other answer is a bit vague, but offers a solution. In your AppServiceProvider:

public function register()
{
    \App\Models\User::setStripeKey(\Config::get('services.stripe.secret'));
}
like image 175
Alix Axel Avatar answered Sep 28 '22 13:09

Alix Axel