laravel / cashier-mollie

MIT License
375 stars 63 forks source link

Invalid API key after download #61

Closed timyboy12345 closed 5 years ago

timyboy12345 commented 5 years ago

I just downloaded the latest version of cashier-mollie and was excited to use it. However, after downloading it gave the error Mollie\Api\Exceptions\ApiException : Invalid API key:. An API key must start with 'test' or 'live' and must be at least 30 characters long.', while I'm not using the API anywhere.

I also added the MOLLIE_KEY="***" key (with my real key, of course) to my .env file, but this doesn't seem to do anything. Every time I do try to execute a command through the console (even trying to clear the cache) the error appears. I can't even continue to step 1 of the installation (php artisan cashier:install) because this throws the same error.

I've pasted the whole error below:

Mollie\Api\Exceptions\ApiException  : Invalid API key: ''. An API key must start with 'test_' or 'live_' and must be at least 30 characters long.

  at D:\PHPStorm folders\WordQuest-4\vendor\mollie\mollie-api-php\src\MollieApiClient.php:339
    335|     {
    336|         $apiKey = trim($apiKey);
    337|
    338|         if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) {
  > 339|             throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long.");
    340|         }
    341|
    342|         $this->apiKey = $apiKey;
    343|         $this->oauthAccess = false;

  Exception trace:

  1   Mollie\Api\MollieApiClient::setApiKey("")
      D:\PHPStorm folders\WordQuest-4\vendor\mollie\laravel-mollie\src\Wrappers\MollieApiWrapper.php:92

  2   Mollie\Laravel\Wrappers\MollieApiWrapper::setApiKey()
      D:\PHPStorm folders\WordQuest-4\vendor\mollie\laravel-mollie\src\Wrappers\MollieApiWrapper.php:67

  Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Does anyone have an idea how I can fix this issue?

PS: I'm using Laravel framework 6.0.3

timyboy12345 commented 5 years ago

Well, I did fix it. But it still seems like it could be solved a little easier. Here's what I did to fix it:

  1. Remove the cashier-mollie package
  2. Clear the cache and config
  3. Re-require the cashier-mollie package. Because the config is reloaded it reads the key and doesn't throw an error.

Maybe there could be a check to make sure a key has been passed to the config? This way, the error isn't thrown.

sandervanhooft commented 5 years ago

Thanks for following up :).

The issue was probably solved by setting the key in .env and clearing the cache.

Currently there's no way around this as Laravel Mollie's ServiceProvider needs to be eagerly loaded. May solve that later on down the road.