Skip to content

Commit

Permalink
fix(google): set google credentials path from config
Browse files Browse the repository at this point in the history
  • Loading branch information
imdhemy committed May 12, 2024
1 parent bd39929 commit dc68966
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/liap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
| @see https://imdhemy.com/laravel-iap-docs/docs/credentials/google-play
|
*/
'google_application_credentials' => base_path(env('GOOGLE_APPLICATION_CREDENTIALS')),
'google_application_credentials' => base_path((string)env('GOOGLE_APPLICATION_CREDENTIALS')),

/*
|--------------------------------------------------------------------------
Expand Down
15 changes: 3 additions & 12 deletions src/ServiceProviders/LiapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Imdhemy\Purchases\Subscription;
use Lcobucci\JWT\Decoder;
use Lcobucci\JWT\Encoding\JoseEncoder;
use RuntimeException;

/**
* Laravel Iap service provider.
Expand Down Expand Up @@ -114,18 +113,10 @@ private function registerConfig(): void
{
$this->mergeConfigFrom(self::CONFIG_PATH, self::CONFIG_KEY);

// Check if it should set GOOGLE_APPLICATION_CREDENTIALS to the configured path
$currentGoogleCredPath = getenv('GOOGLE_APPLICATION_CREDENTIALS');
if (is_string($currentGoogleCredPath) && file_exists($currentGoogleCredPath)) {
return;
}
$googleApplicationCredentials = (string)config('liap.google_application_credentials');

$googleCredentials = (string)config(self::CONFIG_KEY.'.google_application_credentials');
if (! empty($googleCredentials) && ! is_dir($googleCredentials)) {
if (! file_exists($googleCredentials)) {
throw new RuntimeException("Google Application Credentials file not found at $googleCredentials");
}
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$googleCredentials);
if (! empty($googleApplicationCredentials) && file_exists($googleApplicationCredentials)) {
putenv("GOOGLE_APPLICATION_CREDENTIALS=$googleApplicationCredentials");
}
}

Expand Down

0 comments on commit dc68966

Please sign in to comment.