Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with small PHP XML API problem fast! Please help! Can eventu

Status
Not open for further replies.

oskare100

Technical User
Mar 25, 2005
16
SE
Hello,
I'm currently using this page to get information about the buyers email, Ebay status and the Ebay transaction ID of a transaction at Ebay. The problem is that I also need to get some more information from the XML reply, but I don't know how to do it.

Here is the page:
PHP:
<?php   
if ($_POST['itemid'] == ""){

    print "<form name='form1' method='post' action='GetItemTransactionss.php'>";
    print "<input name='itemid' type='text' id='itemid'>";
    print "<input name='userid' type='text' id='userid'>";
    print "<input type='submit' name='Submit0' value='Post'>";
}
else { 
include('functions.php');
include('variables.php');
error_reporting(E_ALL);
ini_set('display_errors', '1');
    //SiteID must also be set in the Request's XML
    //SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
    //SiteID Indicates the eBay site to associate the call with
    $siteID = 0;
    //the call being made:
    $verb = 'GetItemTransactions';
    //Regulates versioning of the XML interface for the API
    $compatabilityLevel = 433;

    //get an array of strings containing the required headers
    $headers = buildEbayHeaders($devID, $appID, $certID, $compatabilityLevel, $siteID, $verb);
    
    $item_number=$_POST['itemid'];
    $user_id=$_POST['userid'];

    // Time from and time to
    $time_from = date('Y-m-d\TH:i:s',strtotime("-28 days")).'.799Z';
    $time_to = date('Y-m-d\TH:i:s',strtotime("+1 days")).'.799Z';
    
    ///Build the request Xml string
    $requestXmlBody = '<?xml version="1.0" encoding="utf-8"?>';
    $requestXmlBody .= '<GetItemTransactionsRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
    $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
    $requestXmlBody .= "<ItemID>$item_number</ItemID>";
    $requestXmlBody .= "<ModTimeFrom>$time_from</ModTimeFrom>";
    $requestXmlBody .= "<ModTimeTo>$time_to</ModTimeTo>";
    $requestXmlBody .= '</GetItemTransactionsRequest>';
    
    $responseXml = sendHttpRequest($requestXmlBody, $serverUrl, $headers);
    if(stristr($responseXml, 'HTTP 404') || $responseXml == '')
        die('<P>Error sending request');
    
    //Xml string is parsed and creates a DOM Document object
    $responseDoc = domxml_open_mem($responseXml);
    
    //get any error nodes
    $errors = $responseDoc->get_elements_by_tagname('Errors');
    
    //if there are error nodes
    if(count($errors) > 0)
    {
        echo '<P><B>eBay returned the following error(s):</B>';
        //display each error
        //Get error code, ShortMesaage and LongMessage
        $code = $errors[0]->get_elements_by_tagname('ErrorCode');
        $shortMsg = $errors[0]->get_elements_by_tagname('ShortMessage');
        $longMsg = $errors[0]->get_elements_by_tagname('LongMessage');
        //Display code and shortmessage
        echo '<P>', $code[0]->get_content(), ' : ', str_replace(">", "&gt;", str_replace("<", "&lt;", $shortMsg[0]->get_content()));
        //if there is a long message (ie ErrorLevel=1), display it
        if(count($longMsg) > 0)
            echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg[0]->get_content()));

    }
    else //no errors
    {
     //get results nodes
$transactionNodes = $responseDoc->get_elements_by_tagname('Transaction');
    
$transaction_id=-1;
foreach ($transactionNodes as $key=>$node){
  $buyer=$node->get_elements_by_tagname("Buyer");
  $userid=$buyer[0]->get_elements_by_tagname("UserID");
  if($userid[0]->get_content()==$user_id) $transaction_id=$key;
}

if($transaction_id!=-1){
  $transaction=$transactionNodes[$transaction_id]->get_elements_by_tagname("TransactionID");
  $ebay_transaction_id = $transaction[0]->get_content();

  $ebaystatus=$transactionNodes[$transaction_id]->get_elements_by_tagname("Status");
  $ebay_status = $ebaystatus[0]->get_content();
  
  $ebayemail=$transactionNodes[$transaction_id]->get_elements_by_tagname("Email");
  $ebay_email = $ebayemail[0]->get_content();
  
  echo "$ebay_transaction_id";
  echo "$ebay_status";
  echo "$ebay_email";
  
} 

    }
    }
?>

Here is the structure of the reply from Ebay: .

I need to be able to get information from different places of the transaction part of the XML reponse, not just from "buyer" as for example I need to get <ExternalTransactionID> from <ExternalTransaction> and the <PaidTime> and similar from that <transaction> with that <UserID> . So I can be able to use the different levels, as for example to get TransactionArray.Transaction.Buyer.BuyerInfo.ShippingAddress.Name for that user and transaction.

I've tried for several hours now to get this to work, so please, help me! If you PM your Paypal email I'll also leave compensation for your time if it works - I really need this to work.

Thanks in advance,
/Oskar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top