[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/carlos-mg89/oauth/src/OAuth/OAuth2/Service/ -> Stripe.php (source)

   1  <?php
   2  
   3  namespace OAuth\OAuth2\Service;
   4  
   5  use OAuth\Common\Consumer\CredentialsInterface;
   6  use OAuth\Common\Http\Client\ClientInterface;
   7  use OAuth\Common\Http\Exception\TokenResponseException;
   8  use OAuth\Common\Http\Uri\Uri;
   9  use OAuth\Common\Http\Uri\UriInterface;
  10  use OAuth\Common\Storage\TokenStorageInterface;
  11  use OAuth\OAuth2\Token\StdOAuth2Token;
  12  
  13  class Stripe extends AbstractService
  14  {
  15      const SCOPE_READONLY = 'read_only';
  16      const SCOPE_READWRITE = 'read_write';
  17  
  18      public function __construct(
  19          CredentialsInterface $credentials,
  20          ClientInterface $httpClient,
  21          TokenStorageInterface $storage,
  22          $scopes = [],
  23          ?UriInterface $baseApiUri = null
  24      ) {
  25          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
  26  
  27          if (null === $baseApiUri) {
  28              $this->baseApiUri = new Uri('https://connect.stripe.com/');
  29          }
  30      }
  31  
  32      /**
  33       * {@inheritdoc}
  34       */
  35      public function getAuthorizationEndpoint()
  36      {
  37          return new Uri('https://connect.stripe.com/oauth/authorize');
  38      }
  39  
  40      /**
  41       * {@inheritdoc}
  42       */
  43      public function getAccessTokenEndpoint()
  44      {
  45          return new Uri('https://connect.stripe.com/oauth/token');
  46      }
  47  
  48      /**
  49       * {@inheritdoc}
  50       */
  51      protected function getAuthorizationMethod()
  52      {
  53          return static::AUTHORIZATION_METHOD_QUERY_STRING;
  54      }
  55  
  56      /**
  57       * {@inheritdoc}
  58       */
  59      protected function parseAccessTokenResponse($responseBody)
  60      {
  61          $data = json_decode($responseBody, true);
  62  
  63          if (null === $data || !is_array($data)) {
  64              throw new TokenResponseException('Unable to parse response.');
  65          } elseif (isset($data['error'])) {
  66              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
  67          }
  68  
  69          $token = new StdOAuth2Token();
  70          $token->setAccessToken($data['access_token']);
  71  
  72          unset($data['access_token']);
  73  
  74          $token->setExtraParams($data);
  75  
  76          return $token;
  77      }
  78  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1