Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezupsxml.php
Go to the documentation of this file.
1 <?php
3 //
5 /*
6 Modified from UPSTrack Class by Jon Whitcraft <jon_whitcraft@sweetwater.com>
7
8 upsRate class
9
10 It's simple XML ups rate calculation class.
11 I didn't have much time. enjoy.
12
13 Chris Lee (http://www.neox.net)
14 */
16 //
17 //
18
19 /*
20 service code to service name mapping is different according to shipping
21 originting country.
22 This table is only used in service code to name conversion to show user
23 Empty entry means N/A
24 Ex. If shipping origin is Europe, use European Union Origin map.
25 */
26
28
29 /*
30 // From European Union Origin
31 $ups_service = array (
32 '01' => '',
33 '02' => '',
34 '03' => '',
35 '07' => 'UPS Express',
36 '08' => 'UPS Expedited',
37 '11' => 'UPS Standard',
38 '12' => '',
39 '13' => '',
40 '14' => '',
41 '54' => 'UPS Worldwide Express Plus',
42 '59' => '',
43 '64' => 'UPS Express NA1',
44 '65' => 'UPS Express Saver',
45 );
46
47 // From Canada origin
48 $ups_service = array (
49 '01' => 'UPS Express',
50 '02' => 'UPS Expedited',
51 '03' => '',
52 '07' => 'UPS Worldwide Express',
53 '08' => 'UPS Worldwide Expedited',
54 '11' => 'UPS Standard',
55 '12' => 'UPS 3 Day Select',
56 '13' => 'UPS Express Saver',
57 '14' => 'UPS Express Early A.M.',
58 '54' => 'UPS Worldwide Express Plus',
59 '59' => '',
60 '64' => '',
61 '65' => '',
62 );
63 */
64
66 // For other countries , please refer to UPS development docs.
67
68 //US ORIGIN
69 $ups_service = array (
70 '01' => 'UPS Next Day Air',
71 '02' => 'UPS 2nd Day Air',
72 '03' => 'UPS Ground',
73 '07' => 'UPS Worldwide Express',
74 '08' => 'UPS Worldwide Expedited',
75 '11' => 'UPS Standard',
76 '12' => 'UPS 3 Day Select',
77 '13' => 'UPS Next Day Air Saver',
78 '14' => 'UPS Next Day Air Early A.M.',
79 '54' => 'UPS Worldwide Express Plus',
80 '59' => 'UPS 2nd Day Air A.M.',
81 '64' => '',
82 '65' => 'UPS Express Saver',
83 );
84
85
87
88
90 // upsRate
91
92 class upsRate
93 {
94
95 // You need to create userid ... at http://www.ec.ups.com
96 // var $userid = "riderhaus";
97 // var $passwd = "71sims";
98 // var $accesskey = "ABA87436FDCE7AA8";
99
100 var $request; //'rate' for single service or 'shop' for all possible services
101
102 var $userid;
103 var $passwd;
104 var $accesskey;
105 var $upstool;
106 var $service;
107
108 var $pickuptype='01'; // 01 daily pickup
109
110 /* Pickup Type
111 01- Daily Pickup
112 03- Customer Counter
113 06- One Time Pickup
114 07- On Call Air
115 11- Suggested Retail Rates
116 19- Letter Center
117 20- Air Service Center
118 */
119
120 var $residential;
121
122 // ship from location or shipper
123 var $s_zip;
124 var $s_state;
125 var $s_country;
126
127 // ship to location
128 var $t_zip;
129 var $t_state;
130 var $t_country;
131
132 // package info
133 var $package_type; // 02 customer supplied package
134 var $weight;
135
136 var $length;
137 var $width;
138 var $height;
139
140 var $error=0;
141 var $errormsg;
142 var $xmlarray = array();
143 var $xmlreturndata = "";
144
146 // upsRate
147
148 function upsRate($szip,$sstate,$scountry)
149 {
150 // init function
151 $this->s_zip = $szip;
152 $this->s_state = $sstate;
153 $this->s_country = $scountry;
154
155 }
156
157
159 // upsRateNames
160
161 function upsRateNames()
162 {
163 //US ORIGIN
164
165 $ups_service = array (
166 '01' => 'UPS Next Day Air',
167 '02' => 'UPS 2nd Day Air',
168 '03' => 'UPS Ground',
169 '07' => 'UPS Worldwide Express',
170 '08' => 'UPS Worldwide Expedited',
171 '11' => 'UPS Standard',
172 '12' => 'UPS 3 Day Select',
173 '13' => 'UPS Next Day Air Saver',
174 '14' => 'UPS Next Day Air Early A.M.',
175 '54' => 'UPS Worldwide Express Plus',
176 '59' => 'UPS 2nd Day Air A.M.',
177 '64' => '',
178 '65' => 'UPS Express Saver',
179 );
180
181 return $ups_service;
182 }
183
184
186 // construct_request_xml
187
188 function construct_request_xml(){
189 include_once( "classes/INIFile.php" );
190 $ini =& eZINI::instance( 'site.ini' );
191
192 $xml="<?xml version=\"1.0\"?>
193 <AccessRequest xml:lang=\"en-US\">
194 <AccessLicenseNumber>".$ini->variable( "eZTradeMain", "UPSAccessKey" )."</AccessLicenseNumber>
195 <UserId>".$ini->variable( "eZTradeMain", "UPSUserID" )."</UserId>
196 <Password>".$ini->variable( "eZTradeMain", "UPSPassword" )."</Password>
197 </AccessRequest>
198 <?xml version=\"1.0\"?>
199 <RatingServiceSelectionRequest xml:lang=\"en-US\">
200 <Request>
201 <TransactionReference>
202 <CustomerContext>Rating and Service</CustomerContext>
203 <XpciVersion>1.0001</XpciVersion>
204 </TransactionReference>
205 <RequestAction>Rate</RequestAction>
206 <RequestOption>$this->request</RequestOption>
207 </Request>
208 <PickupType>
209 <Code>$this->pickuptype</Code>
210 </PickupType>
211 <Shipment>
212 <Shipper>
213 <Address>
214 <StateProvinceCode>$this->s_state</StateProvinceCode>
215 <PostalCode>$this->s_zip</PostalCode>
216 <CountryCode>$this->s_country</CountryCode>
217 </Address>
218 </Shipper>
219 <ShipTo>
220 <Address>
221 <StateProvinceCode>$this->t_state</StateProvinceCode>
222 <PostalCode>$this->t_zip</PostalCode>
223 <CountryCode>$this->t_country</CountryCode>
224 <ResidentialAddressIndicator>$this->residential</ResidentialAddressIndicator>
225 </Address>
226 </ShipTo>
227 <Service>
228 <Code>$this->service</Code>
229 </Service>
230 <Package>
231 <PackagingType>
232 <Code>$this->package_type</Code>
233 <Description>Package</Description>
234 </PackagingType>";
235
236 if ( $this->length > 0 &&
237 $this->width > 0 &&
238 $this->height > 0 ) {
239 $xml .=
240 "<Dimensions>
241 <UnitOfMeasurement>
242 <Code>IN</Code>
243 </UnitOfMeasurement>
244 <Length>$this->length</Length>
245 <Width>$this->width</Width>
246 <Height>$this->height</Height>
247 </Dimensions>";
248 }
249
250 $xml .="<Description>Rate Shopping</Description>
251 <PackageWeight>
252 <Weight>$this->weight</Weight>
253 </PackageWeight>
254 </Package>
255 <ShipmentServiceOptions/>
256 </Shipment>
257 </RatingServiceSelectionRequest>";
258
259 return $xml;
260 }
261
263 function rate($service='',$tzip,$tstate='',$tcountry='US',
264 $weight,$length,$height,$width,$residential=0,$packagetype='02')
265 {
266 if($service=='')
267 $this->request = 'shop';
268 else
269 $this->request = 'rate';
270
271 $this->service = $service;
272 $this->t_zip = $tzip;
273 $this->t_state= $tstate;
274 $this->t_country = $tcountry;
275 $this->weight = $weight;
276 $this->length = $length;
277 $this->height = $height;
278 $this->width = $width;
279 $this->residential=$residential;
280 $this->package_type=$packagetype;
281
282 $this->__runCurl();
283
284 $this->xmlarray = $this->_get_xml_array($this->xmlreturndata);
285
286 //check if error occurred
287 if($this->xmlarray==""){
288 $this->error=0;
289 $this->errormsg="Unable to retrieve the Shipping info";
290 return NULL;
291 }
292 $values = $this->xmlarray[RatingServiceSelectionResponse][Response][0];
293
294 if($values[ResponseStatusCode] == 0){
295 $this->error=$values[Error][0][ErrorCode];
296 $this->errormsg=$values[Error][0][ErrorDescription];
297 return NULL;
298 }
299
300 return $this->get_rates();
301 }
302
303
311 function __runCurl()
312 {
313 $y = $this->construct_request_xml();
314 // echo $y;
315
316 include_once( "classes/INIFile.php" );
317 $ini =& eZINI::instance( 'site.ini' );
318
319 $ch = curl_init();
320
321 curl_setopt ($ch, CURLOPT_URL,$ini->variable( "eZTradeMain", "UPSServer" ));
322 curl_setopt ($ch, CURLOPT_HEADER, 0);
323 curl_setopt ($ch, CURLOPT_POST, 1);
324 curl_setopt ($ch, CURLOPT_POSTFIELDS, "$y");
325 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
326 curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
327
328 $this->xmlreturndata = curl_exec ($ch);
329
330 //echo "\n<P>:result--------------\n<P>";
331 //echo $this->xmlreturndata;
332 //curl_errno($ch);
333 curl_close ($ch);
334 }
335
336
347 function __get_xml_array($values, &$i)
348 {
349 $child = array();
350 if ($values[$i]['value']) array_push($child, $values[$i]['value']);
351
352 while (++$i < count($values))
353 {
354 switch ($values[$i]['type'])
355 {
356 case 'cdata':
357 array_push($child, $values[$i]['value']);
358 break;
359
360 case 'complete':
361 $name = $values[$i]['tag'];
362 $child[$name]= $values[$i]['value'];
363 if($values[$i]['attributes'])
364 {
365 $child[$name] = $values[$i]['attributes'];
366 }
367 break;
368
369 case 'open':
370 $name = $values[$i]['tag'];
371 $size = sizeof($child[$name]);
372 if($values[$i]['attributes'])
373 {
374 $child[$name][$size] = $values[$i]['attributes'];
375 $child[$name][$size] = $this->__get_xml_array($values, $i);
376 }
377 else
378 {
379 $child[$name][$size] = $this->__get_xml_array($values, $i);
380 }
381 break;
382
383 case 'close':
384 return $child;
385 break;
386 }
387 }
388 return $child;
389 }
390
391
401 function _get_xml_array($data)
402 {
403 $values = array();
404 $index = array();
405 $array = array();
406 $parser = xml_parser_create();
407 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
408 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
409 xml_parse_into_struct($parser, $data, $values, $index);
410 xml_parser_free($parser);
411
412 $i = 0;
413
414 $name = $values[$i]['tag'];
415 $array[$name] = $values[$i]['attributes'];
416 $array[$name] = $this->__get_xml_array($values, $i);
417
418 return $array;
419 }
420
421
422 function get_rates()
423 {
424 // $retArray = array('service'=>'','basic'=>0,'option'=>0,'total'=>0,'days'=>'','time'=>'');
425
426 $retArray=array();
427
428 $values = $this->xmlarray[RatingServiceSelectionResponse][RatedShipment];
429 $ct = count($values);
430 for($i=0;$i<$ct;$i++){
431 $current=&$values[$i];
432
433 $retArray[$i]['service'] = $current[Service][0][Code];
434 $retArray[$i]['basic'] = $current[TransportationCharges][0][MonetaryValue];
435 $retArray[$i]['option'] = $current[ServiceOptionsCharges][0][MonetaryValue];
436 $retArray[$i]['total'] = $current[TotalCharges][0][MonetaryValue];
437 $retArray[$i]['days'] = $current[GuaranteedDaysToDelivery];
438 $retArray[$i]['time'] = $current[ScheduledDeliveryTime];
439 }
440
441 unset($values);
442
443 return $retArray;
444 }
445
446 }
447 ?>
$i
$i
Definition: admin/adlist.php:91
$ini
$ini
Definition: classes/admin/linklist.php:64
upsRate
Definition: ezupsxml.php:93
upsRate\$upstool
$upstool
Definition: ezupsxml.php:105
upsRate\$s_country
$s_country
Definition: ezupsxml.php:125
upsRate\$pickuptype
$pickuptype
Definition: ezupsxml.php:108
upsRate\$accesskey
$accesskey
Definition: ezupsxml.php:104
upsRate\$length
$length
Definition: ezupsxml.php:136
upsRate\_get_xml_array
_get_xml_array($data)
Definition: ezupsxml.php:401
upsRate\upsRateNames
upsRateNames()
Definition: ezupsxml.php:161
upsRate\$passwd
$passwd
Definition: ezupsxml.php:103
upsRate\$weight
$weight
Definition: ezupsxml.php:134
upsRate\$xmlarray
$xmlarray
Definition: ezupsxml.php:142
upsRate\$t_zip
$t_zip
Definition: ezupsxml.php:128
upsRate\$t_state
$t_state
Definition: ezupsxml.php:129
upsRate\$s_state
$s_state
Definition: ezupsxml.php:124
upsRate\$t_country
$t_country
Definition: ezupsxml.php:130
upsRate\get_rates
get_rates()
Definition: ezupsxml.php:422
upsRate\$errormsg
$errormsg
Definition: ezupsxml.php:141
upsRate\$width
$width
Definition: ezupsxml.php:137
upsRate\$residential
$residential
Definition: ezupsxml.php:120
upsRate\$userid
$userid
Definition: ezupsxml.php:102
upsRate\$height
$height
Definition: ezupsxml.php:138
upsRate\$error
$error
Definition: ezupsxml.php:140
upsRate\__get_xml_array
__get_xml_array($values, &$i)
Definition: ezupsxml.php:347
upsRate\$package_type
$package_type
Definition: ezupsxml.php:133
upsRate\$s_zip
$s_zip
Definition: ezupsxml.php:123
upsRate\upsRate
upsRate($szip, $sstate, $scountry)
Definition: ezupsxml.php:148
upsRate\construct_request_xml
construct_request_xml()
Definition: ezupsxml.php:188
upsRate\rate
rate($service='', $tzip, $tstate='', $tcountry='US', $weight, $length, $height, $width, $residential=0, $packagetype='02')
Definition: ezupsxml.php:263
upsRate\__runCurl
__runCurl()
Definition: ezupsxml.php:311
upsRate\$xmlreturndata
$xmlreturndata
Definition: ezupsxml.php:143
upsRate\$service
$service
Definition: ezupsxml.php:106
upsRate\$request
$request
Definition: ezupsxml.php:100
$name
$name
Definition: companytypelist.php:194
error
error( $errmsg)
Definition: eZPBINIFile.php:465
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$index
$index
Definition: ezforum/user/messageedit.php:36
$ups_service
$ups_service
Definition: ezupsxml.php:69
$values
$values
Definition: fixedvalues.php:103
$current
$current
Definition: slideshow.php:97
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.