You are here

class ClientCredentials in Commerce PayPal 8

Client credentials grant type.

Hierarchy

  • class \Drupal\commerce_paypal\ClientCredentials extends \Sainsburys\Guzzle\Oauth2\GrantType\ClientCredentials

Expanded class hierarchy of ClientCredentials

File

src/ClientCredentials.php, line 12

Namespace

Drupal\commerce_paypal
View source
class ClientCredentials extends BaseClientCredentials {

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * Constructs a new ClientCredentials object.
   *
   * @param \GuzzleHttp\ClientInterface $client
   *   The client.
   * @param array $config
   *   The configuration.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(ClientInterface $client, array $config, StateInterface $state) {
    parent::__construct($client, $config);
    $this->state = $state;
  }

  /**
   * {@inheritdoc}
   */
  public function getToken() {
    $token = parent::getToken();

    // Store the token retrieved for later reuse (to make sure we don't request
    // for a new one on each API request).
    $this->state
      ->set($this->config['token_key'], [
      'token' => $token
        ->getToken(),
      'expires' => $token
        ->getExpires()
        ->getTimestamp(),
    ]);
    return $token;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientCredentials::$state protected property The state service.
ClientCredentials::getToken public function
ClientCredentials::__construct public function Constructs a new ClientCredentials object.