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; }
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); }
/** * * @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); }
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 testGetInstance() { $instance = $this->object->getInstance(); $this->assertTrue($instance instanceof PPCredentialManager); }
/** * @test */ public function testInvalidConfiguration() { $this->setExpectedException('PPMissingCredentialException'); $o = PPCredentialManager::getInstance(array('mode' => 'sandbox')); }
} 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>