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); }
/** * 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 testInvalidBinding() { $this->setExpectedException('InvalidArgumentException'); FormatterFactory::factory('Unknown'); }