Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Set google credentials path from config #407

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading