Source for file Session.php
Documentation is available at Session.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Stephan Schmidt <schst@php.net> |
// +----------------------------------------------------------------------+
// $Id: Session.php,v 1.3 2004/11/16 19:34:05 schst Exp $
* Services/Ebay/Session.php
* manages IDs, authentication, serialization, etc.
* @author Stephan Schmidt <schst@php.net>
* If you do not already have one, please
* apply for a developer ID at http://developer.ebay.com
private $requestPassword;
* name of the transport driver to use
private $transportDriver = 'Curl';
* @var object Services_Ebay_Transport
private $url = 'https://api.sandbox.ebay.com/ws/api.dll';
* @var object XML_Serializer
* XML_Unserializer object
* @var object XML_Unserializer
private $detailLevel = 0;
* additional options for the serializer
* These options will be set by the call objects
private $serializerOptions = array ();
* create the session object
* @param string developer id
* @param string application id
* @param string certificate id
'scalarAsAttributes' => false ,
'rootAttributes' => array ( 'xmlns' => 'urn:eBayAPIschema' ),
$this->ser = new XML_Serializer ( $opts );
'forceEnum' => array ('Error')
$this->us = new XML_Unserializer ( $opts );
* set the authentication token
* set the authentication username and password
$this->requestUserId = $username;
$this->requestPassword = $password;
$this->detailLevel = $level;
* build XML code for a request
* @param string verb of the request
* @param array|null parameters of the request
* @return string XML request
public function buildRequestBody( $verb, $params = array (), $authType = Services_Ebay ::AUTH_TYPE_TOKEN )
'DetailLevel' => $this->detailLevel,
if (empty ($this->token)) {
$request['RequestToken'] = $this->token;
if (empty ($this->requestUserId) || empty ($this->requestPassword)) {
$request['RequestUserId'] = $this->requestUserId;
$request['RequestPassword'] = $this->requestPassword;
if (empty ($this->requestUserId)) {
$request['RequestUserId'] = $this->requestUserId;
$this->ser->serialize ($request, $this->serializerOptions);
return $this->ser->getSerializedData ();
* This method is used by the API methods. You
* may call it directly to access any eBay function that
* is not yet implemented.
* @param string function to call
* @param array associative array containing all parameters for the function call
* @todo add real error handling
public function sendRequest( $verb, $params = array (), $authType = Services_Ebay ::AUTH_TYPE_TOKEN )
if (!isset ($params['DetailLevel'])) {
$params['DetailLevel'] = $this->detailLevel;
'X-EBAY-API-SESSION-CERTIFICATE' => sprintf( '%s;%s;%s', $this->devId, $this->appId, $this->certId ), // Required. Used to authenticate the function call. Use this format, where DevId is the same as the value of the X-EBAY-API-DEV-NAME header, AppId is the same as the value of the X-EBAY-API-APP-NAME header, and CertId is the same as the value of the X-EBAY-API-CERT-NAME header: DevId;AppId;CertId
'X-EBAY-API-COMPATIBILITY-LEVEL' => $this->compatLevel, // Required. Regulates versioning of the XML interface for the API.
'X-EBAY-API-DEV-NAME' => $this->devId, // Required. Developer ID, as registered with the Developer's Program. This value should match the first value (DevId) in the X-EBAY-API-SESSION-CERTIFICATE header. Used to authenticate the function call.
'X-EBAY-API-APP-NAME' => $this->appId, // Required. Application ID, as registered with the Developer's Program. This value should match the second value (AppId) in the X-EBAY-API-SESSION-CERTIFICATE header. Used to authenticate the function call.
'X-EBAY-API-CERT-NAME' => $this->certId, // Required. Certificate ID, as registered with the Developer's Program. This value should match the third value (CertId) in the X-EBAY-API-SESSION-CERTIFICATE header. Used to authenticate the function call.
'X-EBAY-API-CALL-NAME' => $verb, // Required. Name of the function being called, for example: 'GetItem' (without the quotation marks). This must match the information passed in the Verb input argument for each function.
'X-EBAY-API-SITEID' => 0 , // Required. eBay site an item is listed on or that a user is registered on, depending on the purpose of the function call. This must match the information passed in the SiteId input argument for all functions.
'X-EBAY-API-DETAIL-LEVEL' => $params['DetailLevel'], // Required. Controls amount or level of data returned by the function call. May be zero if the function does not support varying detail levels. This must match the information passed in the DetailLevel input argument for each function.
'Content-Type' => 'text/xml', // Required. Specifies the kind of data being transmitted. The value must be 'text/xml'. Sending any other value (e.g., 'application/x-www-form-urlencoded') may cause the call to fail.
'Content-Length' => strlen( $body ) // Recommended. Specifies the size of the data (i.e., the length of the XML string) you are sending. This is used by eBay to determine how much data to read from the stream.
$class = 'Services_Ebay_Transport_'. $this->transportDriver;
$this->wire .= $body. "\n\n";
$response = $tp->sendRequest ($this->url, $body, $headers);
if (PEAR ::isError ($response)) {
$this->wire .= $response. "\n\n";
$this->us->unserialize ( $response );
$result = $this->us->getUnserializedData ();
if (isset ($result['Errors'])) {
if (isset ($result['Errors']['Error'])) {
foreach ($result['Errors']['Error'] as $error) {
$message = $message . ' ' . $error['LongMessage'];
* set additional options for the serializer
$this->serializerOptions = $opts;
Documentation generated on Mon, 11 Mar 2019 13:58:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|