/** * 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(PPConfigManager::getInstance()->get('service.EndPoint.IPN')); $httpConfig->addCurlOption(CURLOPT_FORBID_REUSE, 1); $httpConfig->addCurlOption(CURLOPT_HTTPHEADER, array('Connection: Close')); $connection = PPConnectionManager::getInstance()->getConnection($httpConfig); $response = $connection->execute($request); if ($response == 'VERIFIED') { $this->isIpnVerified = true; return true; } $this->isIpnVerified = false; return false; // value is 'INVALID' } }
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); }
/** * 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); }
/** * Generate OAuth type token from Base64Client ID */ private function generateOAuthToken($base64ClientID) { $headers = array("Authorization" => "Basic " . $base64ClientID, "Accept" => "*/*"); $httpConfiguration = $this->getOAuthHttpConfiguration(); $httpConfiguration->setHeaders($headers); $connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration); $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; }
/** * 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); //var_dump("<pre>", $payload); die(); //requestEnvelope.errorLanguage=en_US&actionType=PAY&cancelUrl=http%3A%2F%2Fcusa-local%2Fsignup¤cyCode=USD&receiverList.receiver.amount=240&receiverList.receiver.email=JulianIWetmore%40armyspy.com&returnUrl=http%3A%2F%2Fcusa-local%2Fsignup-paypal-success%2F%3Fpay_chk%3D1799557580%26 // 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); }
/** * @test */ public function testGetInstance() { $instance = $this->object->getInstance(); $this->assertTrue($instance instanceof PPConnectionManager); }