PayPal\Core\PPAPIService::makeRequest PHP Method

makeRequest() public method

Execute an api call
public makeRequest ( string $apiMethod, $request ) : array
$apiMethod string Name of the API operation (such as 'Pay')
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);
    }

Usage Example

 /**
  * @test
  */
 public function testMakeRequestWithHandlers()
 {
     $this->object->addHandler(new MockHandler());
     $req = new PPRequest(new MockNVPClass(), "NV");
     $ret = $this->object->makeRequest('GetInvoiceDetails', $req);
     $this->assertArrayHasKey('response', $ret);
     $this->assertContains("responseEnvelope.timestamp=", $ret['response']);
 }
All Usage Examples Of PayPal\Core\PPAPIService::makeRequest