-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrates_create.php
More file actions
91 lines (86 loc) · 1.8 KB
/
rates_create.php
File metadata and controls
91 lines (86 loc) · 1.8 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
<?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 rates_calculate.php\n";
}
$item = array (
'description' => 'PS4',
'origin_country' => 'JPN',
'quantity' => 2,
'price' => array (
'amount' => 50,
'currency' => 'JPY',
),
'weight' => array (
'value' => 0.59999999999999998,
'unit' => 'kg',
),
'sku' => 'PS4-2015',
);
$sender = array (
'contact_name' => 'Yin Ting Wong',
'street1' => 'Flat A, 30/F, Block 17 Laguna Verde',
'city' => 'Hung Hom',
'state' => 'Kowloon',
'country' => 'HKG',
'phone' => '96679797',
'email' => 'test@test.test',
'type' => 'residential',
);
$receiver = array (
'contact_name' => 'Mike Carunchia',
'street1' => '9504 W Smith ST',
'city' => 'Yorktown',
'state' => 'Indiana',
'postal_code' => '47396',
'country' => 'USA',
'phone' => '7657168649',
'email' => 'test@test.test',
'type' => 'residential',
);
$payload = array (
'async' => false,
'shipper_accounts' => array (
0 => array (
'id' => $shipper,
),
),
'shipment' => array (
'parcels' => array (
0 => array (
'box_type' => 'custom',
'weight' => array (
'value' => 0.5,
'unit' => 'kg',
),
'dimension' => array (
'width' => 20,
'height' => 10,
'depth' => 10,
'unit' => 'cm',
),
'items' => array (
0 => $item
),
),
),
'ship_from' => $sender,
'ship_to' => $receiver,
),
'is_document' => false
);
try {
$api = new Postmen($key, $region);
$result = $api->create('rates', $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
}
?>