Jump to content

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


oskare100

Recommended Posts

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   
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(">", ">", str_replace("<", "<", $shortMsg[0]->get_content()));
        //if there is a long message (ie ErrorLevel=1), display it
        if(count($longMsg) > 0)
            echo '<BR>', str_replace(">", ">", str_replace("<", "<", $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: http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/io_GetItemTransactions.html .

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.