it's a few days that I am trying to update the quantity of inventory on Amazon through php and Amazon MWS in php (without using MWS APIs because in my opinion are out of dated)
Here is my code:
$param = array();
$param['AWSAccessKeyId'] = $this->CHIAVE_ACCESSO;
$param['Action'] = 'SubmitFeed';
$param['Merchant'] = $this->SELLER_ID;
$param['FeedType'] = '_POST_INVENTORY_AVAILABILITY_DATA_';
$param['SignatureMethod'] = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version'] = '2009-01-01';
$params['MarketplaceId.Id.1'] = $this->MARCKETPLACE_IT;
$params['MarketplaceId.Id.2'] = $this->MARCKETPLACE_UK;
$params['MarketplaceId.Id.3'] = $this->MARCKETPLACE_ES;
$params['MarketplaceId.Id.4'] = $this->MARCKETPLACE_DE;
$params['MarketplaceId.Id.5'] = $this->MARCKETPLACE_FR;
$param['PurgeAndReplace'] = 'false';
foreach ($param as $key => $val) {
$key = str_replace("%7E", "~", rawurlencode($key));
$val = str_replace("%7E", "~", rawurlencode($val));
$url[] = "{$key}={$val}";
}
$amazon_feed = '<?xml version="1.0" encoding="utf-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>' .$this->SELLER_ID. '</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>'.$sku.'</SKU>
<Quantity>'.$qty.'</Quantity>
</Inventory>
</Message>
</AmazonEnvelope>';
sort($url);
$arr = implode('&', $url);
$sign = 'POST' . "\n";
$sign .= 'mws.amazonservices.it' . "\n";
$sign .= '/Feeds/'.$param['Version'].'' . "\n";
$sign .= $arr;
$signature = hash_hmac("sha256", $sign, $this->secretKey, true);
$httpHeader = array();
$httpHeader[] = 'Transfer-Encoding: chunked';
$httpHeader[] = 'Content-Type: application/xml';
$httpHeader[] = 'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
//$httpHeader[] = 'x-amazon-user-agent: MyScriptName/1.0';
$httpHeader[] = 'Expect:';
$httpHeader[] = 'Accept:';
$signature = urlencode(base64_encode($signature));
$link = "https://mws.amazonservices.it/Feeds/".$param['Version']."?";
$link .= $arr . "&Signature=" . $signature;
echo $link;
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$errors=curl_error($ch);
curl_close($ch);
echo '<pre>';
print_r($response); //xml response
The response is
50691017150_POST_INVENTORY_AVAILABILITY_DATA_2016-12-15T10:00:09+00:00_SUBMITTED_47843855-c5fb-4db9-bc3c-1ccd0aff4169
But When I go on the Amazon Inventory I cannot see any changes. I've tried also to wait some days but nothing changes.
What I'm doing wrong?
Thanks in advance for help!
Using MWS Scratchpad the error I have is the following
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>A2PDC8GCZHAL2D</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>50691017150</DocumentTransactionID>
<StatusCode>Complete</StatusCode>
<ProcessingSummary>
<MessagesProcessed>1</MessagesProcessed>
<MessagesSuccessful>0</MessagesSuccessful>
<MessagesWithError>1</MessagesWithError>
<MessagesWithWarning>0</MessagesWithWarning>
</ProcessingSummary>
<Result>
<MessageID>1</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>13013</ResultMessageCode>
<ResultDescription>This SKU does not exist in the Amazon.com catalog. Your inventory data was not processed. For reasons why, and help fixing this, see http://sellercentral.amazon.it/gp/errorcode/13013</ResultDescription>
<AdditionalInfo>
<SKU>887235757035</SKU>
</AdditionalInfo>
</Result>
</ProcessingReport>
</Message>
but this sku exists in my catalog
The actual response is alway XML from MWS, where you can see that 50691017150 is actually your FeedSubmissionId.
When you submit a feed MWS gives you back with a FeedSubmissionId, by which you can track what happened to your feed.
If you go to MWS Scratchpad, you can get the feed result.
Enter the required credentials in Authentication form and select feed as Sezione AP and GetFeedSubmissionResult as Operation.
You will be than asked for FeedSubmissionId which you already have.
See what happened to that feed and why did it fail?
You are passing Marketplace Ids , which means that the sku is available there. But in your case it might not be available in any one of these. And MarketplaceId is optional, you can remove
$params['MarketplaceId.Id.1'] = $this->MARCKETPLACE_IT;
$params['MarketplaceId.Id.2'] = $this->MARCKETPLACE_UK;
$params['MarketplaceId.Id.3'] = $this->MARCKETPLACE_ES;
$params['MarketplaceId.Id.4'] = $this->MARCKETPLACE_DE;
$params['MarketplaceId.Id.5'] = $this->MARCKETPLACE_FR;
Related
I need to create payment module for opencart. The problem how to build xml output in php to post it to remote leasing server url: https://ecredit.leasing.com/eshop_test/UBLOnline.aspx?eshopdata=?
using post method.
I trying to build this xml:
<?xml version="1.0" encoding="UTF-8"?>
<ContractRequest xmlns="http://e-credit.ubl.lt/eshop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://e-credit.ubl.lt/eshop http://e-credit.leasing.com/eshop/contractrequest.xsd">
<SaleLogin>test</SaleLogin>
<SaleConditionID>111</SaleConditionID>
<Person>
<FirstName>John</FirstName>
<LastName>Jones</LastName>
</Person>
<Communication>
<StreetOrVillage>First</StreetOrVillage>
<City>New York</City>
<PostCode>21212</PostCode>
<Phone>+100000000</Phone>
<Email>john#mymail.com</Email>
</Communication>
<ContractDetails>
<CreditAmount>617.60</CreditAmount>
<CreditCurrency>USD</CreditCurrency>
</ContractDetails>
<OrderedItemsDetail>
<Item>
<Name>1 x HP 250 G5 UMA Celeron N3060 15.6 HD SVA, 1 x HP 15-r101na 15.6 HD Brightview flat (B), </Name>
<Amount>2pcs.</Amount>
<Price>617.60</Price>
<Currency>USD</Currency>
</Item>
</OrderedItemsDetail>
</ContractRequest>
I have tried create xml like this:
$XmlString = '<?xml version="1.0" encoding="UTF-8" ?>';
$XmlString .= '<ContractRequest
xmlns="http://e-credit.ubl.lt/eshop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://e-credit.ubl.com/eshop http://e-credit.leasing.com/eshop/contractrequest.xsd">';
$XmlString .= '<SaleLogin>' . $data['SaleLogin'] . '</SaleLogin>';
$XmlString .= '<SaleConditionID>' . $data['SaleConditionID'] . '</SaleConditionID>';
$XmlString .= '<Person>';
$XmlString .= '<FirstName>' . $data['first_name'] . '</FirstName>';
$XmlString .= '<LastName>' . $data['last_name'] . '</LastName>';
$XmlString .= '</Person>';
$XmlString .= '<Communication>';
$XmlString .= '<StreetOrVillage>' . $data['street'] . '</StreetOrVillage>';
$XmlString .= '<City>' . $data['city'] . '</City>';
$XmlString .= '<PostCode>' . $data['postcode'] . '</PostCode>';
$XmlString .= '<Phone>' . $data['telephone'] . '</Phone>';
$XmlString .= '<Email>' . $data['email'] . '</Email>';
$XmlString .= '</Communication>';
$XmlString .= '<ContractDetails>';
$XmlString .= '<CreditAmount>' . $data['amount'] . '</CreditAmount>';
$XmlString .= '<CreditCurrency>' . $data['currency'] . '</CreditCurrency>';
$XmlString .= '</ContractDetails>';
$XmlString .= '<OrderedItemsDetail>';
$XmlString .= '<Item>';
$XmlString .= '<Name>' . $data['description'] . '</Name>';
$XmlString .= '<Amount>' . $data['products_amount'] . '</Amount>';
$XmlString .= '<Price>' . $data['amount'] . '</Price>';
$XmlString .= '<Currency>' .$data['currency'] . '</Currency>';
$XmlString .= '</Item>';
$XmlString .= '</OrderedItemsDetail>';
$XmlString .= '</ContractRequest>';
and after :
$url = https://ecredit.leasing.com/eshop_test/UBLOnline.aspx?eshopdata=?;
$header = array();
$header[] = 'Content-Type: text/xml';
$header[] = 'Content-Length: ' . strlen($XmlString);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $XmlString);
///////////////////////
$response = curl_exec($ch);
curl_close($ch);
$XmlString = simplexml_load_string($response);
//create object to use as json
$json = array();
$json['redirect'] = $this->url->link('checkout/success', '', true);
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
but this does not work... sad.... what i miss?
how to create properly xml request and post it to url?
You already has some tips (and maybe your answer) in the comments, but here is some thoughts on what you should do to improve your code and also help others to help you.
PHP gives you some good resources to create XML, you should use them. I recommend DOMDocument. Below is a starter code to your example.
$dom = new DOMDocument('1.0', 'utf-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$namespace = 'http://e-credit.ubl.lt/eshop';
$contractRequest = $dom->createElement('ContractRequest');
$contractRequest->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', $namespace);
$saleLogin = $dom->createElement('SaleLogin', 'test');
$saleConditionID = $dom->createElement('SaleConditionID', '111');
$contractRequest->appendChild($saleLogin);
$contractRequest->appendChild($saleConditionID);
$dom->appendChild($contractRequest);
//you got the idea...
For the curl part, first change the first setopt to curl_setopt($ch, CURLOPT_URL, $url);. Now, before close your curl handle, insert the following code:
if($response === false)
{
echo 'Curl error: ' . curl_error($ch);
}
If it not work, you can debug your curl request. This another question may help you.
UPDATE
I think that the use of curl for your request is the right option, but, as you requested in the comment, here is an option if your curl request continues to fail.
$payload = array();
$payload['header'] = 'Content-Type: text/xml';
$payload['header'] .= 'Content-Length: ' . strlen($XmlString);
$payload['content'] = is_array($XmlString) ? http_build_query($XmlString) : $XmlString;
$payload['method'] = 'POST';
$payloadContext = stream_context_create(array('http' => $payload));
$result = file_get_contents($url, false, $payloadContext);
if ($result === false) {
print_r ("Error in your request. Check logs for more information");
}
As I said, its just an option, but curl remains a good one, you just need to correct it.
My XML to be parsed is in this format:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header />
<env:Body>
<n0:ZFM_PAYSLIP1Response xmlns:n0="urn:sap-com:document:sap:rfc:functions">
<LS_EMP_PAYSLIP_DATA>
<ZEMP_NO>00199999</ZEMP_NO>
<ZEMP_NAME>AJ KUMAR</ZEMP_NAME>
<ZSAL_MONTH>JUL-2016</ZSAL_MONTH>
<ZBASIC_PAY>57240.0</ZBASIC_PAY>
<ZGROSS_PAY>145062.29</ZGROSS_PAY>
<ZNET_PAY>50728.0</ZNET_PAY>
<ZINCOME_TAX>25858.0</ZINCOME_TAX>
<ZLEAVE_ENCASH>0.0</ZLEAVE_ENCASH>
<ZDUTY_PAY>41976.0</ZDUTY_PAY>
<ZDA>56950.4</ZDA>
<ZPERKS>26330.4</ZPERKS>
<ZHRA>11448.0</ZHRA>
<ZTOT_DEDUCTIONS>94334.29</ZTOT_DEDUCTIONS>
<ZCPF>12787.0</ZCPF>
<ZVPF>50000.0</ZVPF>
<ZLIC>0.0</ZLIC>
<ZTHRIFT_FUND>0.0</ZTHRIFT_FUND>
<ZGRP_INS>160.0</ZGRP_INS>
<ZPROF_TAX>200.0</ZPROF_TAX>
<ZDUTY_DAYS>18</ZDUTY_DAYS>
<ZWEEK_OFF>4</ZWEEK_OFF>
<ZFL />
<ZCL />
<ZEL />
<ZFPL />
<ZHPL>8</ZHPL>
<ZCML />
<ZEOL />
<ZUAB />
<ZDEISGNATION>Sr.Manager(IT)</ZDEISGNATION>
<ZDEPT_CODE>03007900</ZDEPT_CODE>
<ZCL_BAL>3</ZCL_BAL>
<ZEL_BAL>270.5</ZEL_BAL>
<ZHPL_BAL>180</ZHPL_BAL>
</LS_EMP_PAYSLIP_DATA>
</n0:ZFM_PAYSLIP1Response>
</env:Body> </env:Envelope>
I am using PHP curl to get data from remote with
this PHP code :
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://hostanme.tld/ERP_PAY_XML.xml');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//echo $result;
curl_close($ch);
$xml = simplexml_load_string($result);
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['env']);
echo "<br> len-soap : " . $soap;
$getaddressresponse = $soap->Body->children($ns['n0']);
foreach ($getaddressresponse->getLocationForGroupResponse->children($ns['n0']) as $item)
{
$item = $item->children();
echo $item->address . '<br />';
}
?>
but still I am not getting any result. Anybody please help..
Is there any other way to parse XML to an object..
I am using amazon api for update product's quantity using "_POST_INVENTORY_AVAILABILITY_DATA_" feedtype like,
<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>$merchantID</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>$SKU</SKU>
<Quantity>8</Quantity>
</Inventory>
</Message>
</AmazonEnvelope>
<?xml version="1.0"?>
<SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
<SubmitFeedResult>
<FeedSubmissionInfo>
<FeedSubmissionId>6791310806</FeedSubmissionId>
<FeedType>_POST_INVENTORY_AVAILABILITY_DATA_</FeedType>
<SubmittedDate>2013-03-21T19:48:37+00:00</SubmittedDate>
<FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus>
</FeedSubmissionInfo>
</SubmitFeedResult>
<ResponseMetadata>
<RequestId>fd07bf18-4f6a-4786-bdf9-9d4db50956d0</RequestId>
</ResponseMetadata>
</SubmitFeedResponse>
but when i try to update 15k or more products at a time by loading products using magento collection quantity not updating in amazon after few hours also. Is it right method or do i need to use any other method?
Can anyone help me?
Thanks in advance.
Try Using _POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_ feedtype and send a CSV file (tab delimited) in the body of the https request instead of an XML file. The first line of the csv should be: sku price quantity (separated by tabs) followed by lines containing the values (separated by tabs).
Quoting Amazon MWS API:
Feed size is limited to 2,147,483,647 bytes (2^31 -1) per feed. If you
have a large amount of data to submit, you should submit feeds smaller
than the feed size limit by breaking up the data, or submit the feeds
over a period of time. One good practice is to submit feeds with a
size limit of 30,000 records/items or submit feeds over a period of
time, such as every few hours.
$feed = '<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>AG7AH5X9UOHEC</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>UK-BBD10002</SKU>
<Quantity>4</Quantity>
<FulfillmentLatency>15</FulfillmentLatency>
</Inventory>
</Message>
<Message>
<MessageID>2</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>UK-BBD10003</SKU>
<Quantity>6</Quantity>
<FulfillmentLatency>14</FulfillmentLatency>
</Inventory>
</Message>
</AmazonEnvelope>';
$feedHandle = #fopen('php://temp', 'rw+');
fwrite($feedHandle, $feed);
rewind($feedHandle);
$param['AWSAccessKeyId'] = Configure::read('AWS_ACCESS_KEY');
$param['Action'] = 'SubmitFeed';
$param['SellerId'] = Configure::read('SELLER_ID');
$param['SignatureMethod'] = Configure::read('SIGNATURE_METHOD');
$param['SignatureVersion'] = Configure::read('SIGNATURE_VERSION');
$param['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version'] = '2009-01-01';
$param['FeedType'] = $FeedType;
$param['FeedContent'] = stream_get_contents($feedHandle);
$param['ContentMd5'] = base64_encode(md5(stream_get_contents($feedHandle), true));
$param['MarketplaceIdList.Id.1'] = $MARKETPLACE_ID; //FR
//$param['MarketplaceIdList.Id.2'] = 'A1F83G8C2ARO7P'; //GB
ksort($param);
$MARKETPLACE_URL = 'mws.amazonservices.co.uk';
$secret = Configure::read('SECRET_KEY');
$url = array();
foreach ($param as $key => $val) {
$key = str_replace("%7E", "~", rawurlencode($key));
$val = str_replace("%7E", "~", rawurlencode($val));
$url[] = "{$key}={$val}";
}
ksort($url);
$arr = implode('&', $url);
$sign = 'GET' . "\n";
$sign .= ''.$MARKETPLACE_URL.'' . "\n";
$sign .= '/Feeds/2009-01-01' . "\n";
$sign .= $arr;
$signature = hash_hmac("sha256", $sign, $secret, true);
$signature = urlencode(base64_encode($signature));
$link = "https://".$MARKETPLACE_URL."/Feeds/2009-01-01?";
$link .= $arr . "&Signature=" . $signature;
$httpHeader = array();
$httpHeader[] = 'Content-Type: application/xml';
$httpHeader[] = 'Content-MD5: ' . base64_encode(md5(stream_get_contents($feedHandle), true));
$httpHeader[] = 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'];
$httpHeader[] = 'Host: ' . $MARKETPLACE_URL;
ksort($httpHeader);
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
#fclose($feedHandle);
print_r($response);
exit;
I'm tring to process xml (website) into php array.
I have tried the following code which works for everyting in results but i need to get the totalpage which i'm not able to see how I can do this.
function get_content($url)
/// basically opens the page and stores it as a variable. Buggered if I know how it works!
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
$string = NULL;
$ch = NULL;
$url = NULL;
}
$url = "url";
$content = get_content($url);
$content_x = explode("<result>", $content);
foreach ($content_x as $item)
{
$p1 = strpos($item, '<title>');
$p2 = strpos($item, '</title>');
$l1 = $p2 - $p1;
echo '<br>'.$title = substr($item, $p1, $l1);
}
xml site feed
<?xml version="1.0" encoding="UTF-8"?>
<response version="2">
<totalpage>1005</totalpage>
<results>
<result>
<title>test</title>
<title2>test2</title2>
<title3>test3</title3>
<result>
<result>
<title>test</title>
<title2>test2</title2>
<title3>test3</title3>
<result>
<result>
<title>test</title>
<title2>test2</title2>
<title3>test3</title3>
<result>
........so on
<results>
</response>
I need to get totalpage and everyting in results
How do get totalpage and is they better way to process the results
You absolutely should not be using string manipulation to try to parse XML. There are any number of PHP libraries that can do this. I might recommend SimpleXML.
Usage would be:
$xml = simplexml_load_string($content);
$totalpage = $xml->response->totalpage;
I have a php function that communicates with UPS using curl, xml.The script was given to me and i dont know much about it.
It works in every browser except IE9
The function returns something like this:
HTTP/1.1 200 OK Date: Tue, 06 Dec 2011 21:36:41 GMT Server: Apache
Pragma: no-cache Content-Length: 1481 X-Powered-By: Servlet/2.5
JSP/2.1 Vary: User-Agent Content-Type: application/xml
it goes on to show all the responses
from ups in xml
here is the function with the curl and xml parameters.
function ups($dest_zip,$service,$weight,$length,$width,$height) {
// This script was written by Mark Sanborn at http://www.marksanborn.net
// If this script benefits you are your business please consider a donation
// You can donate at http://www.marksanborn.net/donate.
// ========== CHANGE THESE VALUES TO MATCH YOUR OWN ===========
$AccessLicenseNumber = '000000009F002AC0'; // Your license number <br>
$UserId = '+++++'; // Username <br>
$Password = '+++++'; // Password <br>
$PostalCode = '01862'; // Zipcode you are shipping FROM <br>
$ShipperNumber = '++++'; // Your UPS shipper number <br>
// =============== DON'T CHANGE BELOW THIS LINE ===============
$data ="<?xml version=\"1.0\"?>
<AccessRequest xml:lang=\"en-US\">
<AccessLicenseNumber>$AccessLicenseNumber</AccessLicenseNumber>
<UserId>$UserId</UserId>
<Password>$Password</Password>
</AccessRequest>
<?xml version=\"1.0\"?>
<RatingServiceSelectionRequest xml:lang=\"en-US\">
<Request>
<TransactionReference>
<CustomerContext>Bare Bones Rate Request</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>Rate</RequestAction>
<RequestOption>Rate</RequestOption>
</Request>
<PickupType>
<Code>01</Code>
</PickupType>
<Shipment>
<Shipper>
<Address>
<PostalCode>$PostalCode</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<ShipperNumber>$ShipperNumber</ShipperNumber>
</Shipper>
<ShipTo>
<Address>
<PostalCode>$dest_zip</PostalCode>
<CountryCode>US</CountryCode>
<ResidentialAddressIndicator/>
</Address>
</ShipTo>
<ShipFrom>
<Address>
<PostalCode>$PostalCode</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>$service</Code>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
</PackagingType>
<Dimensions>
<UnitOfMeasurement>
<Code>IN</Code>
</UnitOfMeasurement>
<Length>$length</Length>
<Width>$width</Width>
<Height>$height</Height>
</Dimensions>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>$weight</Weight>
</PackageWeight>
</Package>
</Shipment>
</RatingServiceSelectionRequest>";
$ch = curl_init("https://www.ups.com/ups.app/xml/Rate");
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POST,0);
curl_setopt($ch,CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result=curl_exec ($ch);
echo '<!-- '. $result. ' -->'; // THIS LINE IS FOR DEBUG PURPOSES ONLY-IT WILL SHOW IN HTML COMMENTS
$data = strstr($result, '<?');
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
//$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
if (isset($xml_elem['value'])) {
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
}
else {
$php_stmt .= '[$xml_elem[\'tag\']] = "";';
}
eval($php_stmt);
}
}
curl_close($ch);
return $params['RATINGSERVICESELECTIONRESPONSE']['RATEDSHIPMENT']['TOTALCHARGES']['MONETARYVALUE'];
}
The page will not render the HTML
I have no clue what I am doing. HELP!
Double check that the output of headers hasn't been enabled
curl_setopt($curl_handle, CURLOPT_HEADER,1);
Comment out that line or set it to false.