PPBaseService.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. class PPBaseService {
  3. // SDK Name
  4. protected static $SDK_NAME = "paypal-php-sdk";
  5. // SDK Version
  6. protected static $SDK_VERSION = "2.1.96";
  7. private $serviceName;
  8. private $serviceBinding;
  9. private $handlers;
  10. /*
  11. * Setters and getters for Third party authentication (Permission Services)
  12. */
  13. protected $accessToken;
  14. protected $tokenSecret;
  15. protected $lastRequest;
  16. protected $lastResponse;
  17. /**
  18. * Compute the value that needs to sent for the PAYPAL_REQUEST_SOURCE
  19. * parameter when making API calls
  20. */
  21. public static function getRequestSource()
  22. {
  23. return str_replace(" ", "-", self::$SDK_NAME) . "-" . self::$SDK_VERSION;
  24. }
  25. public function getLastRequest() {
  26. return $this->lastRequest;
  27. }
  28. public function setLastRequest($lastRqst) {
  29. $this->lastRequest = $lastRqst;
  30. }
  31. public function getLastResponse() {
  32. return $this->lastResponse;
  33. }
  34. public function setLastResponse($lastRspns) {
  35. $this->lastResponse = $lastRspns;
  36. }
  37. public function getAccessToken() {
  38. return $this->accessToken;
  39. }
  40. /**
  41. * @deprecated
  42. * For using third party token permissions,
  43. * create a ICredential object and pass it to the
  44. * call() method instead.
  45. *
  46. *<pre>
  47. * $service = new *Service();
  48. * $cred = new PPSignatureCredential("username", "password", "signature");
  49. * $cred->setThirdPartyAuthorization(new PPTokenAuthorization("accessToken", "tokenSecret"));
  50. * $service->SomeOperation($reqObject, $cred);
  51. *</pre>
  52. */
  53. public function setAccessToken($accessToken) {
  54. $this->accessToken = $accessToken;
  55. }
  56. public function getTokenSecret() {
  57. return $this->tokenSecret;
  58. }
  59. /**
  60. * @deprecated
  61. * For using third party token permissions,
  62. * create a ICredential object and pass it to the
  63. * call() method instead.
  64. *
  65. *<pre>
  66. * $service = new *Service();
  67. * $cred = new PPSignatureCredential("username", "password", "signature");
  68. * $cred->setThirdPartyAuthorization(new PPTokenAuthorization("accessToken", "tokenSecret"));
  69. * $service->SomeOperation($reqObject, $cred);
  70. *</pre>
  71. */
  72. public function setTokenSecret($tokenSecret) {
  73. $this->tokenSecret = $tokenSecret;
  74. }
  75. public function __construct($serviceName, $serviceBinding, $handlers=array()) {
  76. $this->serviceName = $serviceName;
  77. $this->serviceBinding = $serviceBinding;
  78. $this->handlers = $handlers;
  79. }
  80. public function getServiceName() {
  81. return $this->serviceName;
  82. }
  83. /**
  84. *
  85. * @param string $method - API method to call
  86. * @param object $requestObject Request object
  87. * @param mixed $apiCredential - Optional API credential - can either be
  88. * a username configured in sdk_config.ini or a ICredential object
  89. * created dynamically
  90. */
  91. public function call($port, $method, $requestObject, $apiCredential = null) {
  92. $service = new PPAPIService($port, $this->serviceName,
  93. $this->serviceBinding, $this->handlers);
  94. $ret = $service->makeRequest($method, $requestObject, $apiCredential,
  95. $this->accessToken, $this->tokenSecret);
  96. $this->lastRequest = $ret['request'];
  97. $this->lastResponse = $ret['response'];
  98. return $this->lastResponse;
  99. }
  100. }