OAuthOAuth2ServicePaypal

PayPal service.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Paypal.php  
  1. class Paypal extends AbstractService 
  2. /** 
  3. * Defined scopes 
  4. * @link https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/ 
  5. * @see #attributes 
  6. */ 
  7. const SCOPE_OPENID = 'openid'; 
  8. const SCOPE_PROFILE = 'profile'; 
  9. const SCOPE_PAYPALATTRIBUTES = 'https://uri.paypal.com/services/paypalattributes'; 
  10. const SCOPE_EMAIL = 'email'; 
  11. const SCOPE_ADDRESS = 'address'; 
  12. const SCOPE_PHONE = 'phone'; 
  13. const SCOPE_EXPRESSCHECKOUT = 'https://uri.paypal.com/services/expresscheckout'; 
  14.  
  15. public function __construct( 
  16. CredentialsInterface $credentials,  
  17. ClientInterface $httpClient,  
  18. TokenStorageInterface $storage,  
  19. $scopes = array(),  
  20. UriInterface $baseApiUri = null 
  21. ) { 
  22. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  23.  
  24. if (null === $baseApiUri) { 
  25. $this->baseApiUri = new Uri('https://api.paypal.com/v1/'); 
  26.  
  27. /** 
  28. * {@inheritdoc} 
  29. */ 
  30. public function getAuthorizationEndpoint() 
  31. return new Uri('https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'); 
  32.  
  33. /** 
  34. * {@inheritdoc} 
  35. */ 
  36. public function getAccessTokenEndpoint() 
  37. return new Uri('https://api.paypal.com/v1/identity/openidconnect/tokenservice'); 
  38.  
  39. /** 
  40. * {@inheritdoc} 
  41. */ 
  42. protected function getAuthorizationMethod() 
  43. return static::AUTHORIZATION_METHOD_HEADER_BEARER; 
  44.  
  45. /** 
  46. * {@inheritdoc} 
  47. */ 
  48. protected function parseAccessTokenResponse($responseBody) 
  49. $data = json_decode($responseBody, true); 
  50.  
  51. if (null === $data || !is_array($data)) { 
  52. throw new TokenResponseException('Unable to parse response.'); 
  53. } elseif (isset($data['message'])) { 
  54. throw new TokenResponseException('Error in retrieving token: "' . $data['message'] . '"'); 
  55. } elseif (isset($data['name'])) { 
  56. throw new TokenResponseException('Error in retrieving token: "' . $data['name'] . '"'); 
  57.  
  58. $token = new StdOAuth2Token(); 
  59. $token->setAccessToken($data['access_token']); 
  60. $token->setLifeTime($data['expires_in']); 
  61.  
  62. if (isset($data['refresh_token'])) { 
  63. $token->setRefreshToken($data['refresh_token']); 
  64. unset($data['refresh_token']); 
  65.  
  66. unset($data['access_token']); 
  67. unset($data['expires_in']); 
  68.  
  69. $token->setExtraParams($data); 
  70.  
  71. return $token;