-
Notifications
You must be signed in to change notification settings - Fork 11
/
labels_create.php
112 lines (104 loc) · 2.26 KB
/
labels_create.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
<?php
require('credentials.php');
use Postmen\Postmen;
// TODO put ID of your shipper account
$shipper = NULL;
if(!isset($shipper)) {
echo "\$shipper is not set, modify file labels_create.php\n";
}
$parcel = array(
'description' => 'info about the parcel',
'box_type' => 'custom',
'weight' => array (
'value' => 1.5,
'unit' => 'kg',
),
'dimension' => array (
'width' => 20,
'height' => 30,
'depth' => 40,
'unit' => 'cm',
),
'items' => array (
0 => array (
'description' => 'Food Bar',
'origin_country' => 'USA',
'quantity' => 2,
'price' => array (
'amount' => 50,
'currency' => 'USD',
),
'weight' => array (
'value' => 0.6,
'unit' => 'kg',
),
),
),
);
$sender = array (
'contact_name' => 'your name',
'company_name' => 'name of your company',
'street1' => 'your address',
'street2' => null,
'street3' => null,
'city' => 'your city',
'state' => 'your state',
'postal_code' => 'your postal code',
'country' => 'HKG',
'phone' => '1-403-504-5496',
'fax' => '1-403-504-5497',
'tax_id' => null,
'email' => 'test@test.com',
'type' => 'business'
);
$receiver = array (
'contact_name' => 'Rick McLeod (RM Consulting)',
'street1' => '71 Terrace Crescent NE',
'street2' => 'This is the second streeet',
'city' => 'Medicine Hat',
'state' => 'Alberta',
'postal_code' => 'T1C1Z9',
'country' => 'CAN',
'phone' => '1-403-504-5496',
'email' => 'test@test.test',
'type' => 'residential'
);
$payload = array (
'is_document' => false,
'return_shipment' => false,
'paper_size' => 'default',
'service_type' => 'hong-kong-post_air_parcel',
'customs' => array (
'billing' => array (
'paid_by' => 'shipper',
'method' => array (
'account_number' => '950000002',
'type' => 'account',
),
),
'purpose' => 'gift'
),
'shipper_account' =>
array (
'id' => $shipper,
),
'shipment' => array (
'parcels' => array (
0 => $parcel
),
'ship_from' => $sender,
'ship_to' => $receiver
),
);
try {
$api = new Postmen($key, $region);
$result = $api->create('labels', $payload);
echo "RESULT:\n";
print_r($result);
} catch (exception $e) {
echo "ERROR:\n";
echo $e->getCode() . "\n"; // error code
echo $e->getMessage() . "\n"; // error message
print_r($e->getDetails()); // error details
}
?>