Skip to content

Instantly share code, notes, and snippets.

@manashcse11
Created July 12, 2017 04:45
Show Gist options
  • Save manashcse11/c688e38eced368b8bf014f7c7ef1827c to your computer and use it in GitHub Desktop.
Save manashcse11/c688e38eced368b8bf014f7c7ef1827c to your computer and use it in GitHub Desktop.
public function parseSoapResponseToArray($response) {
$xml = preg_replace('/(<\/?)(\w+):([^>]*>)/', '$1$2$3', $response);
$xml = simplexml_load_string($xml);
$json = json_encode($xml);
return $responseArray = json_decode($json,true);
}
$request_xml = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.rating.uss.transforce.ca" xmlns:xsd="http://ws.rating.uss.transforce.ca/xsd" xmlns:xsd1="http://dto.uss.transforce.ca/xsd">
<soapenv:Header/>
<soapenv:Body>
<ws:getRates>
<ws:request>
<xsd:password>uss</xsd:password>
<xsd:user_id>admin@uss.com</xsd:user_id>
<xsd:shipment>
<xsd1:delivery_address_line_1>123 MAIN ST</xsd1:delivery_address_line_1>
<xsd1:delivery_city>MISSISSAUGA</xsd1:delivery_city>
<xsd1:delivery_country>CA</xsd1:delivery_country>
<xsd1:delivery_name>COMPANY NAME</xsd1:delivery_name>
<xsd1:delivery_postal_code>L5R3R3</xsd1:delivery_postal_code>
<xsd1:delivery_province>ON</xsd1:delivery_province>
<xsd1:dimension_unit>I</xsd1:dimension_unit>
<xsd1:packages>
<xsd1:package_info_num>
<xsd1:name>LENGTH</xsd1:name>
<xsd1:value>20.0</xsd1:value>
</xsd1:package_info_num>
<xsd1:package_info_num>
<xsd1:name>WIDTH</xsd1:name>
<xsd1:value>20.0</xsd1:value>
</xsd1:package_info_num>
<xsd1:package_info_num>
<xsd1:name>HEIGHT</xsd1:name>
<xsd1:value>20.0</xsd1:value>
</xsd1:package_info_num>
<xsd1:reported_weight>10</xsd1:reported_weight>
</xsd1:packages>
<xsd1:pickup_address_line_1>5555 DIXIE RD</xsd1:pickup_address_line_1>
<xsd1:pickup_city>MISSISSAUGA</xsd1:pickup_city>
<xsd1:pickup_name>LOOMIS EXPRESS</xsd1:pickup_name>
<xsd1:pickup_postal_code>L4W1E6</xsd1:pickup_postal_code>
<xsd1:pickup_province>ON</xsd1:pickup_province>
<xsd1:reported_weight_unit>L</xsd1:reported_weight_unit>
<xsd1:service_type>DD</xsd1:service_type>
<xsd1:shipment_info_str>
<xsd1:name>fragile</xsd1:name>
<xsd1:value>TRUE</xsd1:value>
</xsd1:shipment_info_str>
<xsd1:shipment_info_str>
<xsd1:name>sat_delivery</xsd1:name>
<xsd1:value>TRUE</xsd1:value>
</xsd1:shipment_info_str>
<xsd1:shipment_info_num>
<xsd1:name>declared_value</xsd1:name>
<xsd1:value>200</xsd1:value>
</xsd1:shipment_info_num>
<xsd1:shipper_num>HB4499</xsd1:shipper_num>
<xsd1:shipping_date>20170717</xsd1:shipping_date>
</xsd:shipment>
</ws:request>
</ws:getRates>
</soapenv:Body>
</soapenv:Envelope>';
//Change this variables.
$location_URL = 'https://sandbox.loomis-express.com/axis2/services/USSRatingService?wsdl';
$action_URL = "https://sandbox.loomis-express.com/axis2/services/USSRatingService?wsdl";
$client = new SoapClient(null, array(
'location' => $location_URL,
'uri' => "",
'trace' => 1,
));
try{
//Get response from here
$response = $client->__doRequest($request_xml,$location_URL,$action_URL,1);
$responseArray = parseSoapResponseToArray($response);
}
catch (SoapFault $exception){
var_dump(get_class($exception));
var_dump($exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment