Reputation: 1
I am having errors when trying to access the subscription section on my app. It's something with the stripe API, this error occurs mostly when server caches are being cleared. I checked to clear caches, check config.app.php
, payment controller, and all of that but not really understanding the source of this error!
Therefore I need someone's help, maybe someone who had this issue before. Here is the code line for that on vendor/stripe/stripe-php/lib/BaseStripeClient.php
. Please suggest a solution for this error! I will be grateful:
if (\is_string($config)) {
$config = ['api_key' => $config];
} elseif (!\is_array($config)) {
throw new \Stripe\Exception\InvalidArgumentException('$config must be a string or an array');
}
Upvotes: -1
Views: 8015
Reputation: 14634
In my case the problem was env()
function that I called outside of the config files.
In documentation says that this can cause a problem with caching config files so the best way to go is to create those Stripe keys in config/services.php
and get them there with env()
Upvotes: -1
Reputation: 41
Do not use env('STRIPE_SECRET_KEY')
.
If you declared your .env variable using env('STRIPE_SECRET_KEY')
in your Controller, there is a better approach.
First, run php artisan config:cache
. This command is used to cache the configuration files, but if you're looking for your Stripe keys, they won't be available in the bootstrap/cache/config.php
file. That's why running config:cache
won't solve the issue.
To properly set your variables in the configuration, you need to define them in services.php
like this:
'stripe' => [
'secret_key' => env('STRIPE_SECRET_KEY'),
// You can also add subscription IDs or product IDs here
'subscriptions' => [
'premium' => env('STRIPE_PREMIUM_SUB_ID'),
]
],
After making these changes, run php artisan config:cache
to cache the new keys.
You can then access these keys in your Controllers using the following syntax:
config('services.stripe.secret_key')
config('services.stripe.subscriptions.premium')
By following this approach, you can properly configure and access your Stripe keys.
Upvotes: -1
Reputation: 2090
Just run these commands
php artisan cache:clear && php artisan route:clear && php artisan view:clear && composer clear-cache && composer dump-autoload && php artisan config:clear
And then
php artisan serve
Upvotes: -1
Reputation: 115
Your application is trying to access STRIPE_KEY
from the .env file. But it fails to do so.
Make sure you have a key and if run the following command:
php artisan config:clear
personally for me php artisan config:cache
did not do the trick.
Upvotes: -1
Reputation: 748
make sure you have STRIPE_SECRET and STRIPE_KEY in your .env file
then you can just go with php artisan config:cache
if you have these in you .env file and error persists try removing the the files in bootstrap/cache i.e. rm -rf bootsrap/cache/*
Upvotes: 4
Reputation: 655
Your application is pulling a cached version of its config. Delete the bootstrap/cache/config.php file and refresh your browser and the error should go away.
I haven't had much luck with running php artisan cache:clear
so I just remove the file manually or run the command below.
If you run the terminal command rm -rf bootstrap/cache/*
in the root of the application it should remove all the files in the cache directory.
Upvotes: 0