forked from pdf2e/Tektiles
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathups.rate.class.php
executable file
·147 lines (131 loc) · 4.32 KB
/
ups.rate.class.php
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
<?php
// This script was written with help from Mark Sanborn at http://www.marksanborn.net
class UpsShippingQuote {
# Hard Coded UPS Account information
var $strAccessLicenseNumber = 'CCD014DD4CB4AC62';
var $strUserId = 'jgriner0918';
var $strPassword = 'From1248';
var $strShipperNumber = 'R06535';
var $strShipperZip = '37167';
var $strDefaultServiceCode = '03'; // Ground Shipping
var $strRateWebServiceLocation = 'https://www.ups.com/ups.app/xml/Rate'; // Production URL
var $boolDebugMode = false;
function UpsShippingQuote() { }
private function GetServiceCode($strService='GND') {
switch(strtoupper($strService)) {
case '1DM':
$strServiceCode = '14';
break;
case '1DA':
$strServiceCode = '01';
break;
case '1DP':
$strServiceCode = '13';
break;
case '2DM':
$strServiceCode = '59';
break;
case '2DA':
$strServiceCode = '02';
break;
case '3DS':
$strServiceCode = '12';
break;
case 'GND':
$strServiceCode = '03';
break;
default:
$strServiceCode = '03';
break;
}
return $strServiceCode;
} #exit GetServiceCode()
public function GetShippingRate( $strDestinationZip, $strServiceShortName='GND',
$strPackageLength=18, $strPackageWidth=12,
$strPackageHeight=4, $strPackageWeight=2, $boolReturnPriceOnly=true) {
$strServiceCode = $this->GetServiceCode($strServiceShortName);
$strXml ="<?xml version=\"1.0\"?>
<AccessRequest xml:lang=\"en-US\">
<AccessLicenseNumber>{$this->strAccessLicenseNumber}</AccessLicenseNumber>
<UserId>{$this->strUserId}</UserId>
<Password>{$this->strPassword}</Password>
</AccessRequest>
<?xml version=\"1.0\"?>
<RatingServiceSelectionRequest xml:lang=\"en-US\">
<Request>
<TransactionReference>
<CustomerContext>Bare Bones Rate Request</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>Rate</RequestAction>
<RequestOption>Rate</RequestOption>
</Request>
<PickupType>
<Code>01</Code>
</PickupType>
<Shipment>
<Shipper>
<Address>
<PostalCode>{$this->strShipperZip}</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<ShipperNumber>{$this->strShipperNumber}</ShipperNumber>
</Shipper>
<ShipTo>
<Address>
<PostalCode>{$strDestinationZip}</PostalCode>
<CountryCode>US</CountryCode>
<ResidentialAddressIndicator/>
</Address>
</ShipTo>
<ShipFrom>
<Address>
<PostalCode>{$this->strShipperZip}</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>{$strServiceCode}</Code>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
</PackagingType>
<Dimensions>
<UnitOfMeasurement>
<Code>IN</Code>
</UnitOfMeasurement>
<Length>{$strPackageLength}</Length>
<Width>{$strPackageWidth}</Width>
<Height>{$strPackageHeight}</Height>
</Dimensions>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>{$strPackageWeight}</Weight>
</PackageWeight>
</Package>
</Shipment>
</RatingServiceSelectionRequest>";
$rsrcCurl = curl_init($this->strRateWebServiceLocation);
curl_setopt($rsrcCurl, CURLOPT_HEADER, 0);
curl_setopt($rsrcCurl, CURLOPT_POST, 1);
curl_setopt($rsrcCurl, CURLOPT_TIMEOUT, 60);
curl_setopt($rsrcCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rsrcCurl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($rsrcCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($rsrcCurl, CURLOPT_POSTFIELDS, $strXml);
$strResult = curl_exec($rsrcCurl);
if($this->boolDebugMode) echo "<p>{$strResult}</p>";
$objResult = new SimpleXMLElement($strResult);
if($this->boolDebugMode) print_r($objResult);
curl_close($rsrcCurl);
if($boolReturnPriceOnly) {
return (string) $objResult->RatedShipment->TotalCharges->MonetaryValue;
} else {
return $objResult;
}
} # end method GetShippingRate()
} # end class UpsShippingQuote
?>