-
Notifications
You must be signed in to change notification settings - Fork 0
/
uc_fedex.trck.inc
123 lines (107 loc) · 3.99 KB
/
uc_fedex.trck.inc
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
<?php
/**
* @file
* FedEx Web Services Rate / Available Services Quote.
*
* Shipping quote module that interfaces with the FedEx Web Services API
* to get rates for small package shipments. Implements a SOAP Web Service
* client.
*
* @author Tim Rohaly. <http://drupal.org/user/202830>
*/
/******************************************************************************
* Tracking Functions (trck service) *
******************************************************************************/
/**
* Constructs and executes a SOAP TrackService request.
* Returns Tracking information.
*
* SOAP call parameters are set in the order they appear in the WSDL file.
* Associative array of DOM returned.
*
* @param $tracking_number
* FedEx Tracking number.
*
* @return
* Associative array mirroring contents of SOAP object returned from server.
*/
function uc_fedex_tracking_request($tracking_number) {
// Set up SOAP call.
// Allow tracing so details of request can be retrieved for error logging.
$client = new SoapClient(
drupal_get_path('module', 'uc_fedex') .
'/wsdl-' . variable_get('uc_fedex_server_role', 'testing') .
'/TrackService_v5.wsdl',
array('trace' => 1)
);
// FedEx user key and password filled in by user on admin form.
$request['WebAuthenticationDetail'] = array(
'UserCredential' => array(
'Key' => variable_get('uc_fedex_user_credential_key', 0),
'Password' => variable_get('uc_fedex_user_credential_password', 0),
)
);
// FedEx account and meter number filled in by user on admin form.
$request['ClientDetail'] = array(
'AccountNumber' => variable_get('uc_fedex_account_number', 0),
'MeterNumber' => variable_get('uc_fedex_meter_number', 0),
);
// Optional parameter, contains anything.
$request['TransactionDetail'] = array(
'CustomerTransactionId' => '*** Track Service Request v5 from Ubercart ***'
);
// Track Request v5.0.0.
$request['Version'] = array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0',
);
// Tracking Number.
$request['PackageIdentifier'] = array(
'Value' => $tracking_number,
'Type' => 'TRACKING_NUMBER_OR_DOORTAG',
);
// Include Details.
$request['IncludeDetailedScans'] = TRUE;
//
// Send the SOAP request to the FedEx server.
//
try {
$response = $client->track($request);
if ($response->HighestSeverity != 'FAILURE' &&
$response->HighestSeverity != 'ERROR') {
print_request_response($client);
/*
// Just an Example of how to use this information.
// You would typically do the following in whatever routine
// called this function, not here.
$reply = $response->TrackDetails;
print('Tracking Number = ' . $reply->TrackingNumber . "<br />");
print(' ' . $reply->StatusDescription);
print(' by ' . $reply->ServiceInfo);
print(' weight ' . $reply->PackageWeight->Value. ' ' . $reply->PackageWeight->Units . "<br />");
print('Estimated Delivery ' . $reply->EstimatedDeliveryTimestamp . "<br />");
foreach($reply->Events as $event) {
print(' Event = ' . $event->EventDescription . " " . $event->Address->City . ", " . $event->Address->StateOrProvinceCode . " on " . $event->Timestamp. "<br />");
}
*/
}
else {
drupal_set_message(t('Error in processing FedEx tracking transaction.'), 'error');
foreach ($response->Notifications as $notification) {
if (is_array($response->Notifications)) {
drupal_set_message($notification->Severity . ': ' .
$notification->Message, 'error');
}
else {
drupal_set_message($notification, 'error');
}
}
}
return $response;
}
catch (SoapFault $exception) {
drupal_set_message('<h2>Fault</h2><br /><b>Code:</b>' . $exception->faultcode . '<br /><b>String:</b>' . $exception->faultstring . '<br />', 'error');
}
}