PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.21.0
GiveWP – Donation Plugin and Fundraising Platform v2.21.0
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 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Tracking / AccessToken.php

AccessToken.php in GiveWP – Donation Plugin and Fundraising Platform 2.21.0, at src/Tracking/AccessToken.php

65 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Tracking;
4
5 use Give\Tracking\Enum\EventType;
6 use Give\Tracking\Repositories\TelemetryAccessDetails;
7 use Give\Tracking\TrackingData\WebsiteInfoData;
8
9 /**
10 * Class AccessTokenGenerator
11 * @package Give\Tracking
12 *
13 * @since 2.10.0
14 */
15 class AccessToken
16 {
17 /**
18 * @var TrackClient
19 */
20 private $trackClient;
21
22 /**
23 * @var TelemetryAccessDetails
24 */
25 private $telemetryAccessDetails;
26
27 /**
28 * AccessToken constructor.
29 *
30 * @param TrackClient $trackClient
31 * @param TelemetryAccessDetails $telemetryAccessDetails
32 */
33 public function __construct(TrackClient $trackClient, TelemetryAccessDetails $telemetryAccessDetails)
34 {
35 $this->trackClient = $trackClient;
36 $this->telemetryAccessDetails = $telemetryAccessDetails;
37 }
38
39 /**
40 * Store access token
41 *
42 * @since 2.10.0
43 */
44 public function store()
45 {
46 /* @var WebsiteInfoData $dataClass */
47 $dataClass = give(WebsiteInfoData::class);
48
49 $response = $this->trackClient->post(new EventType(EventType::CREATE_TOKEN), $dataClass, ['blocking' => true]);
50 if (is_wp_error($response)) {
51 return false;
52 }
53
54 $response = json_decode(wp_remote_retrieve_body($response), true);
55 if (empty($response['success'])) {
56 return false;
57 }
58
59 $token = $response['data']['access_token'];
60 $this->telemetryAccessDetails->saveAccessTokenOptionValue($token);
61
62 return true;
63 }
64 }
65