Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezusps.php
Go to the documentation of this file.
1 <?php
3 //
4 // Class: eZ USPS (Services)
5 // Licence: GNU GPL
6 //
8
9 class ezuspsservices
10 {
11 function ezuspsget($ser,$user,$pwd,$totarr,$wgt="",$dzip,$dsta,$dcou,$ozip,$sta,$cou,$street1,$street2="",$mach="false")
12 {
13 $this->server = $ser;
14 $this->user = $user;
15 $this->pass = $pwd;
16 $this->totalarr = $totarr;
17
18 //$this->weight = $wgt;
19
20 if ($dcou = 'United Kingdom') {
21 $dcou = 'Great Britain';
22 }
23
24 $this->destzip = $dzip;
25 $this->deststate = $dsta;
26 $this->destcountry = $dcou;
27 $this->orginzip = $ozip;
28 $this->state = $sta;
29 $this->country = $cou;
30 $this->mach = $mach;
31
32 $this->destaddress1 = $street1;
33 $this->destaddress2 = $street2;
34
35 // $this->container = "Flat Rate Box";
36 $this->container = "None";
37
38 $this->size = "Oversize";
39 $this->getservice();
40
41 //$this->getweight();
42 //$this->setpounds();
43 //$this->setcontainer();
44 //$this->setsize();
45
46 $getres = $this->getresult();
47 $cc = $this->num;
48
49 // print_r ($getres);
50
51 return $getres;
52 }
53
54
56 function getservice()
57 {
58 if(($this->destcountry=="United States of America")&&(($this->deststate=="AK")||($this->deststate=="HI")))
59 {
60 $servicearr[0] = "Parcel";
61 $servicearr[1] = "Priority";
62 $this->service = $servicearr;
63 $this->status = "true";
64 }
65 elseif(($this->destcountry=="United States of America")&&(($this->deststate=="AF")||($this->deststate=="AA")||($this->deststate=="AC")||($this->deststate=="AE")||($this->deststate=="AM")||($this->deststate=="AP")))
66 {
67 $servicearr[0] = "Parcel";
68 $servicearr[1] = "Priority";
69 $this->service = $servicearr;
70 $this->status = "true";
71 }
72 elseif($this->country=="Canada")
73 {
74 $servicearr[0] = "Airmail Parcel";
75
76 $servicearr[1] = "Priority Lg";
77 $servicearr[2] = "Priority Sm";
78 $servicearr[3] = "Priority Var";
79 $this->service = $servicearr;
80 }
81 elseif(($this->country!="Canada")||($this->country!="United States of America"))
82 {
83 $servicearr[0] = "Airmail Parcel";
84
85 $servicearr[1] = "Priority Lg";$this->num = $n;
86 $servicearr[2] = "Priority Sm";
87 $servicearr[3] = "Priority Var";
88 $this->service = $servicearr;
89 }
90 return $this->service;
91 }
92
93
95 function getweight()
96 {
97 if($this->weight<0.1)
98 $this->weight = 0.1;
99 else
100 $this->weight = $this->weight;
101
102 return $this->weight;
103 }
104
105
107 function setpounds()
108 {
109 $fullpounds = $this->weight;
110 $this->pounds = floor($this->weight);
111 $this->ounce = round(16*($fullpounds-$this->pounds));
112 if(empty($this->ounce))
113 $this->ounce=0;
114 }
115
116
118 function setcontainer()
119 {
120 // $this->container = "None"; //for Customer Package.
121 $this->container = "None";
122 // $this->container = "Flat Rate Box";
123 }
124
125
127 function setsize()
128 {
129 $tot = $this->totalarr;
130 foreach($tot[box] as $to)
131 {
132 $this->height = $to[height];
133 $this->width = $to[width];
134 $this->length = $to[length];
135 $this->count = $to[count];
136
137 // $this->container = "Flat Rate Box";
138 $this->container = "None"; //for Customer Package.
139
140 $this->totsize = $this->length + (2*($this->width+$this->height));
141
142 if(($this->totsize<=84)&&($this->weight<15))
143 $this->size = "Regular";
144 elseif(($this->totsize>84)&&($this->totsize<=108)&&($this->weight<15))
145 $this->size = "Large";
146 else
147 $this->size = "Oversize";
148 }
149 }
150
151
153 function verifyaddress() {
154 $str = "API=Verify&XML=<AddressValidateRequest USERID=\"";
155 $str .= $this->user . "\" PASSWORD=\"" . $this->pass . "\">";
156 $str .= '<Address ID="0"><Address1></Address1>'.$this->destaddress1.'<Address2>'.$this->destaddress2.'</Address2><City>'.$this->destcity.'</City><State>'.$this->deststate.'</State><Zip5>'.$this->destzip.'</Zip5><Zip4></Zip4></Address></AddressValidateRequest>';
157
158 // Curl : Options
159 $ch = curl_init();
160
161 curl_setopt($ch, CURLOPT_URL,"http://production.shippingapis.com/shippingAPI.dll");
162
163 curl_setopt($ch, CURLOPT_HEADER,0);
164 curl_setopt($ch, CURLOPT_POST,1);
165 curl_setopt($ch, CURLOPT_POSTFIELDS,"$str");
166 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
167 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
168 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
169
170 $this->xmladdressver = curl_exec($ch);
171
172 echo ($this->xmladdressver);
173
174 if (stristr($this->xmladdressver, '<Error>')) {
175 return false;
176 }
177
178 return true;
179 }
180
181
183 function getresult()
184 {
185 $this->nocombine = true;
186
187 foreach ($this->totalarr[box] as $boxflatcheck)
188 {
189 if ($boxflatcheck['flatusps'] == 'off')
190 $this->nocombine = false;
191 }
192
193 foreach ($this->totalarr[withoutbox] as $woutflatcheck)
194 {
195 if ($woutflatcheck['flatusps'] == 'off')
196 $this->nocombine = false;
197 }
198
199 if ($this->nocombine) {
200 return $this->getFlatResult();
201 }
202
203 $i=0;
204 $response = array();
205 $rate = array();
206 $arrpush = array();
207 $rates = array();
208 $this->machinable ="True";
209
210 if($this->destcountry=="United States of America")
211 {
212 // If (!$this->verifyaddress()) {
213 // return false;
214 // }
215 // $str = $this->server. "?API=Rate&XML=<RateRequest USERID=\"";
216
217 $str = "API=Rate&XML=<RateRequest USERID=\"";
218 $str .= $this->user . "\" PASSWORD=\"" . $this->pass . "\">";
219
220 // print_r($this->totalarr[box]);
221
222 $cou=0;
223 foreach($this->totalarr[box] as $getbox)
224 {
225 $this->weight = $getbox[weight];
226 $this->height = $getbox[height];
227 $this->length = $getbox[length];
228 $this->width = $getbox[width];
229 $this->count = $getbox[count];
230
231 $this->flatusps = $getbox['flatusps'];
232 $this->combineflat = $getbox['combineflat'];
233 $this->totsize = $this->length + (2*($this->width+$this->height));
234
235 if(($this->totsize<=84)&&($this->weight<15))
236 $this->size = "Regular";
237 elseif(($this->totsize>84)&&($this->totsize<=108)&&($this->weight<15))
238 $this->size = "Large";
239 else
240 $this->size = "Oversize";
241
242 if($this->weight<0.1)
243 $this->weight = 0.1;
244 else
245 $this->weight = $this->weight;
246
247 $fullpounds = $this->weight;
248 $this->pounds = floor($this->weight);
249 $this->ounce = round(16*($fullpounds-$this->pounds));
250
251 if(empty($this->ounce))
252 $this->ounce=0;
253
254 for($cou=0;$cou<$this->count;$cou++)
255 {
256 $str .= "<Package ID=\"$cou\"><Service>".Parcel . "</Service><ZipOrigination>" . $this->orginzip . "</ZipOrigination>";
257 $str .= "<ZipDestination>" . $this->destzip . "</ZipDestination>";
258 $str .= "<Pounds>" . $this->pounds . "</Pounds><Ounces>" . $this->ounce . "</Ounces>";
259 $str .= "<Container>" . $this->container . "</Container><Size>" . $this->size . "</Size>";
260 $str .= "<Machinable>" . $this->machinable . "</Machinable></Package>";
261 }
262 }
263
264 for ($j=0; $j<sizeof($this->totalarr[withoutbox]);$j++)
265 {
266 $this->wt = $this->totalarr[withoutbox][$j][weight];
267 $this->addamount = 0;
268
269 if (is_numeric($this->totalarr[withoutbox][$j][flatusps]) && $this->totalarr[withoutbox][$j][flatusps] == 0) continue;
270 if ($this->totalarr[withoutbox][$j][flatusps] != 'off' && !$this->totalarr[withoutbox][$j][combineflat])
271 {
272 $this->addamount += $this->totalarr[withoutbox][$j][flatusps];
273 continue;
274 }
275
276 if($this->wt<0.1)
277 $this->wt = 0.1;
278 else
279 $this->wt = $this->wt;
280
281 $fullpnds = $this->wt;
282 $this->pnds = floor($this->wt);
283 $this->oun = round(16*($fullpnds-$this->pnds));
284
285 if(empty($this->oun))
286 $this->oun=0;
287 if(empty($this->pnds)&&empty($this->oun))
288 $this->oun=0.1;
289 /*
290 $this->withoutcount = $this->totalarr[withoutbox][count];
291 $this->withoutcount = $cou + $this->withoutcount;
292 $inc = $cou;
293 */
294
295 $str .= "<Package ID=\"$inc\"><Service>".Parcel . "</Service><ZipOrigination>" . $this->orginzip . "</ZipOrigination>";
296 $str .= "<ZipDestination>" . $this->destzip . "</ZipDestination>";
297 $str .= "<Pounds>" . $this->pnds . "</Pounds><Ounces>" . $this->oun . "</Ounces>";
298 $str .= "<Container>" . $this->container . "</Container><Size>Regular</Size>";
299 $str .= "<Machinable>" . $this->machinable . "</Machinable></Package>";
300 }
301 $str .= "</RateRequest>";
302 }
303 // echo $str;
304
305 // ### INTERNATIONAL ##############################################
306 if($this->destcountry!="United States of America")
307 {
308 // $str = "API=IntlRate&XML=<RateRequest USERID=\"";
309
310 $str = "API=IntlRate&XML=<IntlRateRequest USERID=\"";
311 $str .= $this->user . "\" PASSWORD=\"" . $this->pass . "\">";
312
313 foreach($this->totalarr[box] as $getbox)
314 {
315 $this->weight = $getbox[weight];
316 $this->height = $getbox[height];
317 $this->length = $getbox[length];
318 $this->width = $getbox[width];
319 $this->count = $getbox[count];
320 $this->totsize = $this->length + (2*($this->width+$this->height));
321
322 if(($this->totsize<=84)&&($this->weight<15))
323 $this->size = "Regular";
324 elseif(($this->totsize>84)&&($this->totsize<=108)&&($this->weight<15))
325 $this->size = "Large";
326 else
327 $this->size = "Oversize";
328
329 if($this->weight<0.1)
330 $this->weight = 0.1;
331 else
332 $this->weight = $this->weight;
333
334 $fullpounds = $this->weight;
335 $this->pounds = floor($this->weight);
336 $this->ounce = round(16*($fullpounds-$this->pounds));
337
338 if(empty($this->ounce))
339 $this->ounce=0;
340
341 for($cou=0;$cou<$this->count;$cou++)
342 {
343 $str .= "<Package ID=\"$cou\"><Pounds>" . $this->pounds . "</Pounds><Ounces>" . $this->ounce . "</Ounces>";
344 $str .= "<MailType>" .Package . "</MailType><Country>" . $this->destcountry."</Country>";
345 $str .= "</Package>";
346 }
347 }
348 for ($j=0; $j<sizeof($this->totalarr[withoutbox]);$j++)
349 {
350 $this->wt = $this->totalarr[withoutbox][$j][weight];
351
352 if($this->wt<0.1)
353 $this->wt = 0.1;
354 else
355 $this->wt = $this->wt;
356
357 $fullpnds = $this->wt;
358 $this->pnds = floor($this->wt);
359 $this->oun = round(16*($fullpnds-$this->pnds));
360
361 if(empty($this->oun))
362 $this->oun=0;
363 if(empty($this->pnds)&&empty($this->oun))
364 $this->oun=0.1;
365
366 $str .= "<Package ID=\"$inc\"><Pounds>" . $this->pnds . "</Pounds><Ounces>" . $this->oun . "</Ounces>";
367 $str .= "<MailType>" .Package . "</MailType><Country>" . $this->destcountry."</Country>";
368 $str .= "</Package>";
369 }
370
371 $str .="</IntlRateRequest>";
372
373 }
374
375
376 // ####################################################################################
377
378
380 // Curl : Options
381 $ch = curl_init();
382
383 // ini -- UserUSPSServer=http://production.shippingapis.com/ShippingAPI.dll
384 $c_server = "http://production.shippingapis.com/shippingAPI.dll";
385 curl_setopt($ch, CURLOPT_URL, $c_server);
386
387 curl_setopt($ch, CURLOPT_HEADER,0);
388 curl_setopt($ch, CURLOPT_POST,1);
389 curl_setopt($ch, CURLOPT_POSTFIELDS,"$str");
390 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
391 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
392 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
393
394 $this->xmlreturndata = curl_exec($ch);
395 $body = $this->xmlreturndata;
396 // echo $body;
397
398 if($this->destcountry=="United States of America")
399 {
400 $noofservices=1;
401 while (true) {
402 if ($start = strpos($body, '<Package')) {
403 $body = substr($body, $start);
404 $end = strpos($body, '</Package>');
405 $response[] = substr($body, 0, $end+10);
406 $body = substr($body, $end+9);
407 } else {
408 break;
409 }
410 }
411
412 // if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
413 if (sizeof($response) == '1') {
414 if (ereg('<Error>', $response[0])) {
415
416 $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
417 $number = $regs[1];
418
419 $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
420 $description = $regs[1];
421 return '';
422 // return array('error' => $number . ' - ' . $description);
423 }
424 }
425
426 $nopackage = sizeof($response);
427
428 for ($i=0; $i<$nopackage; $i++) {
429 if (strpos($response[$i], '<Postage>')) {
430
431 $service = ereg('<Service>(.*)</Service>', $response[$i], $regs);
432 $service = $regs[1];
433 $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs);
434 $postage = $regs[1];
435
436 $rates[0][0] = $postage+$rates[0][0];
437 $rates[1][0] ="USPS $service";
438 }
439 }
440 }
441
442 if($this->destcountry!="United States of America")
443 {
444 while (true) {
445
446 if ($start = strpos($body, '<Package ID=')) {
447 $body = substr($body, $start);
448 $end = strpos($body, '</Package>');
449 $response[] = substr($body, 0, $end+10);
450 $body = substr($body, $end+9);
451 } else {
452 break;
453 }
454 }
455
456 $rates = array();
457 if (sizeof($response) == '1') {
458 if (ereg('<Error>', $response[0])) {
459 $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
460 $number = $regs[1];
461 $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
462 $description = $regs[1];
463 return '';
464 // return array('error' => $number . ' - ' . $description);
465 }
466 }
467
468 $nopackage = sizeof($response);
469
470 //echo "total count". $n;
471 //print_r($response);
472
473 for ($j=0; $j<$nopackage; $j++) {
474 $body = $response[$i];
475 $xs=0;
476 $closedx=true;
477 while ($closedx) {
478 // $xs=$xs+1;
479 // if ($xs==6) {break;}
480
481 $start = strpos($body, '<Service ID=');
482 if ($start===false) {
483 $closedx=false;
484 break;
485 }
486 else
487 {
488 // $body = substr($body, $start);
489 // echo $body ."<br><br>";
490 $end = strpos($body, '</Service>');
491 $end =$end +10;
492 $servicex[] = substr($body,$start,$end-$start);
493 // echo $servicex[$xs-1]. "- $start - $end <br><br>";
494 $body = substr($body, $end);
495 }
496 }
497
498 // echo $j;
499 // print_r($servicex); echo "<br /><hr />";
500
501 $n = sizeof($servicex);
502 $noofservices=$n;
503 $this->num = $n;
504 for ($i=0; $i<$n; $i++)
505 {
506 $body = $servicex[$i];
507 $bod = $servicex[$i];
508 if ($start = strpos($body, '<Postage'))
509 {
510 $body = substr($body, $start);
511
512 $end = strpos($body, '</Postage>');
513 $post = substr($body,9,$end-9);
514 // echo $post;
515 $postvalue[$j]=$postvalue[$j]+$post;
516 $body = substr($body, $end+10);
517 }
518 if ($ss = strpos($bod,'<SvcDescription>'))
519 {
520 $bod = substr($bod, $ss);
521 $end = strpos($bod, '</SvcDescription>');
522 $desc = substr($bod,16,$end-16);
523 //echo $desc;
524 //$totdesc.$i = $totdesc.$i;
525 $body = substr($bod, $end+17);
526 }
527
528 $rates[0][$i]=$post+$rates[0][$i];
529 $rates[1][$i]="USPS $desc";
530 }
531 }
532 }
533
534
535 // building the whole shiping method string
536 for ($ij=0;$ij<$noofservices;$ij++)
537 {
538 $ratestotal[$ij]=$rates[0][$ij]."||".$rates[1][$ij];
539 }
540
541
542
543 // strip out canada?
544 if ( $this->destcountry == "Canada" ) {
545 /* Remove / Blank out a single entry
546 unset( $rates[1][0] );
547 */
548 unset( $ratestotal );
549 // print_r( $ratestotal );
550 // echo "<br /><hr />";
551 } elseif ( $this->destcountry == "United States of America" ) {
552 /* Remove / Blank out a single entry
553 unset( $rates[1][0] );
554 */
555 unset( $ratestotal );
556 // print_r( $ratestotal );
557 // echo "<br /><hr />";
558 }
559 elseif ( $this->destcountry == "Australia" ) {
560 /* Remove / Blank out a single entry
561 unset( $rates[1][0] );
562 */
563 // unset( $ratestotal );
564 //print_r( $ratestotal );
565
566 // print_r( $ratestotal[0] ); echo "<br />";
567 unset( $ratestotal[0] );
568
569 // print_r( $ratestotal[1] ); echo "<br />";
570 unset( $ratestotal[1] );
571
572 // print_r( $ratestotal[2] ); echo "<br />";
573 // unset( $ratestotal[2] );
574
575 // print_r( $ratestotal[3] ); echo "<br />";
576 // unset( $ratestotal[3] );
577
578 // print_r( $ratestotal[4] ); echo "<br />";
579 unset( $ratestotal[4] );
580
581 // echo "<br /><hr />";
582
583 // print_r( $ratestotal );
584
585 // echo "<br /><hr />";
586 } elseif ( $this->destcountry == "Great Britain" ) {
587 // print_r( $ratestotal[0] ); echo "<br />";
588 unset( $ratestotal[0] );
589
590 // print_r( $ratestotal[1] ); echo "<br />";
591 unset( $ratestotal[1] );
592
593 // print_r( $ratestotal[2] ); echo "<br />";
594 // unset( $ratestotal[2] );
595
596 // print_r( $ratestotal[3] ); echo "<br />";
597 // // unset( $ratestotal[3] );
598
599 // print_r( $ratestotal[4] ); echo "<br />";
600 unset( $ratestotal[4] );
601
602 // echo "<br /><hr />";
603
604 // print_r( $ratestotal );
605
606 } else {
607 // echo 'no block<br>';
608 // echo $this->destcountry;
609
610 // print_r( $ratestotal );
611
612 // print_r($rates);
613 // print_r( $rates[1] );
614 // echo "<br /><hr />";
615 }
616
617 if ( $this->destcountry != "United States of America" ) {
618 /* Remove / Blank out a single entry
619 unset( $rates[1][0] );
620 */
621 // unset( $ratestotal );
622 //print_r( $ratestotal );
623
624 // print_r( $ratestotal[0] ); echo "<br />";
625 unset( $ratestotal[0] );
626
627 // print_r( $ratestotal[1] ); echo "<br />";
628 unset( $ratestotal[1] );
629
630 // print_r( $ratestotal[2] ); echo "<br />";
631 // unset( $ratestotal[2] );
632
633 // print_r( $ratestotal[3] ); echo "<br />";
634 // unset( $ratestotal[3] );
635
636 // print_r( $ratestotal[4] ); echo "<br />";
637 unset( $ratestotal[4] );
638
639 // echo "<br /><hr />";
640
641 // print_r( $ratestotal );
642
643 // echo "<br /><hr />";
644 }
645
646 //exit;
647
648 return $ratestotal;
649 }
650
651
653 function getFlatResult()
654 {
655 if (!empty($this->totalarr[box])) {
656 foreach ($this->totalarr[box] as $boxnum => $box) {
657 $this->addamount = $this->addamount + $box[flatusps];
658 }
659 }
660 if (!empty($this->totalarr[withoutbox])) {
661 foreach ($this->totalarr[withoutbox] as $woutnum => $wout) {
662 $this->addamount = $this->addamount + $wout[flatusps];
663 }
664 }
665 if ($this->addamount == 0) {
666 return '0.00' . '||' . 'USPS Parcel (Free Shipping)';
667 }
668 elseif (strlen($this->addamount) < 3)
669 {
670 $this->addamount = $this->addamount . '.00';
671 }
672 elseif (strlen($this->addamount) < 4)
673 {
674 $this->addamount = $this->addamount . '0';
675 }
676 return array ( 0 => $this->addamount . '||' . 'USPS Parcel (Flat Shipping)');
677
678 }
679
680 }
681 ?>
$i
$i
Definition: admin/adlist.php:91
ezuspsservices
Definition: ezusps-cleaner.php:10
ezuspsservices\getweight
getweight()
Definition: ezusps.php:95
ezuspsservices\$weight
$weight
Definition: ezusps-cleaner.php:15
ezuspsservices\setcontainer
setcontainer()
Definition: ezusps.php:118
ezuspsservices\$height
$height
Definition: ezusps-cleaner.php:37
ezuspsservices\getresult
getresult()
Definition: ezusps-cleaner.php:213
ezuspsservices\setpounds
setpounds()
Definition: ezusps.php:107
ezuspsservices\$service
$service
Definition: ezusps-cleaner.php:27
ezuspsservices\getFlatResult
getFlatResult()
Definition: ezusps-cleaner.php:729
ezuspsservices\$mach
$mach
Definition: ezusps-cleaner.php:22
ezuspsservices\$count
$count
Definition: ezusps-cleaner.php:36
ezuspsservices\ezuspsget
ezuspsget($ser, $user, $pwd, $totarr, $wgt="", $dzip, $dsta, $dcou, $ozip, $sta, $cou, $street1, $street2="", $mach="false")
Definition: ezusps.php:11
ezuspsservices\$xmlreturndata
$xmlreturndata
Definition: ezusps-cleaner.php:33
ezuspsservices\getservice
getservice()
Definition: ezusps-cleaner.php:84
ezuspsservices\verifyaddress
verifyaddress()
Definition: ezusps.php:153
ezuspsservices\$totalarr
$totalarr
Definition: ezusps-cleaner.php:14
ezuspsservices\$user
$user
Definition: ezusps-cleaner.php:12
ezuspsservices\setsize
setsize()
Definition: ezusps.php:127
ezuspsservices\$num
$num
Definition: ezusps-cleaner.php:31
$desc
$desc
Definition: companytypelist.php:195
$str
$str
Definition: ezarticle/modules/content.php:30
$j
$j
Definition: ezimagecatalogue/admin/imagelist.php:345
$response
while(!feof($socket)) $response
Definition: paypalnotify.php:196
$box
foreach( $vatTypes as $type) $box
Definition: productedit.php:1356
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.