Jump to content

How to select a transaction of an array and check it on regular basis


oskare100

Recommended Posts

Hello,
I know that this is maybe a bit complicated but I thought I could take a chance and see if someone had time to read it trough. I need help with the whole script but the main thing is [B]How to select just one transaction of all transactions ebay is returning (see the code sample, in the end of it)[/B]. I'm working on a script that will be able to "GetFeedback" to see if a user has left positive feedback and then "LeaveFeedback" positive if the feedback left was positive. Everything is built on XML, here is the functions described at ebay;

[url=http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/io_GetFeedback.html]http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/io_GetFeedback.html[/url]
[url=http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/io_LeaveFeedback.html]http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/io_LeaveFeedback.html[/url]

Unfortunately there are not many code samples at Ebay (but all codes looks the same because it is just send and receive with different variables). Below is the sample code for searching, but I've tried to edit it and it also works the same for all other Ebay API functions. So when I request "GetFeedback" the script returns the variables in that function instead and my script creates an array with the the feedback I've received and (because I don't know how to make it do anything else) creates a table in HTML with all those iteams.

[B]I need to "select" a feedback[/B]. Then I need to get all the information about it and assignt PHP variables to them as for example $transaction_id_awaiting for the transaction id, $user_id_awaiting for the user id of that transaction and so on. Because then I need those variables to be able to use the "LeaveFeedback" function to leave feedback for that transaction/user.

Another thing is that the script can't select the same feedback/transaction from "GetFeedback" all the time because then script would loop to the next feedback is left. It should only select feedbacks/transactions that the script already hasn't left feedback for. Maybe I could store the for example 30 latest feedbacks that has been answered in a table in my database, only make Ebay return the 30 latest feedbacks left for me and then fist check the table before leaving feedbacks?

Here is the code sample;
[code=php:0]<?php
if(isset($_POST['Query']))
{
//Get the query entered
$query = $_POST['Query'];


//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 = 'GetSearchResults';
//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);

///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8">';
$requestXmlBody .= '<GetSearchResultsRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
$requestXmlBody .= "<Query>$query</Query>";
$requestXmlBody .= '</GetSearchResultsRequest>';

$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 rrror 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
$itemNodes = $responseDoc->get_elements_by_tagname('Item');

//see if there are any results
if(count($itemNodes) > 0)
{
?>
<TABLE cellpadding="6" cellspacing="0" border="0">
<TR bgcolor="#BBBBBB">
<TD><B>Id</B></TD>
<TD><B>Title</B></TD>
<TD><B>Price</B></TD>
<TD><B>Started</B></TD>
<TD><B>Ends</B></TD>
</TR>
<?php
//stores the alternationg background colour of the rows
$bgColor = "#FFFFFF";
//go through each result
foreach($itemNodes as $item)
{
//get the required nodes from the results
$itemID = $item->get_elements_by_tagname('ItemID');
$title = $item->get_elements_by_tagname('Title');
$price = $item->get_elements_by_tagname('CurrentPrice');
$startTime = $item->get_elements_by_tagname('StartTime');
$endTime = $item->get_elements_by_tagname('EndTime');
$link = $item->get_elements_by_tagname('ViewItemURL');
//display the result in a table row
?>
<TR bgcolor="<?php echo $bgColor ?>">
<TD><?php echo $itemID[0]->get_content(); ?></TD>
<!-- Display the Title as a link to the item on eBay -->
<TD><A href="<?php echo $link[0]->get_content(); ?>" target="_blank">
<?php echo $title[2]->get_content(); ?>
</A>
</TD>
<TD><?php echo $price[0]->get_content(); ?></TD>
<TD><?php echo $startTime[0]->get_content(); ?> GMT</TD>
<TD><?php echo $endTime[0]->get_content(); ?> GMT</TD>
</TR>
<?php
//alternate the background colours
$bgColor = $bgColor == "#FFFFFF" ? "#EEEEEE" : "#FFFFFF";
} ?>
</TABLE>
<?php
}
else
{
echo '<P><B>No items found</B>';
}
}
}
?>[/code]

/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.