ebay api php

Posted on 2009-12-21
Last Modified: 2012-05-08
does this file have to be run to gather ebay orders

ebay orders get imported into the database but not sure how because only get 1-3 ebay orders a day

how does ebay know about this php file
Question by:rgb192
    LVL 8

    Accepted Solution

    does this file have to be run to gather ebay orders -- which file??

    Author Comment

    // This File contains the OWeBAy class which makes and parses all of the ebay requests. And it contains eBayTitle which manages the ebay title table.
    class OWeBay {
        public function __construct($requester,$siteID) {
            $this->requester    = $requester;
            $this->siteID    = $siteID;
            //, false, 517, $this->siteID, $verb
            //Application Specfic Developer tokens
            $this->devID    = '';
            $this->appID    = '';
            $this->certID    = '';
            //the token representing the eBay user to assign the call with -- All eBay Users in use on the system
            $this->token = $this->getToken($this->requester);
        //Request Functions
        public function AddMemberMessageAAQToPartnerRequest($ItemID, $RecipientID, $Message) {
            //Format the strings for XML Input
            $ItemID = $this->cleanXML($ItemID);
            $RecipientID = $this->cleanXML($RecipientID);
            $Message = $this->cleanXML($Message);
            ///Build the request Xml string
            $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
            $requestXmlBody .= '<AddMemberMessageAAQToPartnerRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
            $requestXmlBody .= "<RequesterCredentials><eBayAuthToken></eBayAuthToken></RequesterCredentials>";
            //Request Specific XML
            $requestXmlBody .= "<ItemID>$ItemID</ItemID>";
            $requestXmlBody .= "<MemberMessage>";
            $requestXmlBody .= "<Body>$Message</Body>";
            $requestXmlBody .= "<EmailCopyToSender>true</EmailCopyToSender>";
            $requestXmlBody .= "<HideSendersEmailAddress>false</HideSendersEmailAddress>";
            $requestXmlBody .= "<QuestionType>Payment</QuestionType>";
            $requestXmlBody .= "<RecipientID>$RecipientID</RecipientID>";
            $requestXmlBody .= "</MemberMessage>";
            $requestXmlBody .= "</AddMemberMessageAAQToPartnerRequest>";
            $requestXmlBody = utf8_encode($requestXmlBody);
            return $this->eBayRequest($requestXmlBody , 'AddMemberMessageAAQToPartner');
        public function GetSellerTransactionsRequest() {
            $date = new DateTime(date('c'));
            $date->modify("-2 hours");
            $start = $date->format("c");
            $date1log = $date->format("m/d/Y");
            $date->modify("+3 hours");
            $end = $date->format("c");
            $date2log = $date->format("m/d/Y");    
            ///Build the request Xml string
            $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
            $requestXmlBody .= '<GetSellerTransactionsRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
            $requestXmlBody .= "<RequesterCredentials><eBayAuthToken></eBayAuthToken></RequesterCredentials>";
            //Request Specific XML
            $requestXmlBody .= "<DetailLevel>ReturnAll</DetailLevel>";
            $requestXmlBody .= "<ModTimeFrom>$start</ModTimeFrom>";
            $requestXmlBody .= "<ModTimeTo>$end</ModTimeTo>";
            $requestXmlBody .= "<IncludeContainingOrder>True</IncludeContainingOrder>";
            $requestXmlBody .= "</GetSellerTransactionsRequest>";
            return $this->eBayRequest($requestXmlBody , 'GetSellerTransactions');
        public function eBayRequest($requestXmlBody, $verb) {
            //set the Server to use (Sandbox or Production)
            $serverUrl = '';
            //Fix up $requestXmlBody
            $RequesterCredentials = '<RequesterCredentials><eBayAuthToken>' . $this->token . '</eBayAuthToken></RequesterCredentials>';
            $requestXmlBody = str_replace("<RequesterCredentials><eBayAuthToken></eBayAuthToken></RequesterCredentials>", $RequesterCredentials, $requestXmlBody);
            $session = new eBaySession($this->token, $this->devID, $this->appID, $this->certID, false, "517", $this->siteID, $verb);
            $responseXml = $session->sendHttpRequest($requestXmlBody);
            if(stristr($responseXml, 'HTTP 404') || $responseXml == '')
                die('<P>Error sending request');
            //Xml string is parsed and creates a DOM Document object
            $responseDoc = new DomDocument();
            //echo '<textarea>' . $responseXml . '</textarea>';
            //get any error nodes
            $errors = $responseDoc->getElementsByTagName('Errors');
            //if there are error nodes
            if($errors->length > 0) {
                echo '<P><B>eBay returned the following error(s):</B>';
                //display each error
                //Get error code, ShortMesaage and LongMessage
                $code = $errors->item(0)->getElementsByTagName('ErrorCode');
                $shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
                $longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
                //Display code and shortmessage
                echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));
                //if there is a long message (ie ErrorLevel=1), display it
                if(count($longMsg) > 0)
                    echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));
                return 0;
                echo '<br><br><br>
                echo $requestXmlBody . '<br><br>';
            else {
                return $responseDoc;
        } //End eBayRequest Function Definition
        //Helper Functions    
        public function getToken($requester) {
            //which username is making the request        
            switch ($requester) {
                case 'ebayname':
                    return 'token';
                    return 'token';
        public function cleanXML($var) {
            $var = str_replace("&", "&amp;", $var);
            $var = str_replace("'", "&apos;", $var);
            $var = str_replace("\"", "&quot;", $var);
            return $var;
    class eBaySession
        private $requestToken;
        private $devID;
        private $appID;
        private $certID;
        private $serverUrl;
        private $compatLevel;
        private $siteID;
        private $verb;
        /**    __construct
            Constructor to make a new instance of eBaySession with the details needed to make a call
            Input:    $userRequestToken - the authentication token fir the user making the call
                    $developerID - Developer key obtained when registered at
                    $applicationID - Application key obtained when registered at
                    $certificateID - Certificate key obtained when registered at
                    $useTestServer - Boolean, if true then Sandbox server is used, otherwise production server is used
                    $compatabilityLevel - API version this is compatable with
                    $siteToUseID - the Id of the eBay site to associate the call iwht (0 = US, 2 = Canada, 3 = UK, ...)
                    $callName  - The name of the call being made (e.g. 'GeteBayOfficialTime')
            Output:    Response string returned by the server
        public function __construct($userRequestToken, $developerID, $applicationID, $certificateID, $useTestServer,
                                    $compatabilityLevel, $siteToUseID, $callName)
            $this->requestToken = $userRequestToken;
            $this->devID = $developerID;
            $this->appID = $applicationID;
            $this->certID = $certificateID;
            $this->compatLevel = $compatabilityLevel;
            $this->siteID = $siteToUseID;
            $this->verb = $callName;
                $this->serverUrl = '';
                $this->serverUrl = '';
        /**    sendHttpRequest
            Sends a HTTP request to the server for this session
            Input:    $requestBody
            Output:    The HTTP Response as a String
        public function sendHttpRequest($requestBody)  
            // ----->> Configuring the User Agent to FireFox 2.0 <<---------
            $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061204 Firefox/"; 
            //build eBay headers using variables passed via constructor  
            $headers = $this->buildEbayHeaders();  
            //initialise a CURL session  
            $connection = curl_init();  
            // set user agent 
            curl_setopt($connection, CURLOPT_USERAGENT, $useragent); 
            //------>> set the server we are using (could be Sandbox or Production server) <<-------  
            curl_setopt($connection, CURLOPT_URL, $this->serverUrl);  
            //stop CURL from verifying the peer's certificate  
            curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);  
            curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);  
            //set the headers using the array of headers  
            curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);  
            //set method as POST  
            curl_setopt($connection, CURLOPT_POST, 1);  
            //set the XML body of the request  
            curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);  
            //set it to return the transfer as a string from curl_exec  
            curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);  
            //Send the Request  
            $response = curl_exec($connection);  
            //close the connection  
            //return the response  
            return $response;  
        /**    buildEbayHeaders
            Generates an array of string to be used as the headers for the HTTP request to eBay
            Output:    String Array of Headers applicable for this call
        private function buildEbayHeaders()
            $headers = array (
                //Regulates versioning of the XML interface for the API
                'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $this->compatLevel,
                //set the keys
                'X-EBAY-API-DEV-NAME: ' . $this->devID,
                'X-EBAY-API-APP-NAME: ' . $this->appID,
                'X-EBAY-API-CERT-NAME: ' . $this->certID,
                //the name of the call we are requesting
                'X-EBAY-API-CALL-NAME: ' . $this->verb,            
                //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
                'X-EBAY-API-SITEID: ' . $this->siteID,
            return $headers;
    class eBayTitle {
        public function __construct($title) {
            $this->title    = $title;
        public function checkExistance() {
            $sql = "SELECT COUNT(title) FROM ebaytitles WHERE title = '$this->title'";
            if(dbfetch($sql) == '0') {
                return false;
            else {
                return true;
        public function saveTite($type, $id) {
            $sql = "INSERT INTO ebaytitles (title, type, id) VALUES ('$this->title','$type','$id')";

    Open in new window


    Author Closing Comment

    yes file gathers orders

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now