简体   繁体   中英

In Laravel 5.2, Laravel Cashier stripe can'not create subscription.

I am using Laravel 5.2 and Cashier. I want create subscription

 $user->newSubscription('premium', 'monthly')->create($request->get('stripeToken'));

And I get this error

Api in RequestOptions.php line 78: The second argument to Stripe API method calls is an optional per-request apiKey, which must be a string, or per-request options, which must be an array. (HINT: you can set a global apiKey by "Stripe::setApiKey()")

I've run into the same problem today - the reason behind it is that the Laravel\\Cashier\\Billable::getStripeKey() method gets the environment variable by using getenv('STRIPE_SECRET') instead of actually using config, which forces you to have the environment variable called STRIPE_SECRET - I had mine named differently and that was causing the problem - so make sure that your environment variable for the stripe's secret key is named STRIPE_SECRET .

The method that's causing the problem:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM