1+ <?php
2+
3+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Address ;
4+ use RahulGodiyal \PhpUpsApiWrapper \Entity \BillShipper ;
5+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Dimensions ;
6+ use RahulGodiyal \PhpUpsApiWrapper \Entity \LabelImageFormat ;
7+ use RahulGodiyal \PhpUpsApiWrapper \Entity \LabelSpecification ;
8+ use RahulGodiyal \PhpUpsApiWrapper \Entity \LabelStockSize ;
9+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Package ;
10+ use RahulGodiyal \PhpUpsApiWrapper \Entity \PackageWeight ;
11+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Packaging ;
12+ use RahulGodiyal \PhpUpsApiWrapper \Entity \PaymentInformation ;
13+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Phone ;
14+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Request ;
15+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Service ;
16+ use RahulGodiyal \PhpUpsApiWrapper \Entity \ShipFrom ;
17+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Shipment ;
18+ use RahulGodiyal \PhpUpsApiWrapper \Entity \ShipmentCharge ;
19+ use RahulGodiyal \PhpUpsApiWrapper \Entity \ShipmentRequest ;
20+ use RahulGodiyal \PhpUpsApiWrapper \Entity \Shipper ;
21+ use RahulGodiyal \PhpUpsApiWrapper \Entity \ShipTo ;
22+ use RahulGodiyal \PhpUpsApiWrapper \Entity \UnitOfMeasurement ;
23+ use RahulGodiyal \PhpUpsApiWrapper \Ship ;
24+
25+ require_once ('./vendor/autoload.php ' );
26+
27+ $ client_id = "************************ " ; // UPS Client ID
28+ $ client_secret = "***************************** " ; // UPS Client Secret
29+
30+ /********* Shipper **********/
31+ $ address = new Address ();
32+ $ address ->setAddressLine1 ("address line 1 " );
33+ $ address ->setAddressLine2 ("" ); // optional
34+ $ address ->setCity ("Timonium " );
35+ $ address ->setStateProvinceCode ("MD " );
36+ $ address ->setPostalCode ("21093 " );
37+ $ address ->setCountryCode ("US " );
38+
39+ $ phone = new Phone ();
40+ $ phone ->setNumber ("1115554758 " );
41+ $ phone ->setExtension ("" ); // optional
42+
43+ $ shipper = new Shipper ();
44+ $ shipper ->setName ("Shipper Test " );
45+ $ shipper ->setAttentionName ("" ); // optional
46+ $ shipper ->setTaxIdentificationNumber ("" ); // optional
47+ $ shipper ->setPhone ($ phone );
48+ $ shipper ->setShippingNumber ("123456 " );
49+ $ shipper ->setFaxNumber ("" ); // optional
50+ $ shipper ->setAddress ($ address );
51+ /********* End Shipper **********/
52+
53+ /************ ShipTo **********/
54+ $ address = new Address ();
55+ $ address ->setAddressLine1 ("address line 1 " );
56+ $ address ->setAddressLine2 ("" ); // optional
57+ $ address ->setCity ("Timonium " );
58+ $ address ->setStateProvinceCode ("MD " );
59+ $ address ->setPostalCode ("21093 " );
60+ $ address ->setCountryCode ("US " );
61+
62+ $ phone = new Phone ();
63+ $ phone ->setNumber ("1115554758 " );
64+
65+ $ shipTo = new ShipTo ();
66+ $ shipTo ->setName ("Shipper Test " );
67+ $ shipTo ->setAttentionName ("" ); // optional
68+ $ shipTo ->setPhone ($ phone );
69+ $ shipTo ->setAddress ($ address );
70+ $ shipTo ->setResidential ("" ); // optional
71+ /************ End ShipTo **********/
72+
73+ /************ ShipFrom **********/
74+ $ address = new Address ();
75+ $ address ->setAddressLine1 ("address line 1 " );
76+ $ address ->setAddressLine2 ("" ); // optional
77+ $ address ->setCity ("Timonium " );
78+ $ address ->setStateProvinceCode ("MD " );
79+ $ address ->setPostalCode ("21093 " );
80+ $ address ->setCountryCode ("US " );
81+
82+ $ phone = new Phone ();
83+ $ phone ->setNumber ("1115554758 " );
84+
85+ $ shipFrom = new ShipFrom ();
86+ $ shipFrom ->setName ("Shipper Test " );
87+ $ shipFrom ->setAttentionName ("" ); // optional
88+ $ shipFrom ->setPhone ($ phone );
89+ $ shipFrom ->setFaxNumber ("" ); // optional
90+ $ shipFrom ->setAddress ($ address );
91+ /************ End ShipFrom **********/
92+
93+ /************ PaymentInformation **********/
94+ $ billShipper = new BillShipper ();
95+ $ billShipper ->setAccountNumber ("123456 " );
96+
97+ $ shipmentCharge = new ShipmentCharge ();
98+ $ shipmentCharge ->setBillShipper ($ billShipper );
99+
100+ $ paymentInformation = new PaymentInformation ();
101+ $ paymentInformation ->setShipmentCharge ($ shipmentCharge );
102+ /************ End PaymentInformation **********/
103+
104+ /************ Service **********/
105+ $ service = new Service ();
106+ $ service ->setCode (Service::GROUND );
107+ $ service ->setDescription ("Ground " ); // optional
108+ /************ End Service **********/
109+
110+ /************ Package **********/
111+ $ packaging = new Packaging ();
112+ $ packaging ->setCode (Packaging::CUSTOMER_SUPPLIED_PACKAGE );
113+ $ packaging ->setDescription ("Ups Letter " ); // optional
114+
115+ $ unitOfMeasurement = new UnitOfMeasurement ();
116+ $ unitOfMeasurement ->setCode (UnitOfMeasurement::INCHES );
117+ $ unitOfMeasurement ->setDescription ("Inches " ); // optional
118+
119+ $ dimensions = new Dimensions ();
120+ $ dimensions ->setUnitOfMeasurement ($ unitOfMeasurement );
121+ $ dimensions ->setLength ("10 " );
122+ $ dimensions ->setWidth ("30 " );
123+ $ dimensions ->setHeight ("45 " );
124+
125+ $ unitOfMeasurement = new UnitOfMeasurement ();
126+ $ unitOfMeasurement ->setCode (UnitOfMeasurement::POUNDS );
127+ $ unitOfMeasurement ->setDescription ("POUNDS " ); // optional
128+
129+ $ packageWeight = new PackageWeight ();
130+ $ packageWeight ->setUnitOfMeasurement ($ unitOfMeasurement );
131+ $ packageWeight ->setWeight ("5 " );
132+
133+ $ package = new Package ();
134+ $ package ->setDescription ("" ); // optional
135+ $ package ->setPackaging ($ packaging );
136+ $ package ->setDimensions ($ dimensions );
137+ $ package ->setPackageWeight ($ packageWeight );
138+ /************ End Package **********/
139+
140+ /************ Shipment **********/
141+ $ shipment = new Shipment ();
142+ $ shipment ->setDescription ("Ship WS test " );
143+ $ shipment ->setShipper ($ shipper );
144+ $ shipment ->setShipTo ($ shipTo );
145+ $ shipment ->setShipFrom ($ shipFrom );
146+ $ shipment ->setPaymentInformation ($ paymentInformation );
147+ $ shipment ->setService ($ service );
148+ $ shipment ->setPackage ($ package );
149+ /************ End Shipment **********/
150+
151+ /************ Label Specification **********/
152+ $ labelImageFormat = new LabelImageFormat ();
153+ $ labelImageFormat ->setCode (LabelImageFormat::GIF );
154+ $ labelImageFormat ->setDescription ("GIF " ); // optional
155+
156+ $ labelStockSize = new LabelStockSize ();
157+ $ labelStockSize ->setHeight (LabelStockSize::H_8 );
158+ $ labelStockSize ->setWidth (LabelStockSize::W_4 );
159+
160+ $ labelSpecification = new LabelSpecification ();
161+ $ labelSpecification ->setLabelImageFormat ($ labelImageFormat );
162+ $ labelSpecification ->setLabelStockSize ($ labelStockSize );
163+ $ labelSpecification ->setHttpUserAgent ("Mozilla/4.5 " ); // optional
164+ /************ End Label Specification **********/
165+
166+ /************ Shipment Request **********/
167+ $ shipmentRequest = new ShipmentRequest ();
168+ $ shipmentRequest ->setRequest (new Request );
169+ $ shipmentRequest ->setShipment ($ shipment );
170+ $ shipmentRequest ->setLabelSpecification ($ labelSpecification );
171+ /************ End Shipment Request **********/
172+
173+ /************ Create Ship **********/
174+ $ ship = new Ship ();
175+ $ ship ->setShipmentRequest ($ shipmentRequest );
176+ $ ship ->setOnlyLabel (true ); // optional
177+ // $ship->setMode('PROD'); // Optional | only used for prod
178+ $ shipRes = $ ship ->createShipment ($ client_id , $ client_secret );
179+ /************ End Create Ship **********/
180+
181+ echo '<pre> ' ; print_r ($ shipRes ); echo '</pre> ' ;
182+ ?>
183+ <!DOCTYPE html>
184+ <html lang="en">
185+ <head>
186+ <meta charset="UTF-8">
187+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
188+ <title>Shipping Label</title>
189+ </head>
190+ <body>
191+ <img src="data:image/png;base64,<?= $ shipRes ['data ' ]->GraphicImage ?> " alt="Shipping Label">
192+
193+ </body>
194+ </html>
0 commit comments