PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / PaymentGateways / PayPalCommerce / PayPalCheckoutSdk / AccessToken.php

AccessToken.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/PaymentGateways/PayPalCommerce/PayPalCheckoutSdk/AccessToken.php

70 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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