Requests
1 year ago
AccessToken.php
3 years ago
AuthorizationInjector.php
2 years ago
PayPalHttpClient.php
2 years ago
ProcessorResponseError.php
2 years ago
AccessToken.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\PayPalCommerce\PayPalCheckoutSdk; |
| 4 | |
| 5 | /** |
| 6 | * Class AccessToken. |
| 7 | * |
| 8 | * @since 2.25.0 |
| 9 | */ |
| 10 | class AccessToken extends \PayPalCheckoutSdk\Core\AccessToken |
| 11 | { |
| 12 | /** |
| 13 | * Token creation date. |
| 14 | * |
| 15 | * @since 2.25.0 |
| 16 | * @var int |
| 17 | */ |
| 18 | protected $nonce; |
| 19 | |
| 20 | /** |
| 21 | * Returns true if the token is expired. |
| 22 | * |
| 23 | * @since 2.25.0 |
| 24 | */ |
| 25 | public function isExpired(): bool |
| 26 | { |
| 27 | return time() >= $this->getExpirationDate(); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Returns the token creation date. |
| 32 | * |
| 33 | * The creation date is the first 19 characters of the nonce. |
| 34 | * Example nonce: 2023-02-07T05:03:17ZPeYxT6_thWGlTaamtMGYt5RQzVHx5B4dlNjLNhoF0tM |
| 35 | * |
| 36 | * @since 2.25.0 |
| 37 | */ |
| 38 | protected function getCreationDate(): int |
| 39 | { |
| 40 | return strtotime(substr($this->nonce, 0, 19)); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the token expiration date. |
| 45 | * |
| 46 | * @since 2.25.0 |
| 47 | */ |
| 48 | protected function getExpirationDate(): int |
| 49 | { |
| 50 | return $this->getCreationDate() + $this->expiresIn; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns the class object. |
| 55 | * |
| 56 | * @since 2.25.0 |
| 57 | */ |
| 58 | public static function fromArray(array $data): self |
| 59 | { |
| 60 | $accessToken = new self( |
| 61 | $data['accessToken'], |
| 62 | $data['tokenType'], |
| 63 | $data['expiresIn'] |
| 64 | ); |
| 65 | $accessToken->nonce = $data['nonce']; |
| 66 | |
| 67 | return $accessToken; |
| 68 | } |
| 69 | } |
| 70 |