@@ -29,9 +29,9 @@ class PayPal extends Base
2929
3030 protected string $ authUrl = 'https://www.paypal.com/signin/authorize ' ;
3131
32- protected string $ tokenURL = 'https://api.sandbox .paypal.com/v1/oauth2/token ' ;
32+ protected string $ tokenURL = 'https://api-m .paypal.com/v1/oauth2/token ' ;
3333
34- protected string $ userinfoURL = 'https://api.paypal.com/v1/identity/openidconnect/userinfo ' ;
34+ protected string $ userinfoURL = 'https://api.paypal.com/v1/identity/openidconnect/userinfo?schema=openid ' ;
3535
3636 protected array $ scopes = [
3737 'openid ' , 'profile ' , 'email ' , 'address ' ,
@@ -42,11 +42,11 @@ class PayPal extends Base
4242 public function __construct (array $ config )
4343 {
4444 parent ::__construct ($ config );
45- $ this ->sandbox = (bool ) $ this ->config ->get ('sandbox ' , false );
45+ $ this ->sandbox = (bool )$ this ->config ->get ('sandbox ' , false );
4646 if ($ this ->sandbox ) {
4747 $ this ->authUrl = 'https://www.sandbox.paypal.com/signin/authorize ' ;
4848 $ this ->tokenURL = 'https://api-m.sandbox.paypal.com/v1/oauth2/token ' ;
49- $ this ->userinfoURL = 'https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo ' ;
49+ $ this ->userinfoURL = 'https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo?schema=openid ' ;
5050 }
5151 }
5252
@@ -97,49 +97,24 @@ protected function getTokenUrl(): string
9797 * @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
9898 *
9999 * @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-getaccesstoken
100+ *
100101 */
101102 public function tokenFromCode (string $ code ): array
102103 {
103104 $ response = $ this ->getHttpClient ()->post (
104105 $ this ->getTokenUrl (),
105106 [
106107 'form_params ' => [
107- Contracts \RFC6749_ABNF_GRANT_TYPE => Contracts \RFC6749_ABNF_AUTHORATION_CODE ,
108+ Contracts \RFC6749_ABNF_GRANT_TYPE => Contracts \RFC6749_ABNF_CLIENT_CREDENTIALS ,
108109 Contracts \RFC6749_ABNF_CODE => $ code ,
109110 ],
110111 'headers ' => [
111112 'Accept ' => 'application/json ' ,
112- 'Authorization ' => 'Basic ' .\base64_encode (\sprintf ('%s:%s ' , $ this ->getClientId (), $ this ->getClientSecret ())),
113- ],
114- ]
115- );
116-
117- return $ this ->normalizeAccessTokenResponse ((string ) $ response ->getBody ());
118- }
119-
120- /**
121- * @throws \GuzzleHttp\Exception\GuzzleException
122- * @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
123- *
124- * @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-exchangerefreshtokenforaccesstoken
125- */
126- public function refreshToken (string $ refreshToken ): mixed
127- {
128- $ response = $ this ->getHttpClient ()->post (
129- $ this ->getTokenUrl (),
130- [
131- 'form_params ' => [
132- Contracts \RFC6749_ABNF_GRANT_TYPE => Contracts \RFC6749_ABNF_REFRESH_TOKEN ,
133- Contracts \RFC6749_ABNF_REFRESH_TOKEN => $ refreshToken ,
134- ],
135- 'headers ' => [
136- 'Accept ' => 'application/json ' ,
137- 'Authorization ' => 'Basic ' .\base64_encode (\sprintf ('%s:%s ' , $ this ->getClientId (), $ this ->getClientSecret ())),
113+ 'Authorization ' => 'Basic ' . \base64_encode (\sprintf ('%s:%s ' , $ this ->getClientId (), $ this ->getClientSecret ())),
138114 ],
139115 ]
140116 );
141-
142- return $ this ->normalizeAccessTokenResponse ((string ) $ response ->getBody ());
117+ return $ this ->normalizeAccessTokenResponse ((string )$ response ->getBody ());
143118 }
144119
145120 /**
@@ -154,11 +129,10 @@ protected function getUserByToken(string $token): array
154129 [
155130 'headers ' => [
156131 'Content-Type ' => 'application/x-www-form-urlencoded ' ,
157- 'Authorization ' => 'Bearer ' . $ token ,
132+ 'Authorization ' => 'Bearer ' . $ token ,
158133 ],
159134 ]
160135 );
161-
162136 return $ this ->fromJsonBody ($ response );
163137 }
164138
0 commit comments