Fault Code:SOAP-ENV:Server String:Fault in Fedex Rate Service Response - php

require_once('modules/FedEx/RateAvailableServicesService_v18_php/library/fedex-common.php5');
$path_to_wsdl = PATH."modules/FedEx/RateAvailableServicesService_v18_php/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' => $this->getProperty('key'),
//'Password' => $this->getProperty('password')
//),
'UserCredential' => array(
'Key' => $this->getProperty('key'),
'Password' => $this->getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => $this->getProperty('shipaccount'),
'MeterNumber' => $this->getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '1'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
// Service Type and Packaging Type are not passed in the request
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['Shipper'] = array(
'Address'=> array('StreetLines' => array($UL->str_add1,$UL->str_add2),'City' => $UL->city_name,'StateOrProvinceCode' => $UL->state_name,'PostalCode' => $UL->zipcode,'CountryCode' => $UL->country_code));
$request['RequestedShipment']['Recipient'] = array(
'Address'=>array('StreetLines' => array($this->session->get('shipping_address1'),$this->session->get('shipping_address2')),'City' => $shipping_city,'StateOrProvinceCode' => $shipping_state,'PostalCode' => $this->session->get('shipping_postal_code'),'CountryCode' => $country_code,'Residential' => false));
$request['RequestedShipment']['ShippingChargesPayment'] = array(
'PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => $this->getProperty('billaccount'),
'Contact' => null,
'Address' => array(
'CountryCode' => COUNTRY_CODE
)
)
)
);
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'0' => array(
'SequenceNumber' => 1,
'GroupPackageCount' => 1,
'Weight' => array(
'Value' => $UL->weight//,
//'Units' => 'LB'
),
'Dimensions' => array(
'Length' => $UL->length,
'Width' => $UL->width,
'Height' => $UL->height//,
//'Units' => 'IN'
)
)
);
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client ->getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){
echo 'Rates for following service type(s) were returned.'. Newline. Newline;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td>';
if(is_array($response -> RateReplyDetails)){
foreach ($response -> RateReplyDetails as $rateReply){
$this->printRateReplyDetails($rateReply);
}
}else{
$this->printRateReplyDetails($response -> RateReplyDetails);
}
echo '</table>'. Newline;
printSuccess($client, $response);
}else{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
Here is error exception which i am getting
Fault
Code:SOAP-ENV:Server
String:Fault
Request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v18"><SOAP-ENV:Body><ns1:RateRequest><ns1:WebAuthenticationDetail><ns1:UserCredential><ns1:Key>AndJurrJfCvvWZWn</ns1:Key><ns1:Password>Rps8Pl4jF9zGp5wiEpDRhKiHo</ns1:Password></ns1:UserCredential></ns1:WebAuthenticationDetail><ns1:ClientDetail><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:MeterNumber>107714405</ns1:MeterNumber></ns1:ClientDetail><ns1:TransactionDetail><ns1:CustomerTransactionId> *** Rate Available Services Request using PHP ***</ns1:CustomerTransactionId></ns1:TransactionDetail><ns1:Version><ns1:ServiceId>crs</ns1:ServiceId><ns1:Major>18</ns1:Major><ns1:Intermediate>0</ns1:Intermediate><ns1:Minor>1</ns1:Minor></ns1:Version><ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit><ns1:RequestedShipment><ns1:ShipTimestamp>2016-03-30T18:35:41+05:30</ns1:ShipTimestamp><ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType><ns1:ServiceType>INTERNATIONAL_PRIORITY</ns1:ServiceType><ns1:Shipper><ns1:Address><ns1:StreetLines>SUITE 5A-1204</ns1:StreetLines><ns1:StreetLines>799 E DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode></ns1:Address></ns1:Shipper><ns1:Recipient><ns1:Address><ns1:StreetLines>795 E</ns1:StreetLines><ns1:StreetLines>DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode><ns1:Residential>false</ns1:Residential></ns1:Address></ns1:Recipient><ns1:ShippingChargesPayment><ns1:PaymentType>SENDER</ns1:PaymentType><ns1:Payor><ns1:ResponsibleParty><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:Address><ns1:CountryCode>KWI</ns1:CountryCode></ns1:Address></ns1:ResponsibleParty></ns1:Payor></ns1:ShippingChargesPayment><ns1:PackageCount>1</ns1:PackageCount><ns1:RequestedPackageLineItems><ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount><ns1:Weight>
<ns1:Value>20</ns1:Value></ns1:Weight><ns1:Dimensions>
<ns1:Length>8</ns1:Length><ns1:Width>10</ns1:Width>
<ns1:Height>10</ns1:Height></ns1:Dimensions></ns1:RequestedPackageLineItems>
</ns1:RequestedShipment></ns1:RateRequest></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Since you have trace on, you should look at the actual request/response data. When I took your raw POST data above (in which you shouldn't have posted your account/key info) I get back a schema validation error. Syntax looks correct but the country code for payor is KWI but should be US. I'd suggest you add some code to log the request and responses...
$soap_response_hdr = $client->__getLastResponseHeaders() ;
$soap_response = $client->__getLastResponse() ;
$soap_request_hdr = $client->__getLastRequestHeaders() ;
$soap_request = $client->__getLastRequest() ;

Related

WordPress: Form posting but php script not executing

My goal is to have the user fill out a form with country and postal code, post the data to a php script that makes a call to fedex's server and returns shipment rates.
I have successfully accomplished this on my local web server, but upon implementation to my WordPress site, the php script does not execute when the form data is posted. My code is as follows:
rate.php (form and php script both in this file):
<!-- FORM -->
<h1 style="font-family: "Ek Mukta", sans-serif;">Quick Quote</h1>
<br>
<form id="quick-quote" class="" action="" method="post">
<label>Country</label>
<br>
<input id="country" type="text" name="country" value="">
<br>
<label>Postal Code</label>
<br>
<input id="postal" type="text" name="postal" value="">
<br>
<br>
<input id="submit" type="submit" name="" value="submit">
</form>
<br>
<!-- FEDEX CALL -->
<?php
print_r($_POST); //this works!
error_reporting(E_ALL);
session_start();
require_once('../../library/fedex-common.php'); //code seems to break here
$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "RateService/RateService_v20.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(
'UserCredential' =>array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v20 using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '20',
'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'] = 'INTERNATIONAL_ECONOMY'; // 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']['TotalInsuredValue']=array('Ammount'=>0,'Currency'=>'USD');
$request['RequestedShipment']['Shipper'] = addShipper();
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['VariableHandlingChargeDetail'] = addHandlingCharge();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
//$request['RequestedShipment']['RateRequestTypes'] = addRateType();
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
// $request['RequestedShipment']['RateRequestTypes'] = 'PREFERRED ';
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem1();
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>';
$country = $_POST['country'];
$postal = $_POST['postal'];
$productPrice = 100;
$serviceFee = 50;
echo $country;
// echo '<tr><td>Country Code </td><td>Postal Code</td><td>Service Type</td><td>Amount</td><td>Delivery Date</td></tr><tr>';
$serviceType = '<td>'.$rateReply -> ServiceType . '</td>';
$amount = number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalVariableHandlingCharges->TotalCustomerCharge->Amount,2,".",",");
if(array_key_exists('DeliveryTimestamp',$rateReply)){
$deliveryDate= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
}else if(array_key_exists('TransitTime',$rateReply)){
$deliveryDate= '<td>' . $rateReply->TransitTime . '</td>';
}else {
$deliveryDate='<td> </td>';
}
$total = $productPrice + $serviceFee + $amount;
// echo "<td>$country</td>. <td>$postal</td>. $serviceType. <td>$amount</td>. $deliveryDate";
// echo '</tr>';
// echo '</table>';
echo
"
<h3>Country Code: $country</h3>
<h3>Postal Code: $postal</h3>
<br>
<table>
<tr>
<td>Product Cost</td>
<td>Shipping Cost</td>
<td>Service Fee</td>
<td>Total</td>
</tr>
<br>
<tr>
<td>$$productPrice<span>+</span></td>
<td>$$amount<span>+</span></td>
<td>$$serviceFee<span>=</span></td>
<td>$$total </td>
</tr>
</table>";
printSuccess($client, $response);
}
else
{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
//FUNCTIONS
function addShipper(){
$shipper = array(
'Contact' => array(
'PersonName' => 'XXX',
'CompanyName' => 'XXX',
'PhoneNumber' => 'XXX'),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => 'New York',
'StateOrProvinceCode' => 'XXX',
'PostalCode' => 'XXXX',
'CountryCode' => 'US')
);
return $shipper;
}
function addRecipient(){
$country = $_POST['country'];
$postal = $_POST['postal'];
$recipient = array(
'Contact' => array(
'PersonName' => 'Recipient Name',
'CompanyName' => 'Company Name',
'PhoneNumber' => 'XXX'
),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => '',
'StateOrProvinceCode' => '',
'PostalCode' => ''.$postal.'',
'CountryCode' => ''.$country.'',
'Residential' => false)
);
return $recipient;
}
//HANDLING CHARGE
function addHandlingCharge(){
$VariableHandlingChargeDetail = array(
'RateTypeBasis' => 'LIST',
'RateElementBasis' => 'BASE_CHARGE', // valid values NET_CHARGE, NET_CHARGE_EXCLUDING_TAXES, NET_FREIGHT
'FixedValue' => array('Currency' => 'USD', 'Amount' => 0),
'PercentValue' => '0',
);
return $VariableHandlingChargeDetail;
};
function addShippingChargesPayment(){
$shippingChargesPayment = array(
'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
// 'PostalCode' => '10036',
'CountryCode' => 'US')
)
);
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_7X4.75');
return $labelSpecification;
}
function addSpecialServices(){
$specialServices = array(
'SpecialServiceTypes' => array('COD'),
'CodDetail' => array(
'CodCollectionAmount' => array('Currency' => 'USD', 'Amount' => 150),
'CollectionType' => 'ANY')// ANY, GUARANTEED_FUNDS
);
return $specialServices;
}
function addPackageLineItem1(){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => 2,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 2,
'Width' => 2,
'Height' => 2,
'Units' => 'IN'
)
);
return $packageLineItem;
}
?>
quick-quote.php (template file to include feature on specific pages):
<?php /* Template Name: quick-quote */ ?>
<?php
get_header();
include('RateService_v20_php/RateAvailableServicesService_v20_php/php/RateWebServiceClient/RateAvailableServices/RateAvailableServicesWebServiceClient.php');
get_footer();
?>
functions.php (relevant code only):
add_action( 'admin_post_quick_quote', 'prefix_admin_quick_quote' );
function prefix_admin_quick_quote() {
// What do I do here!?
}
The issue that I have having is this:
-I fill out the form
-hit submit
-print_r($_POST) the data to see if form posted correctly (it does)
-any code after require_once('../../library/fedex-common.php'); does not execute
Things I have already checked/tried:
-PHP and SOAP are installed correctly on the server
-all files are excessible 664 not 666
-ran the file on the server, it works fine
-setting the form's action to "rate.php" or "quick-quote.php" (form posts data to same page so I think this can be left blank)
-made sure ('../../library/fedex-common.php') is the correct path
So my questions are:
-How do I make the php script execute after the form is submitted?
-Is this accomplished using functions.php to hook into admin-post.php?
Thanks so much!
It sounds like PHP does not have access to fedex-common.php.
Change the relative path for the 'require_once` to an absolute path.
Check that the application has permissions to the directory.
Check that the application has permissions to execute the file.
Additionally, you can check that the include is success by replacing the 'require_once' with the following to further determine if the issue actually a side effect of the file location or an issue with the referenced file.
if(!#include_once("/PATH/TO/library/fedex-common.php")) {
throw new Exception ('fedex-common.php does not exist');
}

Array to string conversion with nusoap client

I sent request to webservice like this :
$transaction = new Transaction();
$transaction->amount = $amount;
$transaction->order_id = $orderId;
$transaction->status = 0;
$transaction->additional_data = $additionalData;
$transaction->type = 1;
$transaction->ip = Request::getClientIp();
$transaction->save();
$soap = new nusoap_client(self::$request_url);
$fields = array(
'terminalId' => self::$terminalId,
'userName' => self::$username,
'userPassword' => self::$password,
'orderId' => $transaction->order_id,
'amount' => $amount,
'localDate' => date('Ymd'),
'localTime' => date('His'),
'additionalData' => $additionalData,
'callBackUrl' => self::$callBackUrl,
'payerId' => 0,
);
$response = $soap->call('bpPayRequest', $fields, 'http://interfaces.core.sw.bps.com/');
but i get exception in line 2125 in nusoap.php :
Array to string conversion
exception thrown from :
// TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
foreach(curl_getinfo($this->ch) as $k => $v){
$err .= "$k: $v<br>";
}
$this->debug($err);

Why is PHP SoapClient / Webservice not giving a response?

I have a script that consumes a webservice through SOAP. I'm wondering why I don't receive a response from the server/endpoint URL. The other side said that they're receiving my requests so it means the script works. The only problem is that it doesn't give me a response. I also tried to get the last request, last request header and last response but nothing happens.
Do you have any idea why this is happening?
Here's my code:
$wsdl = "http://imupost.co.za/momentum/CRMLeadService.wsdl";
$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0";
echo("Post to URL: {$momurl}\n");
$username = "817221";
$password = "1234";
echo("<pre>");
$client = new SoapClient ($wsdl, array('location' => $momurl, 'style' => SOAP_DOCUMENT, 'trace' => 1, 'soap_version' => SOAP_1_1, 'exceptions' => true, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'ssl_method' => SOAP_SSL_METHOD_TLS));
$header='
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-45">
<wsse:Username>'.$username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
';
$headerSoapVar = new SoapVar($header,XSD_ANYXML);
$soapheader = new SoapHeader('wsse', "Security" , $headerSoapVar , true);
$client->__setSoapHeaders($soapheader);
$params['createLead'] = array(
'LeadSourceId' => '07d3d6fe-7682-e311-a16d-005056b81ea8',
'AffiliateLeadReference' => '852800020',
'Title' => array('Code' => '852800018'),
'Initials' => 'MH',
'PreferredName' => 'Jane',
'FirstName' => 'Hudson',
'LastName' => 'Craig',
'PreferredCorrespondenceLanguage' => array('Code' => '852800001'),
'PreferredCommunicationMethod' => array('Code' =>'852800000'),
'HomePhoneNumber' => '0725222427',
'BusinessPhoneNumber' => '0725584155',
'MobilePhoneNumber' => '0723694259',
'EmailAddress' => 'jhudson#gmail.com',
'Notes' => 'IMU',
'ProductCategories' => array('Code' => '9c7d3878-5295-e211-9330-005056b81ea8', 'Description' => 'Health - Personal')
);
$result = $client->__soapCall("createLead", array($params));
echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
echo "RESPONSE:\n" . $client->__getLastResponse() . "\n";
print_r($client->__getLastRequestHeaders());
I would suggest using a try catch.
try {
$client->__soapCall("createLead", array($params));
echo $client->__getLastResponse();
} catch (Exception $e) {
echo "<pre>Exception: ".print_r($e, true)."</pre>\n";
}

How to solve Error: SOAP-ERROR: Encoding: object has no 'createLead' property?

I have written a script that should connect to a secure web service (ws-security). However, when running the script, I'm getting this error:
Error: SOAP-ERROR: Encoding: object has no 'createLead' property
I'm using this code:
<?php
$wsdl = "http://localhost/test/wsdl-src/CRMLeadService.wsdl";
$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/";
echo "Post to URL: {$momurl}\n";
$username = '817221';
$password = '1234';
//Perform Request
$client = new SoapClient ($wsdl, array('loacation' => $momurl));
$security = array('UsernameToken' => array(
'Username'=>"$username",
'Password'=>"$password"
));
$header = new SoapHeader('wsse','Security',$security, false);
$client->__setSoapHeaders($header);
print_r($client);
echo "<br />";
print_r( $client->__getFunctions() ); //Available Function
$params = array(
'LeadSourceId' => '23627e70-a29e-e211-b8a8-005056b81ebe',
'AffiliateLeadReference' => '5465546hdfh5sggd52',
'Title' => '852800018',
'Initials' => 'MD',
'PreferredName' => 'Marius',
'FirstName' => 'Marius',
'LastName' => 'Drew',
'PreferredCorrespondenceLanguage' => '852800001',
'PreferredCommunicationMethod' => '852800000',
'Campaign' => '',
'HomePhoneNumber' => '0723621762',
'BusinessPhoneNumber' => '0723621762',
'MobilePhoneNumber' => '0723621762',
'EmailAddress' => 'mdrew#gmail.com',
'Notes' => 'IMU',
'ProductCategories' => array('Code' => 'd000083d-229c-e211-b8a8-005056b81ebe')
);
print_r($params);
try {
echo $result = $client->__soapCall('createLead',array('parameters'=>$params));
} catch (Exception $e) {
$msgs = $e->getMessage();
echo "Error: $msgs";
}
?>
The WSDL and XSD files can be downloaded here:
http://sdrv.ms/16KC8o4
Any help would be appreciated. Thanks!

Fedex Shipping Labels API not sending Address 2

THE SOAP REQUEST AS SENT
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/ship/v12">
<SOAP-ENV:Body>
<ns1:ProcessShipmentRequest>
<ns1:WebAuthenticationDetail>
<ns1:UserCredential>
<ns1:Key>kQyj3MtQGLJ3ZYWG</ns1:Key>
<ns1:Password>66ywMwyasljK5uRkaNENRZCZW</ns1:Password>
</ns1:UserCredential>
</ns1:WebAuthenticationDetail>
<ns1:ClientDetail>
<ns1:AccountNumber>510087682</ns1:AccountNumber>
<ns1:MeterNumber>100154483</ns1:MeterNumber>
</ns1:ClientDetail>
<ns1:TransactionDetail>
<ns1:CustomerTransactionId>*** Express Domestic Shipping Request v12 using PHP ***</ns1:CustomerTransactionId>
</ns1:TransactionDetail>
<ns1:Version>
<ns1:ServiceId>ship</ns1:ServiceId>
<ns1:Major>12</ns1:Major>
<ns1:Intermediate>1</ns1:Intermediate>
<ns1:Minor>0</ns1:Minor>
</ns1:Version>
<ns1:RequestedShipment>
<ns1:ShipTimestamp>2013-03-25T14:33:08+00:00</ns1:ShipTimestamp>
<ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType>
<ns1:ServiceType>FEDEX_GROUND</ns1:ServiceType>
<ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType>
<ns1:TotalWeight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>17.22</ns1:Value>
</ns1:TotalWeight>
<ns1:Shipper>
<ns1:Contact>
<ns1:PersonName>Shipping Department</ns1:PersonName>
<ns1:CompanyName>Big Dog Treestands</ns1:CompanyName>
<ns1:PhoneNumber>3092636800</ns1:PhoneNumber>
</ns1:Contact>
<ns1:Address>
<ns1:StreetLines>120 E. Detroit Parkway</ns1:StreetLines>
<ns1:City>Morton</ns1:City>
<ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode>
<ns1:PostalCode>61550</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode>
</ns1:Address>
</ns1:Shipper>
<ns1:Recipient>
<ns1:Contact>
<ns1:PersonName>David Sinc</ns1:PersonName>
<ns1:CompanyName>TEST COMPANY</ns1:CompanyName>
<ns1:PhoneNumber>3093701229</ns1:PhoneNumber>
</ns1:Contact>
<ns1:Address>
<ns1:StreetLines>1202 Chalet Ln</ns1:StreetLines>
<ns1:StreetLines>HIDDLY- Test Account</ns1:StreetLines>
<ns1:City>PEORIA</ns1:City>
<ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode>
<ns1:PostalCode>61614</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode>
<ns1:Residential>false</ns1:Residential>
</ns1:Address>
</ns1:Recipient>
<ns1:ShippingChargesPayment>
<ns1:PaymentType>SENDER</ns1:PaymentType>
<ns1:Payor>
<ns1:ResponsibleParty>
<ns1:AccountNumber>510087682</ns1:AccountNumber>
<ns1:Contact/>
<ns1:Address>
<ns1:CountryCode>US</ns1:CountryCode>
</ns1:Address>
</ns1:ResponsibleParty>
</ns1:Payor>
</ns1:ShippingChargesPayment>
<ns1:LabelSpecification>
<ns1:LabelFormatType>COMMON2D</ns1:LabelFormatType>
<ns1:ImageType>PDF</ns1:ImageType>
<ns1:LabelStockType>PAPER_8.5X11_TOP_HALF_LABEL</ns1:LabelStockType>
</ns1:LabelSpecification>
<ns1:RateRequestTypes>ACCOUNT</ns1:RateRequestTypes>
<ns1:PackageCount>1</ns1:PackageCount>
<ns1:RequestedPackageLineItems>
<ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount>
<ns1:Weight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>17.22</ns1:Value>
</ns1:Weight>
</ns1:RequestedPackageLineItems>
</ns1:RequestedShipment>
</ns1:ProcessShipmentRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Fedex APpplication Code
<?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 12.0.0
require_once('library/fedex-common.php5');
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "http://bigdog.webdesign309.com/wp-content/themes/bigdogtreestands-new/woocommerce/emails/ShipWebServiceClient/wsdl/ShipService_v12.wsdl";
$uploads = wp_upload_dir();
define('SHIP_LABEL', $uploads['basedir'].'/shippinglabels/shipexpresslabel'.str_replace('#','',$order->get_order_number()).'.pdf'); // PNG label file. Change to file-extension .pdf for creating a PDF label (e.g. shiplabel.pdf)
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(
'UserCredential' => array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Express Domestic Shipping Request v12 using PHP ***');
$request['Version'] = array(
'ServiceId' => 'ship',
'Major' => '12',
'Intermediate' => '1',
'Minor' => '0'
);
$ships = $order->get_shipping_method();
$shippingType = "FEDEX_GROUND";
if($ships == "Fedex Ground"){
$shippingType = "FEDEX_GROUND";
}
else if( $ships == "Fedex 2 Day"){
$shippingType = "FEDEX_2_DAY";
}
else if($ships == "Fedex Standard Overnight"){
$shippingType = "STANDARD_OVERNIGHT";
}
else if($ships == "Fedex Home Delivery"){
$shippingType = "GROUND_HOME_DELIVERY";
}
function totalOrderWeight($orders) {
$totalWeight = 0;
$items = $orders->get_items();
foreach($items as $item) {
$product = get_product( $item['product_id'] );
$quantity = intval( $item['qty'] );
$totalWeight += $product->get_weight() * $quantity;
}
return $totalWeight;
}
$request['RequestedShipment'] = array(
'ShipTimestamp' => date('c'),
'DropoffType' => 'REGULAR_PICKUP', // valid values REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER and STATION
'ServiceType' => $shippingType, // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
'PackagingType' => 'YOUR_PACKAGING', // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
'TotalWeight' => array('Value' => totalOrderWeight($order), 'Units' => 'LB'), // valid values LB and KG
'Shipper' => addShipper(),
'Recipient' => addRecipient($order),
'ShippingChargesPayment' => addShippingChargesPayment(),
'LabelSpecification' => addLabelSpecification(),
'RateRequestTypes' => array('ACCOUNT'), // valid values ACCOUNT and LIST
'PackageCount' => 1,
'RequestedPackageLineItems' => array(
'0' => addPackageLineItem1(totalOrderWeight($order))
)
);
try
{
if(setEndpoint('changeEndpoint'))
{
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client->processShipment($request); // FedEx web service invocation
if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR')
{
printSuccess($client, $response);
$label =
// Create PNG or PDF label
// Set LabelSpecification.ImageType to 'PDF' or 'PNG for generating a PDF or a PNG label
$fp = fopen(SHIP_LABEL, 'wb');
fwrite($fp, $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image); //Create PNG or PDF file
fclose($fp);
// echo 'Click Here to Download Shipping Label was generated.';
}
else
{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
function addShipper(){
$shipper = array(
'Contact' => array(
'PersonName' => 'Shipping Department',
'CompanyName' => 'Big Dog Treestands',
'PhoneNumber' => '3092636800'),
'Address' => array(
'StreetLines' => array('120 E. Detroit Parkway'),
'City' => 'Morton',
'StateOrProvinceCode' => 'IL',
'PostalCode' => '61550',
'CountryCode' => 'US')
);
return $shipper;
}
function addRecipient($orders){
$residential = get_post_meta($orders->get_order_number(), '_residential-indicator');
/* echo 'Shipping Address 2:'.$orders->shipping_address_2;
echo 'Shipping Address 1:'.$orders->shipping_address_1; */
if($orders->shipping_address_2){
$addressArray = array($orders->shipping_address_1, $orders->shipping_address_2);
/* echo 'Shipping Address 2'; */
/* $addressArray =array('StreetLines' => array('Address Line 1' => $orders->shipping_address_1, 'Address Line 2' => $orders->shipping_address_2)); */
}
else{
$addressArray = array($orders->shipping_address_1);
/* echo 'Shipping Address 1'; */
}
$joy = false;
if($residential == 1){
$joy = true;
}
else{
$joy = false;
}
$recipient = array(
'Contact' => array(
'PersonName' => $orders->billing_first_name . ' ' . $orders->billing_last_name,
'CompanyName' => $orders->shipping_company,
'PhoneNumber' => $orders->billing_phone),
/* 'Address' => array(
'StreetLines' => array($orders->shipping_address_1, $orders->shipping_address_2),
'City' => $orders->shipping_city,
'StateOrProvinceCode' => $orders->shipping_state,
'PostalCode' => $orders->shipping_postcode,
'CountryCode' => 'US',
'Residential' => $joy) */
'Address' => array(
'StreetLines'=>array($orders->shipping_address_1, $orders->shipping_address_2),
//array(utf8_encode($orders->shipping_address_1), utf8_encode($orders->shipping_address_2)),
'City' => $orders->shipping_city,
'StateOrProvinceCode' => $orders->shipping_state,
'PostalCode' => $orders->shipping_postcode,
'CountryCode' => 'US',
'Residential' => $joy)
);
return $recipient;
}
function addShippingChargesPayment(){
$shippingChargesPayment = array('PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
'Contact' => null,
'Address' => array('CountryCode' => 'US'))));
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL');
return $labelSpecification;
}
function addPackageLineItem1($weight){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => $weight,
'Units' => 'LB')
);
return $packageLineItem;
}
?>
It returns this http://bigdog.webdesign309.com/assets/shippinglabels/shipexpresslabel1303.pdf
I have tried everything even calling fedex and they say that they provide no support for this issue as the code is a convenience rather than a service. If anyone can shed some light on this most puzzling issue as to why the second address field never shows up that would be great.
Any thoughts on this one?
In case anyone else comes across this problem, note that FedEx's test labels from their staging environment do not appear to ever include the second address line.
All of my test labels did NOT have a second address line, but as soon as I switched to the production server, the labels had the second line.
It should have multiple address lines as your XML looks valid. FedEx support should be able to provide assistance based on the SOAP request/response, but will not provide assistance with your PHP coding.
according to the Ship Service Docs, you only have two address lines, I solved like this:
'Address' => array(
'StreetLines' => array($array_recipient["address_1"],$array_recipient["address_2"]),
'City' => $array_recipient["City"],
'StateOrProvinceCode' => $array_recipient["StateOrProvinceCode"],
'PostalCode' => $array_recipient["PostalCode"],
'CountryCode' => 'MX',
'Residential' => true
)
in case you need more "space" you can use CUSTOMER_REFERENCE (rigth after dimensions):
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => $dimension_array["weight"],
'Units' => 'KG'
),
'Dimensions' => array(
'Length' => $dimension_array["length"],
'Width' => $dimension_array["width"],
'Height' => $dimension_array["height"],
'Units' => 'CM'
),
'CustomerReferences' => array(
'CustomerReferenceType' => 'CUSTOMER_REFERENCE',
'Value' => $dimension_array["more_references"]
),
If you make the request in Test Enviroment, the second address will not show, but after to production, the second address will shown.
Hope this help you.

Categories