home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Services / Ebay.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  11.7 KB  |  478 lines

  1. <?PHP
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Stephan Schmidt <schst@php.net>                             |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Ebay.php,v 1.12 2005/06/05 13:28:39 schst Exp $
  20.  
  21. /**
  22.  * Services/Ebay.php
  23.  *
  24.  * package to access the eBay API
  25.  *
  26.  * @package  Services_Ebay
  27.  * @author   Stephan Schmidt <schst@php.net>
  28.  */
  29.  
  30. /**
  31.  * uses PEAR_Exception
  32.  */
  33. require_once 'PEAR/Exception.php';
  34.  
  35. /**
  36.  * directory where Services_Ebay is installed
  37.  */
  38. define('SERVICES_EBAY_BASEDIR', dirname(__FILE__));
  39.  
  40. /**
  41.  * Services_Ebay warning class
  42.  */
  43. require_once SERVICES_EBAY_BASEDIR . '/Ebay/Error.php';
  44.  
  45. /**
  46.  * Services_Ebay exception classes
  47.  */
  48. require_once SERVICES_EBAY_BASEDIR . '/Ebay/Exception.php';
  49.  
  50. /**
  51.  * API Call base class
  52.  */
  53. require_once SERVICES_EBAY_BASEDIR . '/Ebay/Call.php';
  54.  
  55. /**
  56.  * Session
  57.  */
  58. require_once SERVICES_EBAY_BASEDIR . '/Ebay/Session.php';
  59.  
  60. /**
  61.  * Model base class
  62.  */
  63. require_once SERVICES_EBAY_BASEDIR . '/Ebay/Model.php';
  64.  
  65. /**
  66.  * uses XML_Serializer to build the request XML
  67.  */
  68.  require_once 'XML/Serializer.php';
  69.  
  70. /**
  71.  * uses XML_Unserializer to parse the response XML
  72.  */
  73.  require_once 'XML/Unserializer.php';
  74.   
  75. /**
  76.  * Services/Ebay.php
  77.  *
  78.  * package to access the eBay API
  79.  *
  80.  * @package  Services_Ebay
  81.  * @author   Stephan Schmidt <schst@php.net>
  82.  * @link     http://developer.ebay.com/DevProgram/developer/api.asp
  83.  */
  84. class Services_Ebay
  85. {
  86.    /**
  87.     * no authentication, this is only needed when using FetchToken
  88.     */
  89.     const AUTH_TYPE_NONE = 0;
  90.  
  91.     /**
  92.     * token based authentication
  93.     */
  94.     const AUTH_TYPE_TOKEN = 1;
  95.     
  96.    /**
  97.     * authentication based on user id and password
  98.     */
  99.     const AUTH_TYPE_USER  = 2;
  100.     
  101.    /**
  102.     * return only feedback summary
  103.     */
  104.     const FEEDBACK_BRIEF   = 0;
  105.  
  106.    /**
  107.     * return verbose feedback
  108.     */
  109.     const FEEDBACK_VERBOSE = 1;
  110.  
  111.    /**
  112.     * GetItemTransactions():
  113.     * Detail level 2 focuses on checkout detail (and status) data.
  114.     */
  115.     const TRANSACTION_DETAIL_CHECKOUT = 2;
  116.  
  117.    /**
  118.     * GetItemTransactions():
  119.     * Detail level 4 focuses on retrieving user data for the buyer.
  120.     */
  121.     const TRANSACTION_DETAIL_BUYER = 4;
  122.     
  123.    /**
  124.     * GetItemTransactions():
  125.     * Detail level 8 focuses on the return of payment terms data.
  126.     */
  127.     const TRANSACTION_DETAIL_PAYMENTTERMS = 8;
  128.     
  129.    /**
  130.     * GetItemTransactions():
  131.     * Detail level 16 retrieves the user data for the seller.
  132.     */
  133.     const TRANSACTION_DETAIL_SELLER = 16;
  134.  
  135.    /**
  136.     * GetItemTransactions():
  137.     * Detail level 32 retrieves checkout status and general auction data (like Title and QuantitySold).
  138.     */
  139.     const TRANSACTION_DETAIL_PAYMENT_AUCTIONDATA = 32;
  140.  
  141.    /**
  142.     * GetItemTransactions():
  143.     * Detail level 64 focuses on retrieving end-of-auction data.
  144.     */
  145.     const TRANSACTION_DETAIL_PAYMENT_ENDOFACTION = 64;
  146.  
  147.    /**
  148.     * GetUserDisputes():
  149.     * 1 = See all disputes that involve me as seller or buyer.
  150.     */
  151.     const USER_DISPUTES_ALL = 1;
  152.  
  153.    /**
  154.     * GetUserDisputes():
  155.     * 2 = See all disputes that are awaiting my response.
  156.     */
  157.     const USER_DISPUTES_MY_RESPONSE = 2;
  158.  
  159.    /**
  160.     * GetUserDisputes():
  161.     * 3 = See all disputes that are awaiting the other party's response.
  162.     */
  163.     const USER_DISPUTES_OTHER_RESPONSE = 3;
  164.  
  165.    /**
  166.     * GetUserDisputes():
  167.     * 4 = See all closed disputes that involve me.
  168.     */
  169.     const USER_DISPUTES_CLOSED = 4;
  170.  
  171.    /**
  172.     * AddDisputeResponse():
  173.     * 11 = Seller wants to add information or respond to an email from the buyer.
  174.     */
  175.     const DISPUTE_RESPONSE_MESSAGE = 11;
  176.  
  177.    /**
  178.     * AddDisputeResponse():
  179.     * 13 = Seller has completed the transaction or otherwise does not need to pursue the dispute any longer.
  180.     */
  181.     const DISPUTE_RESPONSE_COMPLETED = 13;
  182.  
  183.    /**
  184.     * AddDisputeResponse():
  185.     * 14 = Seller has made an agreement with the buyer and requires a credit for FVF fees.
  186.     */
  187.     const DISPUTE_RESPONSE_AGREEMENT = 14;
  188.  
  189.    /**
  190.     * AddDisputeResponse():
  191.     * 15 = Seller wants to end communication or stop waiting for the buyer.
  192.     */
  193.     const DISPUTE_RESPONSE_END = 15;
  194.  
  195.    /**
  196.     * SellerReverseDispute():
  197.     * 7 = Came to agreement with buyer.
  198.     */
  199.     const DISPUTE_REVERSE_AGREEMENT = 7;
  200.  
  201.    /**
  202.     * SellerReverseDispute():
  203.     * 9 = Buyer reimbursed auction fees.
  204.     */
  205.     const DISPUTE_REVERSE_REIMBURSED = 9;
  206.  
  207.    /**
  208.     * SellerReverseDispute():
  209.     * 10 = Received payment.
  210.     */
  211.     const DISPUTE_REVERSE_RECEIVED = 10;
  212.  
  213.    /**
  214.     * SellerReverseDispute():
  215.     * 11 = Other.
  216.     */
  217.     const DISPUTE_REVERSE_OTHER = 11;
  218.  
  219.    /**
  220.     * GetAccount():
  221.     * 0 = view by period or date/range
  222.     */
  223.     const ACCOUNT_TYPE_PERIOD = 0;
  224.  
  225.    /**
  226.     * GetAccount():
  227.     * 1 = view by invoice
  228.     */
  229.     const ACCOUNT_TYPE_INVOICE = 1;
  230.  
  231.    /**
  232.     * SiteId USA
  233.     */
  234.     const SITEID_US = 0;
  235.  
  236.    /**
  237.     * SiteId Canada
  238.     */
  239.     const SITEID_CA = 2;
  240.  
  241.    /**
  242.     * SiteId United Kingdom
  243.     */
  244.     const SITEID_UK = 3;
  245.  
  246.    /**
  247.     * SiteId Australia
  248.     */
  249.     const SITEID_AU = 15;
  250.  
  251.    /**
  252.     * SiteId Austria
  253.     */
  254.     const SITEID_AT = 16;
  255.  
  256.    /**
  257.     * SiteId Belgium (french)
  258.     */
  259.     const SITEID_BEFR = 23;
  260.  
  261.    /**
  262.     * SiteId France
  263.     */
  264.     const SITEID_FR = 71;
  265.  
  266.    /**
  267.     * SiteId Germany
  268.     */
  269.     const SITEID_DE = 77;
  270.  
  271.    /**
  272.     * SiteId eBay Motors
  273.     */
  274.     const SITEID_MOTORS = 100;
  275.  
  276.    /**
  277.     * SiteId Italy
  278.     */
  279.     const SITEID_IT = 101;
  280.  
  281.    /**
  282.     * SiteId Belgium (netherlands)
  283.     */
  284.     const SITEID_BENL = 123;
  285.  
  286.    /**
  287.     * SiteId Netherlands
  288.     */
  289.     const SITEID_NL = 146;
  290.  
  291.    /**
  292.     * SiteId Spain
  293.     */
  294.     const SITEID_ES = 186;
  295.  
  296.    /**
  297.     * SiteId Swiss
  298.     */
  299.     const SITEID_CH = 193;
  300.  
  301.    /**
  302.     * SiteId Taiwan
  303.     */
  304.     const SITEID_TW = 196;
  305.  
  306.    /**
  307.     * SiteId China
  308.     */
  309.     const SITEID_CN = 223;
  310.     
  311.    /**
  312.     * session used for the calls
  313.     *
  314.     * @var  object Services_Ebay_Session
  315.     */
  316.     private $session = null;
  317.  
  318.    /**
  319.     * class maps for the model classes
  320.     *
  321.     * @var  array
  322.     */
  323.     static private $modelClasses = array();
  324.  
  325.    /**
  326.     * create Services Ebay helper class
  327.     *
  328.     * @param    object Services_Ebay_Session
  329.     */
  330.     public function __construct(Services_Ebay_Session $session)
  331.     {
  332.         $this->session = $session;
  333.     }
  334.     
  335.    /**
  336.     * Factory method to create a new session
  337.     *
  338.     * @param    string      developer id
  339.     * @param    string      application id
  340.     * @param    string      certificate id
  341.     * @param    string      encoding that you want to use (UTF-8 or ISO-8859-1)
  342.     *                       If you choose to use ISO-8859-1, Services_Ebay will automatically
  343.     *                       encode and decode your data to and from UTF-8, as eBay only
  344.     *                       allows UTF-8 encoded data
  345.     * @return   object Services_Ebay_Session
  346.     */
  347.     public static function getSession($devId, $appId, $certId, $encoding = 'ISO-8859-1')
  348.     {
  349.         $session = new Services_Ebay_Session($devId, $appId, $certId, $encoding);
  350.  
  351.         return $session;
  352.     }
  353.  
  354.    /**
  355.     * change the class that is used for a certain model
  356.     *
  357.     * @param    string      model name
  358.     * @param    string      class name
  359.     */
  360.     public static function useModelClass($model, $class)
  361.     {
  362.         self::$modelClasses[$model] = $class;
  363.     }
  364.  
  365.    /**
  366.     * make an API call
  367.     *
  368.     * @param    string  method to call
  369.     * @param    array   arguments of the call
  370.     */
  371.     public function __call($method, $args)
  372.     {
  373.         try {
  374.             $call = self::loadAPICall($method, $args);
  375.         } catch (Exception $e) {
  376.             throw $e;
  377.         }
  378.  
  379.         return $call->call($this->session);
  380.     }
  381.  
  382.    /**
  383.     * set the detail level for all subsequent calls
  384.     *
  385.     * @param    integer
  386.     */
  387.     public function setDetailLevel($level)
  388.     {
  389.         return $this->session->setDetailLevel($level);
  390.     }
  391.  
  392.    /**
  393.     * load a method call
  394.     *
  395.     * @param    string  name of the method
  396.     * @param    array   arguments
  397.     */
  398.     public static function loadAPICall($method, $args = null)
  399.     {
  400.         $method = ucfirst($method);
  401.  
  402.         $classname = 'Services_Ebay_Call_'.$method;
  403.         $filename  = SERVICES_EBAY_BASEDIR . '/Ebay/Call/'.$method.'.php';
  404.         if (file_exists($filename)) {
  405.             include_once $filename;
  406.         }
  407.         if (!class_exists($classname)) {
  408.             throw new Services_Ebay_API_Exception('API-Call \''.$method.'\' could not be found, please check the spelling, remember that method calls are case-sensitive.');
  409.         }
  410.         $call = new $classname($args);
  411.         return $call;
  412.     }
  413.  
  414.    /**
  415.     * load a model
  416.     *
  417.     * @param    string  type of the model
  418.     * @param    array   properties
  419.     */
  420.     public static function loadModel($type, $properties = null, $session = null)
  421.     {
  422.         if (isset(self::$modelClasses[$type])) {
  423.             $classname = self::$modelClasses[$type];
  424.         } else {
  425.             // use the default model class
  426.             $classname = 'Services_Ebay_Model_'.$type;
  427.             include_once SERVICES_EBAY_BASEDIR . '/Ebay/Model/'.$type.'.php';
  428.         }
  429.         if (!class_exists($classname)) {
  430.             throw new Services_Ebay_Exception('Model \''.$type.'\' could not be found, please check the spelling');   
  431.         }
  432.         $model = new $classname($properties, $session);
  433.         
  434.         return $model;
  435.     }
  436.  
  437.    /**
  438.     * load a model
  439.     *
  440.     * @param    string  type of the model
  441.     * @param    array   properties
  442.     */
  443.     public static function loadCache($type, $options)
  444.     {
  445.         $classname = 'Services_Ebay_Cache_'.$type;
  446.         include_once SERVICES_EBAY_BASEDIR . '/Ebay/Cache/'.$type.'.php';
  447.  
  448.         if (!class_exists($classname)) {
  449.             throw new Services_Ebay_Exception('Class \''.$type.'\' could not be found, please check the spelling');   
  450.         }
  451.         $cache = new $classname($options);
  452.         
  453.         return $cache;
  454.     }
  455.  
  456.    /**
  457.     * get list of all available API calls
  458.     *
  459.     * This can be used to check, whether an API call already has
  460.     * been implemented
  461.     *
  462.     * @return   array   list of all available calls
  463.     */
  464.     public function getAvailableApiCalls()
  465.     {
  466.         $calls = array();
  467.  
  468.         $it = new DirectoryIterator(SERVICES_EBAY_BASEDIR . '/Ebay/Call');
  469.         foreach ($it as $file) {
  470.             if (!$file->isFile()) {
  471.                 continue;
  472.             }
  473.             array_push($calls, substr($file->getFilename(), 0, -4));
  474.         }
  475.         return $calls;
  476.     }
  477. }
  478. ?>