-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrack.php
More file actions
62 lines (43 loc) · 1.81 KB
/
Copy pathtrack.php
File metadata and controls
62 lines (43 loc) · 1.81 KB
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
<?php
/**
* Follow the postal items of a mailbox, and look one up the way a recipient would.
*
* POSTBODE_API_KEY=your-key php examples/track.php PSBD
*/
declare(strict_types=1);
/** @var \Postbode\PostbodeApiClient $postbode */
$postbode = require __DIR__ . '/bootstrap.php';
$customerCode = $argv[1] ?? null;
if ($customerCode === null) {
fwrite(STDERR, "Usage: php examples/track.php <customer-code> [postal-code-of-a-recipient]\n");
exit(1);
}
$postals = $postbode->postals->list($customerCode, limit: 10);
if ($postals->isEmpty()) {
echo "Mailbox {$customerCode} has no postal items yet.\n";
exit(0);
}
printf("%-14s %-22s %s\n", 'REFERENCE', 'TYPE', 'STATUS');
foreach ($postals as $item) {
printf("%-14s %-22s %s\n", $item->reference, $item->type->name, $item->status->name);
}
echo "\n";
// The full resource carries tracking details, costs and tags.
$detail = $postbode->postals->get($postals->first()->uuid);
printf("Detail for %s\n", $detail->reference);
printf(" Shipping %s\n", $detail->shipping->name);
printf(" Price € %.2f incl. VAT\n", $detail->financial->price->amountInclVat);
printf(" Final %s\n", $detail->status->isFinal() ? 'yes' : 'no, still moving');
if ($detail->tracking->isAvailable()) {
printf(" Tracking %s\n", $detail->tracking->url);
}
foreach ($detail->financial->transactions as $transaction) {
printf(" Charged %-30s € %.2f\n", $transaction->description, $transaction->amount->inclVat);
}
// Public tracking needs only the reference and the recipient's postal code, so it
// is safe to expose to the recipient themselves.
$postalCode = $argv[2] ?? null;
if ($postalCode !== null) {
$tracked = $postbode->tracking->track($detail->reference, 'NL', $postalCode);
printf("\nPublic view: %s — %s\n", $tracked->address, $tracked->status);
}