-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
198 lines (149 loc) · 7.18 KB
/
index.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
const despatchjs = require('./despatchjs')
const addShipment = async () => {
const data = {
// SenderAddressID: '000000', // Sender Address not required as defaults to ENV
orderID: '12345',
serviceID: '9992',
collectionDate: '2021-01-18',
followShipment: false, // Follow the shipment on the Despatch Bay dashboard (optional),
IOSSNumber : '1234567' // 12 digit IOSS number (optional)
}
// An Array of parcels
// International: When sending outside the UK (Including the all EU destinations, Channel Islands, Republic of Ireland and Northern Ireland) all fields of ParcelContentType become mandatory.
data.parcels = [
{
currency: 'GBP',
pWeight:1.0, // Float. The weight of the parcel in kg
pLength: 20, // Float. The length of the parcel in cm (longest dimension)
pWidth: 20, // Float. The width of the parcel in cm (second longest dimension)
pHeight: 20, // Float. The height of the parcel in cm (shortest dimension)
exportReason: 'SOLD', // String. Only needed for Export. Please see https://github.com/despatchbay/despatchbay-api-v16/wiki/Shipping-Service#export-reasons
contents: [
{
description: 'This is my description', // String. Description of the item
unitQuantity: 1, // Int. The quantity of this item within the parcel
unitWeight: 0.5, // Float. The weight of one unit of the item (in kg)
unitValue: 12, // Float. The value of one unit of the item (In the currency specified in the parent ParcelType
tariffCode: 1234567890, // String. Only needed for Export. The HS Tariff Code / Commodity code of the item
originCountryCode: 'GB' // String. The country of origin of the item (ISO 3166-1 alpha-2 code)
}
]
}
]
data.recipientAddress = {
recipientName: 'Joanna Dark', // String. The name of the recipient
recipientTelephone: '07555555555', // String. The telphone number of the recipient (optional)
recipientEmail: '', // String. The email address of the recipient (optional)
companyName: '', // String. Company/Organisation name (optional)
street: 'Buckingham Palace', // String. First line of street address
locality: '', // String. Second line of street address (optional)
townCity: 'London', // String. Town or city name
county: 'London', // String. County
postalCode: 'SW1A1AA', // String. Postal code (optional for countries without postcodes)
countryCode: 'GB', // String. ISO 3166-1 alpha-2 code
}
return await despatchjs.addShipment(data)
}
const bookShipment = async () => {
const data = {
shipmentID: '134876-1691', // will also take an array of IDs
}
return await despatchjs.bookShipments(data)
}
const cancelShipment = async () => {
const data = {
shipmentID: '134876-1691'
}
return await despatchjs.cancelShipment(data)
}
const getAvailableCollectionDates = async () => {
const data = {
// SenderAddressID: '000000', // Sender Address not required as we only have one location - 288918
courierID: '99',
}
return await despatchjs.getAvailableCollectionDates(data)
}
const getAvailableServices = async () => {
const data = {
// SenderAddressID: '000000', // Sender Address not required as defaults to ENV
}
// An Array of parcels
// International: When sending outside the UK (Including the all EU destinations, Channel Islands, Republic of Ireland and Northern Ireland) all fields of ParcelContentType become mandatory.
data.parcels = [
{
currency: 'GBP',
pWeight:1.0, // Float. The weight of the parcel in kg
pLength: 20, // Float. The length of the parcel in cm (longest dimension)
pWidth: 20, // Float. The width of the parcel in cm (second longest dimension)
pHeight: 20, // Float. The height of the parcel in cm (shortest dimension)
exportReason: 'SOLD', // String. Please see https://github.com/despatchbay/despatchbay-api-v16/wiki/Shipping-Service#export-reasons
contents: [
{
description: 'This is my description', // String. Description of the item
unitQuantity: 1, // Int. The quantity of this item within the parcel
unitWeight: 0.5, // Float. The weight of one unit of the item (in kg)
unitValue: 12, // Float. The value of one unit of the item (In the currency specified in the parent ParcelType
tariffCode: 1234567890, // String. Only needed for Export. The HS Tariff Code / Commodity code of the item
originCountryCode: 'GB' // String. The country of origin of the item (ISO 3166-1 alpha-2 code)
}
]
}
]
data.recipientAddress = {
recipientName: 'Joanna Dark', // String. The name of the recipient
recipientTelephone: '07555555555', // String. The telphone number of the recipient (optional)
recipientEmail: '', // String. The email address of the recipient (optional)
companyName: '', // String. Company/Organisation name (optional)
street: 'Buckingham Palace', // String. First line of street address
locality: '', // String. Second line of street address (optional)
townCity: 'London', // String. Town or city name
county: 'London', // String. County
postalCode: 'SW1A1AA', // String. Postal code (optional for countries without postcodes)
countryCode: 'GB', // String. ISO 3166-1 alpha-2 code
}
return await despatchjs.getAvailableServices(data)
}
const getCollection = async () => {
const data = {
collectionID: 'DE-301',
}
return await despatchjs.getCollection(data)
}
const getShipment = async () => {
const data = {
shipmentID: '134876-1691'
}
return await despatchjs.getShipment(data)
}
const getCustomsDocument = async () => {
const data = {
shipmentDocumentID: "ds2ahSjXwCdX8U"
}
return await despatchjs.getCustomsDocument(data)
}
/* Run the methods */
const testing = async () => {
console.log("Test: Each SOAP Method's response as JSON. Please see data object in each test method to what is needed.")
console.log('1. get available services')
const AvailableServices = await getAvailableServices()
console.log(JSON.stringify(AvailableServices, null, 2))
console.log('2. get available collection dates')
const AvailableCollectionDates = await getAvailableCollectionDates()
console.log(JSON.stringify(AvailableCollectionDates, null, 2))
console.log('3. add shipping')
const AddShipment = await addShipment()
console.log(JSON.stringify(AddShipment, null, 2))
console.log('4. book shipping')
const BookShipment = await bookShipment()
console.log(JSON.stringify(BookShipment, null, 2))
console.log('5. cancel shipping')
const CancelShipment = await cancelShipment()
console.log(JSON.stringify(CancelShipment, null, 2))
console.log('6. get collection')
const GetCollection = await getCollection()
console.log(JSON.stringify(GetCollection, null, 2))
console.log('7. get shipment')
const GetShipment = await getShipment()
console.log(JSON.stringify(GetShipment, null, 2))
}
testing()