Guest User

Untitled

a guest
Jan 5th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. <?php
  2.  
  3. // Copyright 2009, FedEx Corporation. All rights reserved.
  4.  
  5. define('TRANSACTIONS_LOG_FILE', '../fedextransactions.log'); // Transactions log file
  6.  
  7. /**
  8. * Print SOAP request and response
  9. */
  10. define('Newline',"<br />");
  11.  
  12. function printSuccess($client, $response) {
  13. echo '<h2>Transaction Successful</h2>';
  14. echo "\n";
  15. printRequestResponse($client);
  16. }
  17. function printRequestResponse($client){
  18. echo '<h2>Request</h2>' . "\n";
  19. echo '<pre>' . htmlspecialchars($client->__getLastRequest()). '</pre>';
  20. echo "\n";
  21.  
  22. echo '<h2>Response</h2>'. "\n";
  23. echo '<pre>' . htmlspecialchars($client->__getLastResponse()). '</pre>';
  24. echo "\n";
  25. }
  26.  
  27. /**
  28. * Print SOAP Fault
  29. */
  30. function printFault($exception, $client) {
  31. echo '<h2>Fault</h2>' . "<br>\n";
  32. echo "<b>Code:</b>{$exception->faultcode}<br>\n";
  33. echo "<b>String:</b>{$exception->faultstring}<br>\n";
  34. writeToLog($client);
  35. }
  36.  
  37. /**
  38. * SOAP request/response logging to a file
  39. */
  40. function writeToLog($client){
  41. if (!$logfile = fopen(TRANSACTIONS_LOG_FILE, "a"))
  42. {
  43. error_func("Cannot open " . TRANSACTIONS_LOG_FILE . " file.\n", 0);
  44. exit(1);
  45. }
  46.  
  47. fwrite($logfile, sprintf("\r%s:- %s",date("D M j G:i:s T Y"), $client->__getLastRequest(). "\n\n" . $client->__getLastResponse()));
  48. }
  49.  
  50. /**
  51. * This section provides a convenient place to setup many commonly used variables
  52. * needed for the php sample code to function.
  53. */
  54. function getProperty($var){
  55. if($var == 'check') Return true;
  56. if($var == 'shipaccount') Return 'XXX';
  57. if($var == 'billaccount') Return 'XXX';
  58. if($var == 'dutyaccount') Return 'XXX';
  59. if($var == 'accounttovalidate') Return 'XXX';
  60. if($var == 'meter') Return 'XXX';
  61. if($var == 'key') Return 'XXX';
  62. if($var == 'password') Return 'XXX';
  63. if($var == 'shippingChargesPayment') Return 'SENDER';
  64. if($var == 'internationalPaymentType') Return 'SENDER';
  65. if($var == 'readydate') Return '2010-05-26T08:44:07';
  66. if($var == 'readytime') Return '12:00:00-05:00';
  67. if($var == 'closetime') Return '20:00:00-05:00';
  68. if($var == 'closedate') Return date("Y-m-d");
  69. if($var == 'dispatchdate') Return date("Y-m-d", mktime(8, 0, 0, date("m") , date("d")+1, date("Y")));
  70. if($var == 'dispatchtimestamp') Return mktime(8, 0, 0, date("m") , date("d")+1, date("Y"));
  71. if($var == 'shiptimestamp') Return mktime(10, 0, 0, date("m"), date("d")+4, date("Y"));
  72. if($var == 'tag_readytimestamp') Return mktime(10, 0, 0, date("m"), date("d")+4, date("Y"));
  73. if($var == 'tag_latesttimestamp') Return mktime(15, 0, 0, date("m"), date("d")+4, date("Y"));
  74. if($var == 'dispatchlocationid') Return 'XXX';
  75. if($var == 'dispatchconfirmationnumber') Return 'XXX';
  76. if($var == 'trackingnumber') Return 'XXX';
  77. if($var == 'trackaccount') Return 'XXX';
  78. if($var == 'shipdate') Return '2009-09-02';
  79. if($var == 'account') Return 'XXX';
  80. if($var == 'phonenumber') Return '9015551212';
  81. if($var == 'rth_trackingnumber') Return 'XXX';
  82. if($var == 'rth_shipdate') Return '2010-05-21';
  83. if($var == 'closedate') Return '2010-06-03';
  84. if($var == 'hubid') Return '5254';
  85. if($var == 'address1') Return array('StreetLines' => array('10 Fed Ex Pkwy'),
  86. 'City' => 'Memphis',
  87. 'StateOrProvinceCode' => 'TN',
  88. 'PostalCode' => '38115',
  89. 'CountryCode' => 'US');
  90. if($var == 'address2') Return array('StreetLines' => array('13450 Farmcrest Ct'),
  91. 'City' => 'Herndon',
  92. 'StateOrProvinceCode' => 'VA',
  93. 'PostalCode' => '20171',
  94. 'CountryCode' => 'US');
  95. if($var == 'locatoraddress') Return array(array('StreetLines'=>'240 Central Park S'),
  96. 'City'=>'Austin',
  97. 'StateOrProvinceCode'=>'TX',
  98. 'PostalCode'=>'78701',
  99. 'CountryCode'=>'US');
  100. if($var == 'holdcontactandlocation') Return array('Contact'=>array('ContactId' => 'arnet',
  101. 'PersonName' => 'Hold Contact',
  102. 'Title' => 'Manager',
  103. 'CompanyName' => 'FedEx Office Print & Ship Center',
  104. 'PhoneNumber' => '7036890004'),
  105. 'Address'=>array('StreetLines'=>array('13085 Worldgate Dr '),
  106. 'City' =>'Herndon',
  107. 'StateOrProvinceCode' => 'VA',
  108. 'PostalCode' => '20170',
  109. 'CountryCode' => 'US'));
  110. if($var == 'recipientcontact') Return array('ContactId' => 'arnet',
  111. 'PersonName' => 'Recipient Contact',
  112. 'PhoneNumber' => '1234567890');
  113. }
  114. function setEndpoint($var){
  115. if($var == 'changeEndpoint') Return false;
  116. if($var == 'endpoint') Return 'XXX';
  117. }
  118.  
  119. function printNotifications($notes){
  120. foreach($notes as $noteKey => $note){
  121. if(is_string($note)){
  122. echo $noteKey . ': ' . $note . Newline;
  123. }
  124. else{
  125. printNotifications($note);
  126. }
  127. }
  128. echo Newline;
  129. }
  130.  
  131. function printError($client, $response){
  132. echo '<h2>Error returned in processing transaction</h2>';
  133. echo "\n";
  134. printNotifications($response -> Notifications);
  135. printRequestResponse($client, $response);
  136. }
  137. function trackDetails($details, $spacer){
  138. foreach($details as $key => $value){
  139. echo '<tr>';
  140. if(is_array($value) || is_object($value)){
  141. $newSpacer = $spacer. '&nbsp;&nbsp;&nbsp;&nbsp;';
  142. echo '<td>'. $spacer . $key.'</td>';
  143. trackDetails($value, $newSpacer);
  144. }
  145. else echo '<td>'.$spacer. $key .'</td><td>'.$value.'</td>';
  146. echo '</tr>';
  147. }
  148. }
  149.  
  150. ?>
Add Comment
Please, Sign In to add comment