-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull-example.php
76 lines (62 loc) · 2.17 KB
/
full-example.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
<?php
require('vendor/autoload.php');
function getStatus ($xml)
{
/** @var SimpleXMLElement $responseXML */
$responseXML = simplexml_load_string($xml);
/** @var SimpleXMLElement $orderIdNode */
$orderIdNode = $responseXML->xpath("//BackgroundReports/BackgroundReportPackage/OrderId")[0];
/** @var SimpleXMLElement $statusNode */
$statusNode = $responseXML->xpath("//BackgroundReports/BackgroundReportPackage/ScreeningStatus/OrderStatus")[0];
return [strval($orderIdNode), strval($statusNode)];
}
// Get ENV variables
$dotEnv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotEnv->safeLoad();
$userId = $_ENV['USER_ID'];
$password = $_ENV['USER_PASSWORD'];
$url = $_ENV['TAZ_URL'];
// Prepare XML to send to TAZ works
$xml = file_get_contents('example-04.xml');
$xml = str_replace('{{userId}}', $userId, $xml);
$xml = str_replace('{{password}}', $password, $xml);
$xmlCheck = file_get_contents('check-status.xml');
$xmlCheck = str_replace('{{userId}}', $userId, $xmlCheck);
$xmlCheck = str_replace('{{password}}', $password, $xmlCheck);
$startTime = microtime(true);
// Send XML to TAZ
$client = new \GuzzleHttp\Client([
'base_uri' => $url,
'timeout' => 2.0
]);
try {
$response = $client->post("/send/interchange", [
'form_params' => [
'request' => $xml
],
]);
echo "OK:", PHP_EOL;
echo $response->getBody();
[$orderId, $status] = getStatus($response->getBody());
$xmlCheck = str_replace('{{orderId}}', $orderId, $xmlCheck);
$count = 1;
while ($status === 'x:pending') {
$response = $client->post("/send/interchange", [
'form_params' => [
'request' => $xmlCheck
],
]);
echo PHP_EOL, "CHECK {$count}:", PHP_EOL;
$count++;
[$orderId, $status] = getStatus($response->getBody());
$lastResponse = $response->getBody();
sleep(1);
}
echo $lastResponse, PHP_EOL;
$endTime = microtime(true);
$timeDiff = $endTime - $startTime;
echo PHP_EOL, PHP_EOL, 'Time to become ready' . $timeDiff, PHP_EOL;
} catch (\GuzzleHttp\Exception\ClientException $e) {
echo "ERROR:", PHP_EOL;
echo $e->getMessage();
}