{"id":33,"date":"2021-02-13T03:18:53","date_gmt":"2021-02-13T03:18:53","guid":{"rendered":"https:\/\/jonrocket.com\/zencart\/?p=33"},"modified":"2021-02-13T17:46:39","modified_gmt":"2021-02-13T17:46:39","slug":"under-the-hood-the-ebay-api","status":"publish","type":"post","link":"https:\/\/jonrocket.com\/zencart\/2021\/02\/13\/under-the-hood-the-ebay-api\/","title":{"rendered":"eBay Integration &#8211; the eBay API"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"497\" src=\"https:\/\/jonrocket.com\/zencart\/wp-content\/uploads\/2021\/02\/ebay-api.png\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/jonrocket.com\/zencart\/wp-content\/uploads\/2021\/02\/ebay-api.png 606w, https:\/\/jonrocket.com\/zencart\/wp-content\/uploads\/2021\/02\/ebay-api-300x246.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\n\n\n\n<p>Integration with eBay is made possible by the <a href=\"https:\/\/developer.ebay.com\/\">eBay Application Program Interface (API)<\/a> which is a collection of services that expose methods that can be called from your server to access information and to define notifications to be sent by eBay to your server.<\/p>\n\n\n\n<p>What this means is that the eBay Integration plug-in for Zen Cart, running on your server, can access your account data at eBay. It can create listings, get notified of orders, update listings, and more.  <\/p>\n\n\n\n<p>In order to do all these neat things, the plug-in has to get permission to access the API and your data.  The plug-in accesses the API by making <a href=\"https:\/\/developer.ebay.com\/api-docs\/static\/ebay-rest-landing.html\">RESTfull calls<\/a> to eBay&#8217;s servers using the same <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP protocol<\/a> that your browser uses to get a web page from a web site or submit a form to it.<\/p>\n\n\n\n<p>In order to use the API, the plug-in needs permission to access it. eBay uses three identifiers as keys &#8211; sort like a user ID and password &#8211; to let your plug-in call the API methods.  The keys are assigned to your application (the plug-in).  To create the keys, you have to <a href=\"https:\/\/developer.ebay.com\/DevZone\/guides\/features-guide\/content\/basics\/Call-DevelopmentKeys.html\">create an account at eBay&#8217;s Developer web site and register your application<\/a>.<\/p>\n\n\n\n<p>The keys give the plug-in permission to call the eBay API methods, but only to get public information.  To get access to your eBay account information, the plug-in needs to get a <a href=\"https:\/\/developer.ebay.com\/DevZone\/guides\/features-guide\/content\/basics\/Tokens.html\">security token<\/a>.<\/p>\n\n\n\n<p>The security token grants permission to the plug-in allowing it to access the account information that it needs.<\/p>\n\n\n\n<p>To talk to the eBay API, the plug-in uses a slightly-updated version of a <a href=\"https:\/\/www.php.net\/manual\/en\/intro-whatis.php\">PHP<\/a> class written by eBay. The <strong>eBaySessionHandler <\/strong>class  (called just <strong><a href=\"https:\/\/developer.ebay.com\/devzone\/xml\/docs\/howto\/PHP_PlaceOfferGS\/PHP_PlaceOfferGS_TradingShopping.html\">eBaySession<\/a><\/strong> by eBay) encapsulates the code for sending a request to an eBay server and receiving the response.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/**\n *  eBay's PHP code for making API calls\n *\/<\/span>\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">eBaySessionHandler<\/span>\n <\/span>{\n  <span class=\"hljs-keyword\">var<\/span> $devID;\n  <span class=\"hljs-keyword\">var<\/span> $appID;\n  <span class=\"hljs-keyword\">var<\/span> $certID;\n  <span class=\"hljs-keyword\">var<\/span> $serverUrl;\n  <span class=\"hljs-keyword\">var<\/span> $compatLevel;\n  <span class=\"hljs-keyword\">var<\/span> $siteID;\n  <span class=\"hljs-keyword\">var<\/span> $verb;\n\n  <span class=\"hljs-comment\">\/**\n   * __construct\n   * Constructor to make a new instance of eBaySessionHandler with the details needed to make a call\n   * Note that authentication credentials (normally token, but could be username and password)\n   * are assumed to come in the request body, and not in the constructor args\n   * Input: $developerID - Developer key obtained when registered at http:\/\/developer.ebay.com\n   * $applicationID - Application key obtained when registered at http:\/\/developer.ebay.com\n   * $certificateID - Certificate key obtained when registered at http:\/\/developer.ebay.com\n   * $severUrl - URL of the server to use\n   * $compatabilityLevel - API version this is compatable with\n   * $siteToUseID - the Id of the eBay site to associate the call iwht (0 = US, 2 = Canada, 3 = UK, ...)\n   * $callName - The name of the call being made (e.g. 'GeteBayOfficialTime')\n   * Output: Response string returned by the server\n   *\/<\/span>\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">__construct<\/span><span class=\"hljs-params\">($developerID, $applicationID, $certificateID, $serverUrl, $compatabilityLevel, $siteToUseID, $callName)<\/span>\n   <\/span>{\n    <span class=\"hljs-comment\">\/\/ $this-&gt;requestToken = $userRequestToken;<\/span>\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;devID = $developerID;\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;appID = $applicationID;\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;certID = $certificateID;\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;compatLevel = $compatabilityLevel;\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;siteID = $siteToUseID;\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;verb = $callName;\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;serverUrl = $serverUrl;\n   }\n\n  <span class=\"hljs-comment\">\/**\n   * sendHttpRequest\n   * Sends a HTTP request to the server for this session\n   * Input: $requestBody\n   * Output: The HTTP Response as a String\n   *\/<\/span>\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">sendHttpRequest<\/span><span class=\"hljs-params\">($requestBody)<\/span>\n   <\/span>{\n    <span class=\"hljs-comment\">\/\/ build eBay headers using variables passed via constructor<\/span>\n    $headers = <span class=\"hljs-keyword\">$this<\/span>-&gt;buildEbayHeaders ();\n\n    <span class=\"hljs-comment\">\/\/ initialise a CURL session<\/span>\n    $connection = curl_init ();\n    <span class=\"hljs-comment\">\/\/ set the server we are using (could be Sandbox or Production server)<\/span>\n    curl_setopt ( $connection, CURLOPT_URL, <span class=\"hljs-keyword\">$this<\/span>-&gt;serverUrl );\n\n    curl_setopt ( $connection, CURLOPT_TIMEOUT, <span class=\"hljs-number\">30<\/span> );\n\n    <span class=\"hljs-comment\">\/\/ stop CURL from verifying the peer's certificate<\/span>\n    curl_setopt ( $connection, CURLOPT_SSL_VERIFYPEER, <span class=\"hljs-number\">0<\/span> );\n    curl_setopt ( $connection, CURLOPT_SSL_VERIFYHOST, <span class=\"hljs-number\">0<\/span> );\n\n    <span class=\"hljs-comment\">\/\/ curl_setopt($connection, CURLOPT_HEADER, 1 ); \/\/ Uncomment these for debugging<\/span>\n    <span class=\"hljs-comment\">\/\/ curl_setopt($connection, CURLOPT_VERBOSE, true); \/\/ Display communication with serve<\/span>\n\n    curl_setopt ( $connection, CURLOPT_TIMEOUT, <span class=\"hljs-number\">360<\/span> );\n\n    <span class=\"hljs-comment\">\/\/ set the headers using the array of headers<\/span>\n    curl_setopt ( $connection, CURLOPT_HTTPHEADER, $headers );\n\n    <span class=\"hljs-comment\">\/\/ set method as POST<\/span>\n    curl_setopt ( $connection, CURLOPT_POST, <span class=\"hljs-number\">1<\/span> );\n\n    <span class=\"hljs-comment\">\/\/ set the XML body of the request<\/span>\n    curl_setopt ( $connection, CURLOPT_POSTFIELDS, $requestBody );\n\n    <span class=\"hljs-comment\">\/\/ set it to return the transfer as a string from curl_exec<\/span>\n    curl_setopt ( $connection, CURLOPT_RETURNTRANSFER, <span class=\"hljs-number\">1<\/span> );\n\n    <span class=\"hljs-comment\">\/\/ Send the Request<\/span>\n    $response = curl_exec ( $connection );\n\n    <span class=\"hljs-comment\">\/\/ print curl_error($connection) . \": \" . $response;<\/span>\n\n    <span class=\"hljs-comment\">\/\/ close the connection<\/span>\n    curl_close ( $connection );\n\n    <span class=\"hljs-comment\">\/\/ return the response<\/span>\n    <span class=\"hljs-keyword\">return<\/span> $response;\n   }\n\n  <span class=\"hljs-comment\">\/**\n   * buildEbayHeaders\n   * Generates an array of string to be used as the headers for the HTTP request to eBay\n   * Output: String Array of Headers applicable for this call\n   *\/<\/span>\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">buildEbayHeaders<\/span><span class=\"hljs-params\">()<\/span>\n   <\/span>{\n    $headers = <span class=\"hljs-keyword\">array<\/span> ( <span class=\"hljs-comment\">\/\/ Regulates versioning of the XML interface for the API<\/span>\n      <span class=\"hljs-string\">'X-EBAY-API-COMPATIBILITY-LEVEL: '<\/span> . <span class=\"hljs-keyword\">$this<\/span>-&gt;compatLevel,\n\n      <span class=\"hljs-comment\">\/\/ set the keys<\/span>\n      <span class=\"hljs-string\">'X-EBAY-API-DEV-NAME: '<\/span> . <span class=\"hljs-keyword\">$this<\/span>-&gt;devID,\n      <span class=\"hljs-string\">'X-EBAY-API-APP-NAME: '<\/span> . <span class=\"hljs-keyword\">$this<\/span>-&gt;appID,\n      <span class=\"hljs-string\">'X-EBAY-API-CERT-NAME: '<\/span> . <span class=\"hljs-keyword\">$this<\/span>-&gt;certID,\n\n      <span class=\"hljs-comment\">\/\/ the name of the call we are requesting<\/span>\n      <span class=\"hljs-string\">'X-EBAY-API-CALL-NAME: '<\/span> . <span class=\"hljs-keyword\">$this<\/span>-&gt;verb,\n\n      <span class=\"hljs-comment\">\/\/ SiteID must also be set in the Request's XML<\/span>\n      <span class=\"hljs-comment\">\/\/ SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....<\/span>\n      <span class=\"hljs-comment\">\/\/ SiteID Indicates the eBay site to associate the call with<\/span>\n      <span class=\"hljs-string\">'X-EBAY-API-SITEID: '<\/span> . <span class=\"hljs-keyword\">$this<\/span>-&gt;siteID\n    );\n\n    <span class=\"hljs-keyword\">return<\/span> $headers;\n   }\n }\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>I added classes to encapsulate handling of the specific eBay requests that the plug-in uses.  All are derived from a base class I called <strong>eBayRequest<\/strong>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/**\n *  An eBay request\n *\/<\/span>\n<span class=\"hljs-keyword\">abstract<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">eBayRequest<\/span>\n <\/span>{\n  <span class=\"hljs-keyword\">private<\/span> $requestType;\n\n  <span class=\"hljs-comment\">\/**\n    *  <span class=\"hljs-doctag\">@brief<\/span> Constructor\n    *   \n    *  <span class=\"hljs-doctag\">@param<\/span> string $requestType the eBay API request type\n    *  <span class=\"hljs-doctag\">@return<\/span> void\n    *\/<\/span>\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">__construct<\/span><span class=\"hljs-params\">($requestType)<\/span>\n   <\/span>{\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;requestType = $requestType;\n   }\n\n  <span class=\"hljs-comment\">\/**\n    *  <span class=\"hljs-doctag\">@brief<\/span> getXML - return the XML used to make the API the call\n    *  \n    *  <span class=\"hljs-doctag\">@return<\/span> string the XML of the call\n    *\/<\/span>\n  <span class=\"hljs-keyword\">abstract<\/span> <span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">getXML<\/span><span class=\"hljs-params\">()<\/span><\/span>;\n\n  <span class=\"hljs-comment\">\/**\n   *  <span class=\"hljs-doctag\">@brief<\/span> addResults - add results to the list of results\n   *  \n   *  <span class=\"hljs-doctag\">@param<\/span> string $xml the output XML from the API call\n   *  <span class=\"hljs-doctag\">@param<\/span> array $results the array to hold the $results\n   *  <span class=\"hljs-doctag\">@return<\/span> array the array of results\n   *\/<\/span>\n  <span class=\"hljs-keyword\">abstract<\/span> <span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">addResults<\/span><span class=\"hljs-params\">($xml, $results)<\/span><\/span>;\n\n  <span class=\"hljs-comment\">\/**\n   *  <span class=\"hljs-doctag\">@brief<\/span> getServerURL - return the URL of the API call\n   *  \n   *  <span class=\"hljs-doctag\">@return<\/span> sting the URL\n   *\/<\/span>\n  <span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">getServerURL<\/span><span class=\"hljs-params\">()<\/span>\n   <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">\"https:\/\/api.ebay.com\/ws\/api.dll\"<\/span>;\n   }\n\n  <span class=\"hljs-comment\">\/**\n   *  <span class=\"hljs-doctag\">@brief<\/span> getResults - make the actual API call and return the results\n   *\n   *  <span class=\"hljs-doctag\">@param<\/span> boolean|array - if true, error messages are not logged.  If an array, \n   *                         messages are logged only for errors not in the array \n   *                         of error codes.\n   *  \n   *  <span class=\"hljs-doctag\">@return<\/span> array the results\n   *\/<\/span>\n  <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">getResults<\/span><span class=\"hljs-params\">($suppressErrors = false)<\/span>\n   <\/span>{\n    $devID = ebayGetConfiguration ( <span class=\"hljs-string\">'PROD_DEVID'<\/span> );\n    $appID = ebayGetConfiguration ( <span class=\"hljs-string\">'PROD_APPID'<\/span> );\n    $certID = ebayGetConfiguration ( <span class=\"hljs-string\">'PROD_CERTID'<\/span> );\n    $serverUrl = <span class=\"hljs-keyword\">$this<\/span>-&gt;getServerURL ();\n    $compatabilityLevel = <span class=\"hljs-number\">705<\/span>;\n    $siteID = <span class=\"hljs-number\">0<\/span>;\n    $verb = <span class=\"hljs-keyword\">$this<\/span>-&gt;requestType;\n\n    $session = <span class=\"hljs-keyword\">new<\/span> eBaySessionHandler ( $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb );\n\n    $xml = <span class=\"hljs-keyword\">$this<\/span>-&gt;getXML ();\n    \n    <span class=\"hljs-keyword\">if<\/span> (function_exists(<span class=\"hljs-string\">'eBayModifyRequest'<\/span>))\n      {\n        $xml = eBayModifyRequest($verb, $xml);\n      }\n\n    $response = $session-&gt;sendHttpRequest ( $xml );\n\n    $results = <span class=\"hljs-keyword\">array<\/span> ();\n\n    $results &#91;<span class=\"hljs-string\">'count'<\/span>] = <span class=\"hljs-number\">0<\/span>;\n    $results &#91;<span class=\"hljs-string\">'errorcode'<\/span>] = <span class=\"hljs-string\">'0'<\/span>;\n    $results &#91;<span class=\"hljs-string\">'errormessage'<\/span>] = <span class=\"hljs-string\">''<\/span>;\n    <span class=\"hljs-keyword\">if<\/span> (stristr ( $response, <span class=\"hljs-string\">'HTTP 404'<\/span> ) || $response == <span class=\"hljs-string\">''<\/span>)\n     {\n      $results &#91;<span class=\"hljs-string\">'count'<\/span>] = <span class=\"hljs-number\">0<\/span>;\n      $results &#91;<span class=\"hljs-string\">'status'<\/span>] = <span class=\"hljs-string\">'Failure'<\/span>;\n      $results &#91;<span class=\"hljs-string\">'errorcode'<\/span>] = <span class=\"hljs-string\">'999'<\/span>;\n      $results &#91;<span class=\"hljs-string\">'errorlink'<\/span>]  = <span class=\"hljs-string\">'https:\/\/jonrocket.com\/zencart\/errorcode-'<\/span> . $results &#91;<span class=\"hljs-string\">'errorcode'<\/span>];\n      $results &#91;<span class=\"hljs-string\">'errormessage'<\/span>] = <span class=\"hljs-string\">'HTTP Error'<\/span>;\n      \n      $message = $verb . <span class=\"hljs-string\">': '<\/span> . $results &#91;<span class=\"hljs-string\">'errormessage'<\/span>] . <span class=\"hljs-string\">' {&lt;a href=\"'<\/span> . $results&#91;<span class=\"hljs-string\">'errorlink'<\/span>] . <span class=\"hljs-string\">'\"&gt;'<\/span> . $results &#91;<span class=\"hljs-string\">'errorcode'<\/span>] . <span class=\"hljs-string\">'&lt;\/a&gt;)'<\/span>;\n      eBayLog($message, <span class=\"hljs-keyword\">true<\/span>);\n\n      <span class=\"hljs-keyword\">return<\/span> $results;\n     }\n      \n    $simpleXML = simplexml_load_string ( $response );\n\n    $results &#91;<span class=\"hljs-string\">'status'<\/span>] = ( string ) $simpleXML-&gt;Ack;\n\n    <span class=\"hljs-keyword\">if<\/span> ($results &#91;<span class=\"hljs-string\">'status'<\/span>] != <span class=\"hljs-string\">'Success'<\/span>)\n     {\n      $results &#91;<span class=\"hljs-string\">'errors'<\/span>] = <span class=\"hljs-keyword\">array<\/span> ();\n      <span class=\"hljs-keyword\">foreach<\/span> ( $simpleXML-&gt;Errors <span class=\"hljs-keyword\">as<\/span> $error )\n       {\n        $results &#91;<span class=\"hljs-string\">'errorcode'<\/span>] = ( string ) $error-&gt;ErrorCode;\n        $results &#91;<span class=\"hljs-string\">'errorlink'<\/span>]  = <span class=\"hljs-string\">'https:\/\/jonrocket.com\/zencart\/errorcode-'<\/span> . $results &#91;<span class=\"hljs-string\">'errorcode'<\/span>];\n        $results &#91;<span class=\"hljs-string\">'errormessage'<\/span>] = ( string ) $error-&gt;LongMessage;\n        \n        <span class=\"hljs-keyword\">if<\/span> (!$suppressErrors) \n          {\n            $message = $verb . <span class=\"hljs-string\">': '<\/span> . htmlentities($error-&gt;LongMessage) . <span class=\"hljs-string\">' {&lt;a href=\"'<\/span> . $results &#91;<span class=\"hljs-string\">'errorlink'<\/span>] . <span class=\"hljs-string\">'\"&gt;'<\/span> . $error-&gt;ErrorCode . <span class=\"hljs-string\">'&lt;\/a&gt;)'<\/span>;\n            eBayLog($message, <span class=\"hljs-keyword\">true<\/span>);\n          }\n        \n        \n        $results &#91;<span class=\"hljs-string\">'errors'<\/span>] &#91;] = <span class=\"hljs-keyword\">array<\/span> (\n          <span class=\"hljs-string\">'errorcode'<\/span> =&gt; ( string ) $error-&gt;ErrorCode,\n          <span class=\"hljs-string\">'errormessage'<\/span> =&gt; $error-&gt;LongMessage,\n          <span class=\"hljs-string\">'errorlink'<\/span> =&gt; $results&#91;<span class=\"hljs-string\">'errorlink'<\/span>]\n        );\n       }\n      <span class=\"hljs-keyword\">return<\/span> $results;\n     }\n\n    $results = <span class=\"hljs-keyword\">$this<\/span>-&gt;addResults ( $simpleXML, $results );\n\n    <span class=\"hljs-keyword\">return<\/span> $results;\n   }\n }\n \n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The code for a specific request is derived from the <strong>eBayRequest<\/strong> class.  For example, to get your recent eBay orders, a <strong>GetOrders<\/strong> request is made to eBay&#8217;s Trading API service.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/**\n *  GetOrders Request\n *  \n *  As a side-effect, executing this call will update the store\n *  quantities based on items sold on eBay.\n *\/<\/span>\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">eBayGetOrdersRequest<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">eBayRequest<\/span>\n <\/span>{\n  <span class=\"hljs-keyword\">var<\/span> $from;\n  <span class=\"hljs-keyword\">var<\/span> $to;\n  <span class=\"hljs-keyword\">var<\/span> $role;\n\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">__construct<\/span><span class=\"hljs-params\">($from, $to, $role)<\/span>\n   <\/span>{\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;from = eBayGetUTC8601 ( $from );\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;to = eBayGetUTC8601 ( $to );\n    <span class=\"hljs-keyword\">$this<\/span>-&gt;role = $role;\n\n    <span class=\"hljs-keyword\">parent<\/span>::__construct ( <span class=\"hljs-string\">'GetOrders'<\/span> );\n   }\n\n  <span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">getXML<\/span><span class=\"hljs-params\">()<\/span>\n   <\/span>{\n    $authToken = ebayGetConfiguration ( <span class=\"hljs-string\">'AUTH_TOKEN'<\/span> );\n\n    $request = <span class=\"hljs-string\">&lt;&lt;&lt;XML\n    \n           &lt;?xml version=\"1.0\" encoding=\"utf-8\" ?&gt;\n           &lt;GetOrdersRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\"&gt;\n             &lt;RequesterCredentials&gt;\n                &lt;eBayAuthToken&gt;<span class=\"hljs-subst\">$authToken<\/span>&lt;\/eBayAuthToken&gt;\n             &lt;\/RequesterCredentials&gt;\n             &lt;CreateTimeFrom&gt;<span class=\"hljs-subst\">{$this-&gt;from}<\/span>&lt;\/CreateTimeFrom&gt;\n             &lt;CreateTimeTo&gt;<span class=\"hljs-subst\">{$this-&gt;to}<\/span>&lt;\/CreateTimeTo&gt;\n             &lt;OrderRole&gt;<span class=\"hljs-subst\">{$this-&gt;role}<\/span>&lt;\/OrderRole&gt;\n             &lt;OrderStatus&gt;Completed&lt;\/OrderStatus&gt;\n             &lt;DetailLevel&gt;ReturnAll&lt;\/DetailLevel&gt;\n           &lt;\/GetOrdersRequest&gt;\n    \nXML;<\/span>\n\n    <span class=\"hljs-keyword\">return<\/span> $request;\n   }\n\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">addResults<\/span><span class=\"hljs-params\">($simpleXML, $results)<\/span>\n   <\/span>{\n    $results &#91;<span class=\"hljs-string\">'orders'<\/span>] = <span class=\"hljs-keyword\">array<\/span> ();\n    <span class=\"hljs-keyword\">foreach<\/span> ( $simpleXML-&gt;OrderArray-&gt;Order <span class=\"hljs-keyword\">as<\/span> $order )\n     {\n      $result = <span class=\"hljs-keyword\">array<\/span> ();\n      $result &#91;<span class=\"hljs-string\">'orderid'<\/span>] = ( string ) $order-&gt;OrderID;\n      $result &#91;<span class=\"hljs-string\">'subtotal'<\/span>] = floatval ( ( string ) $order-&gt;Subtotal );\n      $result &#91;<span class=\"hljs-string\">'total'<\/span>] = floatval ( ( string ) $order-&gt;Total );\n      $result &#91;<span class=\"hljs-string\">'buyerid'<\/span>] = ( string ) $order-&gt;BuyerUserID;\n      $result &#91;<span class=\"hljs-string\">'paidtime'<\/span>] = date_create ( ( string ) $order-&gt;PaidTime );\n      $results &#91;<span class=\"hljs-string\">'orders'<\/span>] &#91;] = $result;\n      <span class=\"hljs-keyword\">foreach<\/span> ( $order-&gt;TransactionArray-&gt;Transaction <span class=\"hljs-keyword\">as<\/span> $transaction )\n       {\n         $itemId = $transaction-&gt;Item-&gt;ItemID;\n         $quantity = $transaction-&gt;QuantityPurchased;\n         $transactionId = $transaction-&gt;TransactionID;\n         eBayProcessItemSold($itemId, $transactionId, $quantity);\n       }\n     }\n    $results &#91;<span class=\"hljs-string\">'count'<\/span>] = count ( $results &#91;<span class=\"hljs-string\">'orders'<\/span>] );\n\n    <span class=\"hljs-keyword\">return<\/span> $results;\n   }\n }\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <strong>GetOrders<\/strong> request, like all of the eBay requests starts with creating <a href=\"https:\/\/en.wikipedia.org\/wiki\/XML#:~:text=Extensible%20Markup%20Language%20(XML)%20is,free%20open%20standards%E2%80%94define%20XML.\">XML<\/a> which contains the information to send to eBay&#8217;s server. This includes the three IDs used as keys and the authorization token allowing access to the eBay store information. <\/p>\n\n\n\n<p>The XML is sent to eBay&#8217;s server using the HTTP protocol.  The eBay server returns a response in XML.  The <strong>GetOrdersRequest<\/strong> class parses the returned XML to get information about the orders.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Integration with eBay is made possible by the eBay Application Program Interface (API) which is a collection of services that expose methods that can be called from your server to access information and to define notifications to be sent by eBay to your server. What this means is that the eBay Integration plug-in for Zen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[4,5],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-ebay-integration","tag-ebay","tag-ebay-integration"],"_links":{"self":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":9,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts\/33\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}