/
rate.php
231 lines (214 loc) · 7.54 KB
/
rate.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
// if have post
if(isset($_POST['submit']))
{
require_once('include/menu.php');
echo "<h1>Rate</h1>";
require_once('include/fedex-common.php');
function addShipper()
{
$shipper = array
(
'Contact' => array
(
'PersonName' => 'Rubaiet M',
'CompanyName' => 'ELS',
'PhoneNumber' => '019130191355'
),
'Address' => getProperty('address1')
);
return $shipper;
} // end of function addShipper
function addRecipient($input)
{
$recipient = array
(
'Contact' => array
(
'PersonName' => $input['PersonName'],
'CompanyName' => $input['CompanyName'],
'PhoneNumber' => $input['PhoneNumber']
),
'Address' => array(
'StreetLines' => array($input['StreetLines']),
'City' => $input['City'],
'StateOrProvinceCode' => $input['StateOrProvinceCode'],
'PostalCode' => $input['PostalCode'],
'CountryCode' => $input['CountryCode'],
'Residential' => 1
)
);
return $recipient;
} // end of function addRecipient
function addShippingChargesPayment($input)
{
$shippingChargesPayment = array
(
'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array
(
'ResponsibleParty' => array
(
'AccountNumber' => getProperty('billaccount'),
'CountryCode' => 'US'
)
)
);
return $shippingChargesPayment;
} // end of function addShippingChargesPayment
function addSmartPostDetail($input)
{
$smartPostDetail = array
(
'Indicia' => 'PARCEL_SELECT',
'AncillaryEndorsement' => 'CARRIER_LEAVE_IF_NO_RESPONSE',
'SpecialServices' => 'USPS_DELIVERY_CONFIRMATION',
'HubId' => getProperty('hubid'),
'CustomerManifestId' => 'XXX'
);
return $smartPostDetail;
} // end of function addSmartPostDetail
function addPackageLineItem($input)
{
$packageLineItem = array
(
'SequenceNumber' => 1,
'GroupPackageCount' => 1,
'Weight' => array
(
'Value' => $input['Weight'],
'Units' => 'LB'
),
'Dimensions' => array
(
'Length' => $input['Length'],
'Width' => $input['Width'],
'Height' => $input['Height'],
'Units' => 'IN'
)
);
return $packageLineItem;
} // end of function addPackageLineItem
$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "wsdl/RateService_v18.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array
(
'ParentCredential' => array
(
'Key' => getProperty('parentkey'),
'Password' => getProperty('parentpassword')
),
'UserCredential' =>array
(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array
(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** SmartPost Rate Request using PHP ***');
$request['Version'] = array
(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '0'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = $_POST['ServiceType']; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['Shipper'] = addShipper($_POST);
$request['RequestedShipment']['Recipient'] = addRecipient($_POST);
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment($_POST);
$request['RequestedShipment']['SmartPostDetail'] = addSmartPostDetail($_POST);
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem($_POST);
try {
if(setEndpoint('changeEndpoint'))
{
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client -> getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
$rateReply = $response -> RateReplyDetails;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Transit Time</td><td>Max Transit Time</td><td>Ship</td></tr><tr>';
$serviceType = '<td>'.$rateReply -> ServiceType . '</td>';
if($rateReply->RatedShipmentDetails && is_array($rateReply->RatedShipmentDetails))
{
$amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
}
elseif($rateReply->RatedShipmentDetails && ! is_array($rateReply->RatedShipmentDetails))
{
$amount = '<td>$' . number_format($rateReply->RatedShipmentDetails->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
} // endif
if(array_key_exists('TransitTime',$rateReply->CommitDetails))
{
$transitTime= '<td>' . $rateReply->CommitDetails->TransitTime . '</td>';
}
elseif(array_key_exists('DeliveryTimestamp',$rateReply))
{
$transitTime= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
}
else
{
$transitTime= '<td>' . 'N/A' . '</td>';
} // endif
if(array_key_exists('MaximumTransitTime',$rateReply->CommitDetails))
{
$maxTransitTime= '<td>' . $rateReply->CommitDetails->MaximumTransitTime . '</td>';
}
else
{
$maxTransitTime= '<td>' . 'not working' . '</td>';
} // endif
echo $serviceType . $amount. $transitTime. $maxTransitTime;
?>
<td>
<form action="ship.php" method="post">
<input type="hidden" name="ServiceType" value="<?php echo $_POST['ServiceType']?>">
<input type="hidden" name="PersonName" value="<?php echo $_POST['PersonName']?>">
<input type="hidden" name="CompanyName" value="<?php echo $_POST['CompanyName']?>">
<input type="hidden" name="PhoneNumber" value="<?php echo $_POST['PhoneNumber']?>">
<input type="hidden" name="StreetLines" value="<?php echo $_POST['StreetLines']?>">
<input type="hidden" name="City" value="<?php echo $_POST['City']?>">
<input type="hidden" name="StateOrProvinceCode" value="<?php echo $_POST['StateOrProvinceCode']?>">
<input type="hidden" name="PostalCode" value="<?php echo $_POST['PostalCode']?>">
<input type="hidden" name="CountryCode" value="<?php echo $_POST['CountryCode']?>">
<input type="hidden" name="Length" value="<?php echo $_POST['Length']?>">
<input type="hidden" name="Width" value="<?php echo $_POST['Width']?>">
<input type="hidden" name="Height" value="<?php echo $_POST['Height']?>">
<input type="hidden" name="Weight" value="<?php echo $_POST['Weight']?>">
<input type="submit" name="submit" name="Finalize Shipment">
</form>
</td>
<?php
echo '</tr>';
echo '</table>';
// printSuccess($client, $response);
}
else
{
printError($client, $response);
}
writeToLog($client); // Write to log file
}
catch (SoapFault $exception)
{
printFault($exception, $client);
}
}
else
{
header('Location: index.php');
}