コード例 #1
0
 /**
  * @test
  */
 public function testGetConnection()
 {
     $conn = $this->object->getConnection(new PPHttpConfig("http://domain.com"), $this->config);
     $this->assertNotNull($conn);
     $this->assertTrue($conn instanceof PPHttpConnection);
     $this->assertEquals(get_class($conn), "PayPal\\Core\\PPHttpConnection");
 }
コード例 #2
0
ファイル: PPAPIService.php プロジェクト: Lucerin/Yii-projects
 public function makeRequest($apiMethod, $params, $apiUsername = null)
 {
     $this->apiMethod = $apiMethod;
     if (is_string($apiUsername) || is_null($apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($this->config);
         $apiCredential = clone $credMgr->getCredentialObject($apiUsername);
     } else {
         $apiCredential = $apiUsername;
         //TODO: Aargh
     }
     if (isset($this->config['accessToken']) && isset($this->config['tokenSecret'])) {
         $apiCredential->setThirdPartyAuthorization(new PPTokenAuthorization($this->config['accessToken'], $this->config['tokenSecret']));
     }
     $request = new PPRequest($params, $this->serviceBinding);
     $request->setCredential($apiCredential);
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     $this->runHandlers($httpConfig, $request);
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->config);
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
コード例 #3
0
ファイル: PPAPIService.php プロジェクト: paypal/sdk-core-php
 /**
  * Execute an api call
  *
  * @param string    $apiMethod Name of the API operation (such as 'Pay')
  * @param PPRequest $params    Request object
  *
  * @return array containing request and response
  */
 public function makeRequest($apiMethod, $request)
 {
     $this->apiMethod = $apiMethod;
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     if ($this->apiContext->getHttpHeaders() != null) {
         $httpConfig->setHeaders($this->apiContext->getHttpHeaders());
     }
     $this->runHandlers($httpConfig, $request);
     // Serialize request object to a string according to the binding configuration
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     // Execute HTTP call
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->apiContext->getConfig());
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
コード例 #4
0
 /**
  * Generates a new access token
  */
 private function _generateAccessToken($config)
 {
     $base64ClientID = base64_encode($this->clientId . ":" . $this->clientSecret);
     $headers = array("User-Agent" => PPUserAgent::getValue(PPConstants::SDK_NAME, PPCONSTANTS::SDK_VERSION), "Authorization" => "Basic " . $base64ClientID, "Accept" => "*/*");
     $httpConfiguration = $this->getOAuthHttpConfiguration($config);
     $httpConfiguration->setHeaders($headers);
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfiguration, $config);
     $res = $connection->execute("grant_type=client_credentials");
     $jsonResponse = json_decode($res, true);
     if ($jsonResponse == NULL || !isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"])) {
         $this->accessToken = NULL;
         $this->tokenExpiresIn = NULL;
         $this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);
     } else {
         $this->accessToken = $jsonResponse["access_token"];
         $this->tokenExpiresIn = $jsonResponse["expires_in"];
     }
     $this->tokenCreateTime = time();
     return $this->accessToken;
 }
コード例 #5
0
 /**
  * Validates a IPN message
  *
  * @return boolean
  */
 public function validate()
 {
     if (isset($this->isIpnVerified)) {
         return $this->isIpnVerified;
     } else {
         $request = self::IPN_CMD;
         if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1) {
             $get_magic_quotes_exists = true;
         } else {
             $get_magic_quotes_exists = false;
         }
         foreach ($this->ipnData as $key => $value) {
             if ($get_magic_quotes_exists) {
                 $value = urlencode(stripslashes($value));
             } else {
                 $value = urlencode($value);
             }
             $request .= "&{$key}={$value}";
         }
         $httpConfig = new PPHttpConfig($this->setEndpoint());
         $httpConfig->addCurlOption(CURLOPT_FORBID_REUSE, 1);
         $httpConfig->addCurlOption(CURLOPT_HTTPHEADER, array('Connection: Close'));
         $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->config);
         $response = $connection->execute($request);
         if ($response == 'VERIFIED') {
             $this->isIpnVerified = true;
             return true;
         }
         $this->isIpnVerified = false;
         return false;
         // value is 'INVALID'
     }
 }