fc6de3fa4593a482ebfc149ea60e314922398519
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 namespace PayPal\Core;
3 use PayPal\Core\PPAPIService;
4 class PPBaseService {
5
6     // SDK Name
7         protected  static $SDK_NAME = "paypal-php-sdk";
8         // SDK Version
9         protected static $SDK_VERSION = "2.1.96";
10         
11         private $serviceName;
12         private $serviceBinding;
13         private $handlers;
14         
15    /*
16     * Setters and getters for Third party authentication (Permission Services)
17     */
18         protected $accessToken;
19         protected $tokenSecret;
20         
21         protected $lastRequest;
22         protected $lastResponse;
23         
24         
25         
26         // config hash map
27         public $config;
28
29         /**
30          * Compute the value that needs to sent for the PAYPAL_REQUEST_SOURCE
31          * parameter when making API calls
32          */
33         public static function getRequestSource()
34         {
35                 return str_replace(" ", "-", self::$SDK_NAME) . "-" . self::$SDK_VERSION;
36         }
37         
38
39     public function getLastRequest() {
40                 return $this->lastRequest;
41         }
42     public function setLastRequest($lastRqst) {
43                 $this->lastRequest = $lastRqst;
44         }
45     public function getLastResponse() {
46                 return $this->lastResponse;
47         }
48     public function setLastResponse($lastRspns) {
49                 $this->lastResponse = $lastRspns;
50         }
51
52         public function __construct($serviceName, $serviceBinding, $handlers=array(), $config = null) {
53                 $this->serviceName = $serviceName;
54                 $this->serviceBinding = $serviceBinding;
55                 $this->handlers = $handlers;
56                 if($config == null)
57                 {
58                         $configFile = PPConfigManager::getInstance();
59                         $this->config = $configFile->getConfigHashmap();
60                 }
61                 else 
62                 {
63                         $this->config = PPConfigManager::mergrDefaults($config);
64                 }
65         }
66
67         public function getServiceName() {
68                 return $this->serviceName;
69         }
70
71         /**
72          * 
73          * @param string $method - API method to call
74          * @param object $requestObject Request object 
75          * @param mixed $apiCredential - Optional API credential - can either be
76          *              a username configured in sdk_config.ini or a ICredential object
77          *      created dynamically             
78          */
79         public function call($port, $method, $requestObject, $apiUserName = NULL) {             
80                 $service = new PPAPIService($port, $this->serviceName, 
81                                 $this->serviceBinding, $this->handlers,$this->config);          
82                 $ret = $service->makeRequest($method, $requestObject, $apiUserName);
83                 $this->lastRequest = $ret['request'];
84                 $this->lastResponse = $ret['response'];
85                 return $this->lastResponse;
86         }
87 }