-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExample.php
More file actions
122 lines (108 loc) · 3.03 KB
/
Example.php
File metadata and controls
122 lines (108 loc) · 3.03 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
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
<?php
/* at startup set API key */
require_once('./lib/Postmaster.php');
Postmaster::setApiKey("example-api-key");
/* at first validate recipient address */
$result = Postmaster_AddressValidation::validate(array(
"company" => "Postmaster Inc.",
"contact" => "Joe Smith",
"line1" => "701 Brazos St. Suite 1616",
"city" => "Austin",
"state" => "TX",
"zip_code" => "78701",
"country" => "US",
));
//var_dump($result);
/* if address is ok you can ask for time and rates for it */
$result = Postmaster_TransitTimes::get(array(
"from_zip" => "78701",
"to_zip" => "78704",
"weight" => 1.5,
"carrier" => "fedex",
));
//var_dump($result);
$result = Postmaster_Rates::get(array(
"from_zip" => "78701",
"to_zip" => "78704",
"weight" => 1.5,
"carrier" => "fedex",
));
//var_dump($result);
/* when user will choose delivery type you create shipment */
$result = Postmaster_Shipment::create(array(
"to" => array(
"company" => "Postmaster Inc.",
"contact" => "Joe Smith",
"line1" => "701 Brazos St. Suite 1616",
"city" => "Austin",
"state" => "TX",
"zip_code" => "78701",
"phone_no" => "512-693-4040",
),
"from" => array(
"company" => "Postmaster Inc.",
"contact" => "Joe Smith",
"line1" => "701 Brazos St. Suite 1616",
"city" => "Austin",
"state" => "TX",
"zip_code" => "78701",
"phone_no" => "512-693-4040",
),
"carrier" => "fedex",
"service" => "2DAY",
"package" => array(
"weight" => 1.5,
"length" => 10,
"width" => 6,
"height" => 8,
),
));
//var_dump($result);
/* store in your DB shipment ID for later use */
$shipment_id = $result->id;
/* anytime you can extract shipment data */
$sm = Postmaster_Shipment::retrieve($shipment_id);
//var_dump($sm);
/* or check delivery status */
$result = $sm->track();
//var_dump($result);
/* you can cancel shipment, but only before being picked up by the carrier */
$result = $sm->void();
//var_dump($result);
/* list all shipments */
$result = Postmaster_Shipment::all();
//var_dump($result);
/* list 3 newest shipments */
$result = Postmaster_Shipment::all(array("limit" => 3));
//var_dump($result);
/* monitor external package */
$result = Postmaster_Tracking::monitor_external(array(
"tracking_no" => "1ZW470V80310800043",
"url" => "http://example.com/your-http-post-listener",
"events" => ["Delivered", "Exception"]
));
//var_dump($result);
/* create box example */
$result = Postmaster_Package::create(array(
"width" => 10,
"height" => 12,
"length" => 8,
"name" => 'My Box'
));
var_dump($result);
/* list boxes example */
$result = Postmaster_Package::all(array(
"limit" => 2
));
var_dump($result);
/* fit items in box example */
$result = Postmaster_Package::fit(array(
"items" => array(
array("width" => 2.2, "length" => 3, "height" => 1, "count" => 2),
),
"packages" => array(
array("width" => 6, "length" => 6, "height" => 6, "sku" => "123ABC"),
array("width" => 12, "length" => 12, "height" => 12, "sku" => "456XYZ"),
),
));
var_dump($result);