@@ -7,6 +7,16 @@ import (
7
7
8
8
type LabelData []byte
9
9
10
+ type CustomsShipmentType int
11
+
12
+ const (
13
+ CustomsShipmentTypeGift = iota
14
+ CustomsShipmentTypeDocuments
15
+ CustomsShipmentTypeCommercialGoods
16
+ CustomsShipmentTypeCommercialSample
17
+ CustomsShipmentTypeReturnedGoods
18
+ )
19
+
10
20
type ParcelParams struct {
11
21
Name string
12
22
CompanyName string
@@ -26,6 +36,47 @@ type ParcelParams struct {
26
36
Weight string
27
37
OrderNumber string
28
38
SenderID int64
39
+ Items []CreateParcelItemRequest
40
+ // The currency of the total order value. Validated against a format of
41
+ // “XYZ” (ISO 4217).
42
+ TotalOrderValueCurrency * string
43
+ // The value paid by the buyer (via various payment methods supported by the
44
+ // shop(cash on delivery, pre-paid or post-paid), it will also be used for
45
+ // the cash on delivery amount for example “99.99”.
46
+ TotalOrderValue * string
47
+ // Shipping method name selected by buyer during the checkout
48
+ ShippingMethodCheckoutName * string
49
+ // Customs invoice number
50
+ CustomsInvoiceNr * string
51
+ // Customs shipment type
52
+ CustomsShipmentType * CustomsShipmentType
53
+ // When set to true configured shipping rules will be applied before creating the label and announcing the Parcel
54
+ ApplyShippingRules * bool
55
+ }
56
+
57
+ type CreateParcelItemRequest struct {
58
+ // Harmonized System Code Wikipedia Link. Providing a complete HS code with 8 characters increases the delivery rate.
59
+ HsCode string `json:"hs_code"`
60
+ // Weight of a single item in kilograms.
61
+ Weight string `json:"weight"`
62
+ // Quantity of items shipped.
63
+ Quantity int `json:"quantity"`
64
+ // Description of the item.
65
+ Description string `json:"description"`
66
+ // ISO-2 code of the country where the items were originally produced. External Link.
67
+ OriginCountry string `json:"origin_country,omitempty"`
68
+ // Value of a single item.
69
+ Value float64 `json:"value"`
70
+ // The SKU of the product.
71
+ SKU string `json:"sku,omitempty"`
72
+ // External ID of the item generated by a shop system or similar.
73
+ ItemId string `json:"item_id,omitempty"`
74
+ // The list of properties of the product. Used as a JSON object with {‘key’: ‘value’}.
75
+ Properties map [string ]interface {} `json:"properties,omitempty"`
76
+ }
77
+
78
+ type CreateParcelShipmentRequest struct {
79
+ ID int64 `json:"id"`
29
80
}
30
81
31
82
type Parcel struct {
@@ -60,26 +111,31 @@ type ParcelRequestContainer struct {
60
111
}
61
112
62
113
type ParcelRequest struct {
63
- Name string `json:"name"`
64
- CompanyName string `json:"company_name"`
65
- Address string `json:"address"`
66
- Address2 string `json:"address_2"`
67
- HouseNumber string `json:"house_number"`
68
- City string `json:"city"`
69
- PostalCode string `json:"postal_code"`
70
- CountryState string `json:"country_state"`
71
- Country string `json:"country"`
72
- Weight string `json:"weight,omitempty"`
73
- Telephone string `json:"telephone"`
74
- Email string `json:"email"`
75
- RequestLabel bool `json:"request_label"`
76
- ToServicePointID * int64 `json:"to_service_point,omitempty"`
77
- OrderNumber string `json:"order_number"`
78
- ExternalID * string `json:"external_reference,omitempty"`
79
- SenderID * int64 `json:"sender_address,omitempty"`
80
- Shipment struct {
81
- ID int64 `json:"id"`
82
- } `json:"shipment"`
114
+ Name string `json:"name"`
115
+ CompanyName string `json:"company_name"`
116
+ Address string `json:"address"`
117
+ Address2 string `json:"address_2"`
118
+ HouseNumber string `json:"house_number"`
119
+ City string `json:"city"`
120
+ PostalCode string `json:"postal_code"`
121
+ CountryState string `json:"country_state"`
122
+ Country string `json:"country"`
123
+ Weight string `json:"weight,omitempty"`
124
+ Telephone string `json:"telephone"`
125
+ Email string `json:"email"`
126
+ RequestLabel bool `json:"request_label"`
127
+ ToServicePointID * int64 `json:"to_service_point,omitempty"`
128
+ OrderNumber string `json:"order_number"`
129
+ ExternalID * string `json:"external_reference,omitempty"`
130
+ SenderID * int64 `json:"sender_address,omitempty"`
131
+ Shipment * CreateParcelShipmentRequest `json:"shipment,omitempty"`
132
+ Items []CreateParcelItemRequest `json:"parcel_items,omitempty"`
133
+ TotalOrderValueCurrency * string `json:"total_order_value_currency,omitempty"`
134
+ TotalOrderValue * string `json:"total_order_value,omitempty"`
135
+ ShippingMethodCheckoutName * string `json:"shipping_method_checkout_name,omitempty"`
136
+ CustomsInvoiceNr * string `json:"customs_invoice_nr,omitempty"`
137
+ CustomsShipmentType * CustomsShipmentType `json:"customs_shipment_type,omitempty"`
138
+ ApplyShippingRules * bool `json:"apply_shipping_rules,omitempty"`
83
139
}
84
140
85
141
type LabelResponseContainer struct {
@@ -156,27 +212,33 @@ type Status struct {
156
212
Message string `json:"message"`
157
213
}
158
214
159
- //Translate the params into an actual request body
215
+ // Translate the params into an actual request body
160
216
func (p * ParcelParams ) GetPayload () interface {} {
161
217
parcel := ParcelRequest {
162
- Name : p .Name ,
163
- CompanyName : p .CompanyName ,
164
- Address : p .Street ,
165
- Address2 : p .AdditionalInfo ,
166
- HouseNumber : p .HouseNumber ,
167
- City : p .City ,
168
- PostalCode : p .PostalCode ,
169
- CountryState : p .State ,
170
- Country : p .CountryCode ,
171
- Telephone : p .PhoneNumber ,
172
- Email : p .EmailAddress ,
173
- RequestLabel : p .IsLabelRequested ,
174
- Shipment : struct {
175
- ID int64 `json:"id"`
176
- }{
177
- ID : p .Method ,
178
- },
218
+ Name : p .Name ,
219
+ CompanyName : p .CompanyName ,
220
+ Address : p .Street ,
221
+ Address2 : p .AdditionalInfo ,
222
+ HouseNumber : p .HouseNumber ,
223
+ City : p .City ,
224
+ PostalCode : p .PostalCode ,
225
+ CountryState : p .State ,
226
+ Country : p .CountryCode ,
227
+ Telephone : p .PhoneNumber ,
228
+ Email : p .EmailAddress ,
229
+ RequestLabel : p .IsLabelRequested ,
230
+ Items : p .Items ,
231
+ TotalOrderValueCurrency : p .TotalOrderValueCurrency ,
232
+ TotalOrderValue : p .TotalOrderValue ,
233
+ ShippingMethodCheckoutName : p .ShippingMethodCheckoutName ,
234
+ CustomsInvoiceNr : p .CustomsInvoiceNr ,
235
+ CustomsShipmentType : p .CustomsShipmentType ,
236
+ ApplyShippingRules : p .ApplyShippingRules ,
179
237
}
238
+ if p .Method != 0 {
239
+ parcel .Shipment = & CreateParcelShipmentRequest {ID : p .Method }
240
+ }
241
+
180
242
if p .SenderID != 0 {
181
243
parcel .SenderID = & p .SenderID
182
244
}
@@ -197,7 +259,7 @@ func (p *ParcelParams) GetPayload() interface{} {
197
259
return ar
198
260
}
199
261
200
- //Handle the response and return it as a Parcel{}
262
+ // Handle the response and return it as a Parcel{}
201
263
func (p * ParcelResponseContainer ) GetResponse () interface {} {
202
264
parcel := Parcel {
203
265
ID : p .Parcel .ID ,
@@ -232,7 +294,7 @@ func (p *ParcelResponseContainer) GetResponse() interface{} {
232
294
return & parcel
233
295
}
234
296
235
- //Set the response
297
+ // Set the response
236
298
func (p * ParcelResponseContainer ) SetResponse (body []byte ) error {
237
299
err := json .Unmarshal (body , & p )
238
300
if err != nil {
@@ -241,12 +303,12 @@ func (p *ParcelResponseContainer) SetResponse(body []byte) error {
241
303
return nil
242
304
}
243
305
244
- //Get formatted response
306
+ // Get formatted response
245
307
func (l LabelData ) GetResponse () interface {} {
246
308
return l
247
309
}
248
310
249
- //Set the response
311
+ // Set the response
250
312
func (l * LabelData ) SetResponse (body []byte ) error {
251
313
* l = body
252
314
return nil
0 commit comments