diff --git a/src/Providers/PayPal.php b/src/Providers/PayPal.php index 386d4a9..fbff158 100644 --- a/src/Providers/PayPal.php +++ b/src/Providers/PayPal.php @@ -29,9 +29,9 @@ class PayPal extends Base protected string $authUrl = 'https://www.paypal.com/signin/authorize'; - protected string $tokenURL = 'https://api.sandbox.paypal.com/v1/oauth2/token'; + protected string $tokenURL = 'https://api-m.paypal.com/v1/oauth2/token'; - protected string $userinfoURL = 'https://api.paypal.com/v1/identity/openidconnect/userinfo'; + protected string $userinfoURL = 'https://api.paypal.com/v1/identity/openidconnect/userinfo?schema=openid'; protected array $scopes = [ 'openid', 'profile', 'email', 'address', @@ -42,11 +42,11 @@ class PayPal extends Base public function __construct(array $config) { parent::__construct($config); - $this->sandbox = (bool) $this->config->get('sandbox', false); + $this->sandbox = (bool)$this->config->get('sandbox', false); if ($this->sandbox) { $this->authUrl = 'https://www.sandbox.paypal.com/signin/authorize'; $this->tokenURL = 'https://api-m.sandbox.paypal.com/v1/oauth2/token'; - $this->userinfoURL = 'https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo'; + $this->userinfoURL = 'https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo?schema=openid'; } } @@ -97,6 +97,7 @@ protected function getTokenUrl(): string * @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException * * @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-getaccesstoken + * */ public function tokenFromCode(string $code): array { @@ -104,42 +105,16 @@ public function tokenFromCode(string $code): array $this->getTokenUrl(), [ 'form_params' => [ - Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_AUTHORATION_CODE, + Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_CLIENT_CREDENTIALS, Contracts\RFC6749_ABNF_CODE => $code, ], 'headers' => [ 'Accept' => 'application/json', - 'Authorization' => 'Basic '.\base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())), - ], - ] - ); - - return $this->normalizeAccessTokenResponse((string) $response->getBody()); - } - - /** - * @throws \GuzzleHttp\Exception\GuzzleException - * @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException - * - * @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-exchangerefreshtokenforaccesstoken - */ - public function refreshToken(string $refreshToken): mixed - { - $response = $this->getHttpClient()->post( - $this->getTokenUrl(), - [ - 'form_params' => [ - Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_REFRESH_TOKEN, - Contracts\RFC6749_ABNF_REFRESH_TOKEN => $refreshToken, - ], - 'headers' => [ - 'Accept' => 'application/json', - 'Authorization' => 'Basic '.\base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())), + 'Authorization' => 'Basic ' . \base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())), ], ] ); - - return $this->normalizeAccessTokenResponse((string) $response->getBody()); + return $this->normalizeAccessTokenResponse((string)$response->getBody()); } /** @@ -154,11 +129,10 @@ protected function getUserByToken(string $token): array [ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', - 'Authorization' => 'Bearer '.$token, + 'Authorization' => 'Bearer ' . $token, ], ] ); - return $this->fromJsonBody($response); }