-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshipment_response.go
182 lines (158 loc) · 4.7 KB
/
shipment_response.go
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
package ups
import (
"encoding/json"
)
type ShipmentResponse struct {
// Response container for Shipment response.
Response Response
// Shipment Results container.
ShipmentResults ShipmentResults
}
type Response struct {
// Response status container.
ResponseStatus ResponseStatus
// Alert Container. There can be zero to many alert containers with
// code and description.
Alerts []Alert `json:"Alert"`
// Transaction Reference Container.
// TransactionReference *TransactionReference // buggy
}
func (s *Response) UnmarshalJSON(data []byte) error {
var v map[string]json.RawMessage
if err := json.Unmarshal(data, &v); err != nil {
return err
}
if status, ok := v["ResponseStatus"]; ok {
err := json.Unmarshal(status, &s.ResponseStatus)
if err != nil {
return err
}
}
if alert, ok := v["Alert"]; ok {
if alert[0] == '{' {
s.Alerts = make([]Alert, 1)
err := json.Unmarshal(alert, &s.Alerts[0])
if err != nil {
return err
}
} else {
err := json.Unmarshal(alert, &s.Alerts)
if err != nil {
return err
}
}
}
return nil
}
type ResponseStatus struct {
// Identifies the success or failure of the transaction. 1 = Successful
Code string
// Describes Response Status Code. Returns text of Success.
Description string
}
type Alert struct {
// Warning code returned by the system.
Code string
// Warning messages returned by the system.
Description string
}
type TransactionReference struct {
// The CustomerContext Information which will be echoed during
// response.
CustomerContext string
}
type ShipmentResults struct {
// Returned UPS shipment ID number.1Z Number of the first package
// in the shipment.
ShipmentIdentificationNumber string
// Returned Package Information.
// Applicable only for ShipmentResponse and ShipAcceptResponse.
PackageResults []PackageResults
}
func (s *ShipmentResults) UnmarshalJSON(data []byte) error {
var v map[string]json.RawMessage
if err := json.Unmarshal(data, &v); err != nil {
return err
}
if number, ok := v["ShipmentIdentificationNumber"]; ok {
err := json.Unmarshal(number, &s.ShipmentIdentificationNumber)
if err != nil {
return err
}
}
if packageResults, ok := v["PackageResults"]; ok {
if packageResults[0] == '{' {
s.PackageResults = make([]PackageResults, 1)
err := json.Unmarshal(packageResults, &s.PackageResults[0])
if err != nil {
return err
}
} else {
err := json.Unmarshal(packageResults, &s.PackageResults)
if err != nil {
return err
}
}
}
return nil
}
type PackageResults struct {
// Package 1Z number. For Mail Innovations shipments, please use
// the USPSPICNumber when tracking packages (a non-1Z number
// Mail Manifest Id is returned).
// Applicable only for ShipmentResponse and ShipAcceptResponse.
TrackingNumber string
// The container for UPS shipping label. Returned for following
// shipments - Forward shipments, Shipments with PRL returns
// service, Electronic Return Label or Electronic Import Control Label
// shipments with SubVersion greater than or equal to 1707.
// Applicable only for ShipmentResponse and ShipAcceptResponse.
ShippingLabel *ShippingLabel
}
type ShippingLabel struct {
// The container image format.
// Applicable only for ShipmentResponse and ShipAcceptResponse.
ImageFormat ImageFormat
// Base 64 encoded graphic image.
// Applicable only for ShipmentResponse and ShipAcceptResponse.
GraphicImage string
// Base 64 encoded graphic image.
// Applicable only for ShipmentResponse and ShipAcceptResponse
// for Mail Innovations CN22 Combination Forward Label with more
// than 3 commodities.
GraphicImagePart string
}
type ImageFormat struct {
// Label image code that the labels are generated. Valid values: EPL
// = EPL2 SPL = SPL ZPL = ZPL GIF = gif images PNG = PNG
// images. Only EPL, SPL, ZPL and GIF are currently supported.
// For multi piece COD shipments, the label image format for the first
// package will always be a GIF for any form of label requested.
// Applicable only for ShipmentResponse and ShipAcceptResponse.
Code string
// Description of the label image format code.
// Applicable only for ShipmentResponse and ShipAcceptResponse.
Description string
}
type VoidShipmentResponse struct {
// Response Container.
Response Response
// Container for the Summary Result.
SummaryResult SummaryResult
}
type SummaryResult struct {
// Container for the status of the Summary Result
Status Status
}
type Status struct {
// Code for the status of the Summary Result
Code string
// Description of the status of the Summary Result
Description string
}
type PackageLevelResult struct {
// Container for the status of the Summary Result
Status Status
// The package's identification number
TrackingNumber string
}