@@ -7,6 +7,16 @@ import (
77
88type LabelData []byte
99
10+ type CustomsShipmentType int
11+
12+ const (
13+ CustomsShipmentTypeGift = iota
14+ CustomsShipmentTypeDocuments
15+ CustomsShipmentTypeCommercialGoods
16+ CustomsShipmentTypeCommercialSample
17+ CustomsShipmentTypeReturnedGoods
18+ )
19+
1020type ParcelParams struct {
1121 Name string
1222 CompanyName string
@@ -26,6 +36,47 @@ type ParcelParams struct {
2636 Weight string
2737 OrderNumber string
2838 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"`
2980}
3081
3182type Parcel struct {
@@ -60,26 +111,31 @@ type ParcelRequestContainer struct {
60111}
61112
62113type 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"`
83139}
84140
85141type LabelResponseContainer struct {
@@ -156,27 +212,33 @@ type Status struct {
156212 Message string `json:"message"`
157213}
158214
159- //Translate the params into an actual request body
215+ // Translate the params into an actual request body
160216func (p * ParcelParams ) GetPayload () interface {} {
161217 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 ,
179237 }
238+ if p .Method != 0 {
239+ parcel .Shipment = & CreateParcelShipmentRequest {ID : p .Method }
240+ }
241+
180242 if p .SenderID != 0 {
181243 parcel .SenderID = & p .SenderID
182244 }
@@ -197,7 +259,7 @@ func (p *ParcelParams) GetPayload() interface{} {
197259 return ar
198260}
199261
200- //Handle the response and return it as a Parcel{}
262+ // Handle the response and return it as a Parcel{}
201263func (p * ParcelResponseContainer ) GetResponse () interface {} {
202264 parcel := Parcel {
203265 ID : p .Parcel .ID ,
@@ -232,7 +294,7 @@ func (p *ParcelResponseContainer) GetResponse() interface{} {
232294 return & parcel
233295}
234296
235- //Set the response
297+ // Set the response
236298func (p * ParcelResponseContainer ) SetResponse (body []byte ) error {
237299 err := json .Unmarshal (body , & p )
238300 if err != nil {
@@ -241,12 +303,12 @@ func (p *ParcelResponseContainer) SetResponse(body []byte) error {
241303 return nil
242304}
243305
244- //Get formatted response
306+ // Get formatted response
245307func (l LabelData ) GetResponse () interface {} {
246308 return l
247309}
248310
249- //Set the response
311+ // Set the response
250312func (l * LabelData ) SetResponse (body []byte ) error {
251313 * l = body
252314 return nil
0 commit comments