@@ -45,4 +45,202 @@ echo '</pre>';
45
45
die();
46
46
47
47
```
48
+ Create Shipment | Shipping Label
49
+ ``` php
50
+ <?php
51
+
52
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Address;
53
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\BillShipper;
54
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Dimensions;
55
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\LabelImageFormat;
56
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\LabelSpecification;
57
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\LabelStockSize;
58
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Package;
59
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\PackageWeight;
60
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Packaging;
61
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\PaymentInformation;
62
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Phone;
63
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Request;
64
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Service;
65
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipFrom;
66
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Shipment;
67
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipmentCharge;
68
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipmentRequest;
69
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\Shipper;
70
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipTo;
71
+ use RahulGodiyal\PhpUpsApiWrapper\Entity\UnitOfMeasurement;
72
+ use RahulGodiyal\PhpUpsApiWrapper\Ship;
73
+
74
+ require_once('./vendor/autoload.php');
75
+
76
+ $client_id = "************************"; // UPS Client ID
77
+ $client_secret = "*****************************"; // UPS Client Secret
78
+
79
+ /********* Shipper **********/
80
+ $address = new Address();
81
+ $address->setAddressLine1("address line 1");
82
+ $address->setAddressLine2(""); // optional
83
+ $address->setCity("Timonium");
84
+ $address->setStateProvinceCode("MD");
85
+ $address->setPostalCode("21093");
86
+ $address->setCountryCode("US");
87
+
88
+ $phone = new Phone();
89
+ $phone->setNumber("1115554758");
90
+ $phone->setExtension(""); // optional
91
+
92
+ $shipper = new Shipper();
93
+ $shipper->setName("Shipper Test");
94
+ $shipper->setAttentionName(""); // optional
95
+ $shipper->setTaxIdentificationNumber(""); // optional
96
+ $shipper->setPhone($phone);
97
+ $shipper->setShippingNumber("123456");
98
+ $shipper->setFaxNumber(""); // optional
99
+ $shipper->setAddress($address);
100
+ /********* End Shipper **********/
101
+
102
+ /************ ShipTo **********/
103
+ $address = new Address();
104
+ $address->setAddressLine1("address line 1");
105
+ $address->setAddressLine2(""); // optional
106
+ $address->setCity("Timonium");
107
+ $address->setStateProvinceCode("MD");
108
+ $address->setPostalCode("21093");
109
+ $address->setCountryCode("US");
110
+
111
+ $phone = new Phone();
112
+ $phone->setNumber("1115554758");
113
+
114
+ $shipTo = new ShipTo();
115
+ $shipTo->setName("Shipper Test");
116
+ $shipTo->setAttentionName(""); // optional
117
+ $shipTo->setPhone($phone);
118
+ $shipTo->setAddress($address);
119
+ $shipTo->setResidential(""); // optional
120
+ /************ End ShipTo **********/
121
+
122
+ /************ ShipFrom **********/
123
+ $address = new Address();
124
+ $address->setAddressLine1("address line 1");
125
+ $address->setAddressLine2(""); // optional
126
+ $address->setCity("Timonium");
127
+ $address->setStateProvinceCode("MD");
128
+ $address->setPostalCode("21093");
129
+ $address->setCountryCode("US");
130
+
131
+ $phone = new Phone();
132
+ $phone->setNumber("1115554758");
133
+
134
+ $shipFrom = new ShipFrom();
135
+ $shipFrom->setName("Shipper Test");
136
+ $shipFrom->setAttentionName(""); // optional
137
+ $shipFrom->setPhone($phone);
138
+ $shipFrom->setFaxNumber(""); // optional
139
+ $shipFrom->setAddress($address);
140
+ /************ End ShipFrom **********/
141
+
142
+ /************ PaymentInformation **********/
143
+ $billShipper = new BillShipper();
144
+ $billShipper->setAccountNumber("123456");
145
+
146
+ $shipmentCharge = new ShipmentCharge();
147
+ $shipmentCharge->setBillShipper($billShipper);
148
+
149
+ $paymentInformation = new PaymentInformation();
150
+ $paymentInformation->setShipmentCharge($shipmentCharge);
151
+ /************ End PaymentInformation **********/
152
+
153
+ /************ Service **********/
154
+ $service = new Service();
155
+ $service->setCode(Service::GROUND);
156
+ $service->setDescription("Ground"); // optional
157
+ /************ End Service **********/
158
+
159
+ /************ Package **********/
160
+ $packaging = new Packaging();
161
+ $packaging->setCode(Packaging::CUSTOMER_SUPPLIED_PACKAGE);
162
+ $packaging->setDescription("Ups Letter"); // optional
163
+
164
+ $unitOfMeasurement = new UnitOfMeasurement();
165
+ $unitOfMeasurement->setCode(UnitOfMeasurement::INCHES);
166
+ $unitOfMeasurement->setDescription("Inches"); // optional
167
+
168
+ $dimensions = new Dimensions();
169
+ $dimensions->setUnitOfMeasurement($unitOfMeasurement);
170
+ $dimensions->setLength("10");
171
+ $dimensions->setWidth("30");
172
+ $dimensions->setHeight("45");
173
+
174
+ $unitOfMeasurement = new UnitOfMeasurement();
175
+ $unitOfMeasurement->setCode(UnitOfMeasurement::POUNDS);
176
+ $unitOfMeasurement->setDescription("POUNDS"); // optional
177
+
178
+ $packageWeight = new PackageWeight();
179
+ $packageWeight->setUnitOfMeasurement($unitOfMeasurement);
180
+ $packageWeight->setWeight("5");
181
+
182
+ $package = new Package();
183
+ $package->setDescription(""); // optional
184
+ $package->setPackaging($packaging);
185
+ $package->setDimensions($dimensions);
186
+ $package->setPackageWeight($packageWeight);
187
+ /************ End Package **********/
188
+
189
+ /************ Shipment **********/
190
+ $shipment = new Shipment();
191
+ $shipment->setDescription("Ship WS test");
192
+ $shipment->setShipper($shipper);
193
+ $shipment->setShipTo($shipTo);
194
+ $shipment->setShipFrom($shipFrom);
195
+ $shipment->setPaymentInformation($paymentInformation);
196
+ $shipment->setService($service);
197
+ $shipment->setPackage($package);
198
+ /************ End Shipment **********/
199
+
200
+ /************ Label Specification **********/
201
+ $labelImageFormat = new LabelImageFormat();
202
+ $labelImageFormat->setCode(LabelImageFormat::GIF);
203
+ $labelImageFormat->setDescription("GIF"); // optional
204
+
205
+ $labelStockSize = new LabelStockSize();
206
+ $labelStockSize->setHeight(LabelStockSize::H_8);
207
+ $labelStockSize->setWidth(LabelStockSize::W_4);
208
+
209
+ $labelSpecification = new LabelSpecification();
210
+ $labelSpecification->setLabelImageFormat($labelImageFormat);
211
+ $labelSpecification->setLabelStockSize($labelStockSize);
212
+ $labelSpecification->setHttpUserAgent("Mozilla/4.5"); // optional
213
+ /************ End Label Specification **********/
214
+
215
+ /************ Shipment Request **********/
216
+ $shipmentRequest = new ShipmentRequest();
217
+ $shipmentRequest->setRequest(new Request);
218
+ $shipmentRequest->setShipment($shipment);
219
+ $shipmentRequest->setLabelSpecification($labelSpecification);
220
+ /************ End Shipment Request **********/
221
+
222
+ /************ Create Ship **********/
223
+ $ship = new Ship();
224
+ $ship->setShipmentRequest($shipmentRequest);
225
+ $ship->setOnlyLabel(true); // optional
226
+ // $ship->setMode('PROD'); // Optional | only used for prod
227
+ $shipRes = $ship->createShipment($client_id, $client_secret);
228
+ /************ End Create Ship **********/
229
+
230
+ echo '<pre >'; print_r($shipRes); echo '</pre >';
231
+ ?>
232
+ <!DOCTYPE html>
233
+ <html lang =" en" >
234
+ <head >
235
+ <meta charset =" UTF-8" >
236
+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" >
237
+ <title >Shipping Label</title >
238
+ </head >
239
+ <body >
240
+ <img src =" data:image/png;base64,<?= $shipRes['data']->GraphicImage ?>" alt =" Shipping Label" >
241
+
242
+ </body >
243
+ </html >
244
+
245
+ ```
48
246
0 commit comments