-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
131 lines (112 loc) · 4.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
require 'vendor/autoload.php';
class Main
{
private string $jwtToken;
private string $clientGuid;
private string $baseUrl;
private Client $client;
/**
* @var string[]
*/
private array $headers;
private string $clientProductGuid;
public function __construct()
{
$dotEnv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotEnv->safeLoad();
$this->jwtToken = $_ENV['JWT_TOKEN'];
$this->clientGuid = $_ENV['CLIENT_GUID'];
$this->baseUrl = $_ENV['TAZ_URL'];
$this->clientProductGuid = 'a04cc4e3-7af8-4f0f-a4c7-c4ca77ca220c'; // Tenant Product // can be obtained using allProducts function
$this->client = new Client();
$this->headers = [
'Content-Type' => 'application/json',
'Authorization' => "Bearer {$this->jwtToken}"
];
}
public function allProducts()
{
$request = new Request('GET', $this->baseUrl . '/clients/' . $this->clientGuid . '/products', $this->headers);
$res = $this->client->sendAsync($request)->wait();
dump(json_decode($res->getBody()));
}
public function createApplicantThatUsesQuickApp(string $firstName, string $lastName, string $email): string
{
$data = [
'firstName' => $firstName,
'lastName' => $lastName,
'email' => $email,
'textingEnabled' => false, // true if you provide the phoneNumber
'phoneNumber' => null,
];
$body = json_encode($data);
$request = new Request('POST', "{$this->baseUrl}/clients/{$this->clientGuid}/applicants", $this->headers, $body);
$res = $this->client->sendAsync($request)->wait();
$response = json_decode($res->getBody());
dump($response);
return $response->applicantGuid;
}
public function submitOrder(string $applicantGuid): string
{
$data = [
"applicantGuid" => $applicantGuid,
"clientProductGuid" => $this->clientProductGuid,
"useQuickApp" => true,
"externalIdentifier" => "guid-from-your-system", // the id on your system to cross-reference
"quickappNotifyApplicants" => true, // send the notification right away
"certifyPermissiblePurpose" => true
];
$body = json_encode($data);
$request = new Request('POST', "{$this->baseUrl}/clients/{$this->clientGuid}/orders", $this->headers, $body);
$res = $this->client->sendAsync($request)->wait();
$response = json_decode($res->getBody());
dump($response);
return $response->orderGuid;
}
public function checkOrderStatus(string $orderGuid): string
{
$request = new Request("GET", "{$this->baseUrl}/clients/{$this->clientGuid}/orders/{$orderGuid}/status", $this->headers);
$res = $this->client->sendAsync($request)->wait();
$response = json_decode($res->getBody());
dump($response);
return $response->orderDetail->status;
}
public function getPdf(string $orderGuid)
{
$request = new Request("GET", "{$this->baseUrl}/clients/{$this->clientGuid}/orders/{$orderGuid}/resultsPdf", $this->headers);
$res = $this->client->sendAsync($request)->wait();
$response = json_decode($res->getBody());
dump($response);
}
public function allOrders()
{
$request = new Request("GET", "{$this->baseUrl}/clients/{$this->clientGuid}/orders?page=0&size=20", $this->headers);
$res = $this->client->sendAsync($request)->wait();
$response = json_decode($res->getBody());
dump($response);
}
public function allClients()
{
$request = new Request("GET", "{$this->baseUrl}/clients?page=0&size=20", $this->headers);
$res = $this->client->sendAsync($request)->wait();
$response = json_decode($res->getBody());
dump($response);
}
}
$main = new Main();
$applicantGuid = $main->createApplicantThatUsesQuickApp("Marcelo", "Andrade", "[email protected]");
$orderGuid = $main->submitOrder($applicantGuid);
// $orderGuid = "a394f387-4887-4f27-9d4f-4ce3542e1aeb";
$status = $main->checkOrderStatus($orderGuid);
// app-pending (APPLICANT_PENDING) means the user have not opened the quickapp form yet
// app-ready (APPLICANT_READY) means the user have submitted all the info in quickapp
// wait or listen for webhook call until status is 'complete'
// there are other statuses: https://docs.developer.tazworks.com/?version=latest#16c2bff6-501c-432b-a89d-19141f277fc6
// Misc calls
// $main->getPdf($orderGuid); die();
// $main->allOrders(); die();
// $main->allProducts(); die();
// $main->allClients(); die();