Example #1
0
 public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
 {
     $config = PPConfigManager::getInstance();
     if (is_string($apiUsername) || is_null($apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance();
         $apiCredential = clone $credMgr->getCredentialObject($apiUsername);
     } else {
         $apiCredential = $apiUsername;
         //TODO: Aargh
     }
     if (isset($accessToken) && isset($tokenSecret)) {
         $apiCredential->setThirdPartyAuthorization(new PPTokenAuthorization($accessToken, $tokenSecret));
     }
     if ($this->serviceBinding == 'SOAP') {
         $url = $this->endpoint;
     } else {
         $url = $this->endpoint . $this->serviceName . '/' . $apiMethod;
     }
     $request = new PPRequest($params, $this->serviceBinding);
     $request->setCredential($apiCredential);
     $httpConfig = new PPHttpConfig($url, PPHttpConfig::HTTP_POST);
     $this->runHandlers($httpConfig, $request);
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig);
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new PPCredentialManager();
     }
     return self::$instance;
 }
Example #3
0
 public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
 {
     $authentication = new PPAuthenticationManager();
     $connectionMgr = PPConnectionManager::getInstance();
     $connection = $connectionMgr->getConnection();
     $credMgr = PPCredentialManager::getInstance();
     // $apiUsernam is optional, if null the default account in congif file is taken
     $apIPPCredential = $credMgr->getCredentialObject($apiUsername);
     $config = PPConfigManager::getInstance();
     if ($config->get('service.Binding') == 'SOAP') {
         $url = $this->endpoint;
         if (isset($accessToken) && isset($tokenSecret)) {
             $headers = $authentication->getPayPalHeaders($apIPPCredential, $connection, $accessToken, $tokenSecret, $url);
         } else {
             $headers = null;
         }
         $params = $authentication->appendSoapHeader($params, $apIPPCredential, $connection, $accessToken, $tokenSecret, $url);
     } else {
         $url = $this->endpoint . $this->serviceName . '/' . $apiMethod;
         $headers = $authentication->getPayPalHeaders($apIPPCredential, $connection, $accessToken, $tokenSecret, $url);
     }
     $this->logger->info("Request: {$params}");
     $response = $connection->execute($url, $params, $headers);
     $this->logger->info("Response: {$response}");
     return $response;
 }
Example #4
0
 /**
  *
  * @param string $path
  * @param string $data
  * @param PayPal/Rest/ApiContext $apiContext
  * @param array $headers
  */
 public function execute($path, $method, $data = '', $apiContext, $headers = array())
 {
     $configMgr = \PPConfigManager::getInstance();
     $credential = $apiContext->getCredential();
     if ($credential == NULL) {
         // Try picking credentials from the config file
         $credMgr = \PPCredentialManager::getInstance();
         $credValues = $credMgr->getCredentialObject();
         if (!is_array($credValues)) {
             throw new \PPMissingCredentialException("Empty or invalid credentials passed");
         }
         $credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
     }
     if ($credential == NULL || !$credential instanceof OAuthTokenCredential) {
         throw new \PPInvalidCredentialException("Invalid credentials passed");
     }
     $resourceUrl = rtrim(trim($configMgr->get('service.EndPoint')), '/') . $path;
     $config = new \PPHttpConfig($resourceUrl, $method);
     $headers += array('Content-Type' => 'application/json', 'User-Agent' => UserAgent::getValue());
     if (!is_null($credential) && $credential instanceof OAuthTokenCredential) {
         $headers['Authorization'] = "Bearer " . $credential->getAccessToken();
     }
     if ($method == 'POST' || $method == 'PUT') {
         $headers['PayPal-Request-Id'] = $apiContext->getRequestId();
     }
     $config->setHeaders($headers);
     $connection = new \PPHttpConnection($config);
     $response = $connection->execute($data);
     $this->logger->fine($response);
     return $response;
 }
 public function handle($httpConfig, $request, $options)
 {
     parent::handle($httpConfig, $request, $options);
     $config = $options['config'];
     if (is_string($this->apiUsername) || is_null($this->apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($options['config']);
         $request->setCredential(clone $credMgr->getCredentialObject($this->apiUsername));
     } else {
         $request->setCredential($this->apiUsername);
     }
     $endpoint = '';
     $credential = $request->getCredential();
     if (isset($options['port']) && isset($config['service.EndPoint.' . $options['port']])) {
         $endpoint = $config['service.EndPoint.' . $options['port']];
     } else {
         if (isset($config['service.EndPoint'])) {
             $endpoint = $config['service.EndPoint'];
         } else {
             if (isset($config['mode'])) {
                 if (strtoupper($config['mode']) == 'SANDBOX') {
                     if ($credential instanceof PPSignatureCredential) {
                         $endpoint = PPConstants::MERCHANT_SANDBOX_SIGNATURE_ENDPOINT;
                     } else {
                         if ($credential instanceof PPCertificateCredential) {
                             $endpoint = PPConstants::MERCHANT_SANDBOX_CERT_ENDPOINT;
                         }
                     }
                 } else {
                     if (strtoupper($config['mode']) == 'LIVE') {
                         if ($credential instanceof PPSignatureCredential) {
                             $endpoint = PPConstants::MERCHANT_LIVE_SIGNATURE_ENDPOINT;
                         } else {
                             if ($credential instanceof PPCertificateCredential) {
                                 $endpoint = PPConstants::MERCHANT_LIVE_CERT_ENDPOINT;
                             }
                         }
                     }
                 }
             } else {
                 throw new PPConfigurationException('endpoint Not Set');
             }
         }
     }
     if ($request->getBindingType() == 'SOAP') {
         $httpConfig->setUrl($endpoint);
     } else {
         throw new PPConfigurationException('expecting service binding to be SOAP');
     }
     $request->addBindingInfo("namespace", "xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\"");
     // Call the authentication handler to tack authentication related info
     $handler = new PPAuthenticationHandler();
     $handler->handle($httpConfig, $request, $options);
 }
 /**
  * @test
  */
 public function testGetCredentialObject()
 {
     $IPPCredential = $this->object->getCredentialObject('jb-us-seller_api1.paypal.com');
     $this->assertNotNull($IPPCredential);
     $IPPCredential = $this->object->getCredentialObject('suarumugam-biz_api1.paypal.com');
     $this->assertNotNull($IPPCredential);
     $this->assertEquals('suarumugam-biz_api1.paypal.com', $IPPCredential->getUsername());
     $this->assertEquals('config/cert_key.pem', $IPPCredential->getCertificatePath());
     $IPPCredential = $this->object->getCredentialObject('suarumugam-biz_api1.paypal.com');
     $this->assertNotNull($IPPCredential->getUserName());
     $IPPCredential = $this->object->getCredentialObject();
     $this->assertEquals('jb-us-seller_api1.paypal.com', $IPPCredential->getUsername());
     $this->setExpectedException('PPInvalidCredentialException');
     $IPPCredential = $this->object->getCredentialObject('invalid_biz_api1.gmail.com');
 }
 public function handle($httpConfig, $request, $options)
 {
     parent::handle($httpConfig, $request, $options);
     if (is_string($this->apiUsername) || is_null($this->apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($options['config']);
         $request->setCredential(clone $credMgr->getCredentialObject($this->apiUsername));
     } else {
         $request->setCredential($this->apiUsername);
     }
     $config = $options['config'];
     $credential = $request->getCredential();
     //TODO: Assuming existence of getApplicationId
     if ($credential && $credential->getApplicationId() != NULL) {
         $httpConfig->addHeader('X-PAYPAL-APPLICATION-ID', $credential->getApplicationId());
     }
     if (isset($config['port']) && isset($config['service.EndPoint.' . $options['port']])) {
         $endpoint = $config['service.EndPoint.' . $options['port']];
     } else {
         if (isset($config['service.EndPoint'])) {
             $endpoint = $config['service.EndPoint'];
         } else {
             if (isset($config['mode'])) {
                 if (strtoupper($config['mode']) == 'SANDBOX') {
                     $endpoint = PPConstants::PLATFORM_SANDBOX_ENDPOINT;
                 } else {
                     if (strtoupper($config['mode']) == 'LIVE') {
                         $endpoint = PPConstants::PLATFORM_LIVE_ENDPOINT;
                     }
                 }
             } else {
                 throw new PPConfigurationException('endpoint Not Set');
             }
         }
     }
     $httpConfig->setUrl($endpoint . $options['serviceName'] . '/' . $options['apiMethod']);
     // Call the authentication handler to tack authentication related info
     $handler = new PPAuthenticationHandler();
     $handler->handle($httpConfig, $request, $options);
 }
 /**
  * @test
  */
 public function testGetPlatformCredentialObject()
 {
     $cred = $this->object->getCredentialObject();
     $this->assertEquals('APP-80W284485P519543T', $cred->getApplicationId());
 }
 public static function getInstance($config)
 {
     return self::$instance = new PPCredentialManager($config);
 }
 /**
  * @test
  */
 public function testInvalidConfiguration()
 {
     $this->setExpectedException('PPMissingCredentialException');
     $o = PPCredentialManager::getInstance(array('mode' => 'sandbox'));
 }
Example #11
0
} else {
    $payKey = $response->payKey;
    if ($response->paymentExecStatus == "COMPLETED") {
        $case = "1";
    } else {
        if ($_POST['actionType'] == "PAY" && $response->paymentExecStatus == "CREATED") {
            $case = "2";
        } else {
            if ($_POST['preapprovalKey'] != null && $_POST['actionType'] == "CREATE" && $response->paymentExecStatus == "CREATED") {
                $case = "3";
            } else {
                if ($_POST['actionType'] == "PAY_PRIMARY") {
                    $case = "4";
                } else {
                    if ($_POST['actionType'] == "CREATE" && $response->paymentExecStatus == "CREATED") {
                        $apiCred = PPCredentialManager::getInstance()->getCredentialObject(null);
                        if (str_replace('_api1.', '@', $apiCred->getUserName()) == $_POST["senderEmail"]) {
                            $case = "3";
                        } else {
                            $case = "2";
                        }
                    }
                }
            }
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>