/**
  * @test
  */
 public function testHeadersAddedForSOAP()
 {
     $options = array('config' => array('mode' => 'sandbox'), 'serviceName' => 'AdaptivePayments', 'apiMethod' => 'ConvertCurrency');
     $req = new PPRequest(new StdClass(), 'SOAP');
     $handler = new PPSignatureAuthHandler();
     // Test that no headers are added if no credential is passed
     $httpConfig = new PPHttpConfig();
     $handler->handle($httpConfig, $req, $options);
     $this->assertEquals('', $req->getBindingInfo('securityHeader'));
     // Test that the 3 token SOAP headers are added for first party API calls
     $req = new PPRequest(new StdClass(), 'SOAP');
     $req->setCredential(new PPSignatureCredential('user', 'pass', 'sign'));
     $handler->handle($httpConfig, $req, $options);
     $this->assertContains('<ebl:Username>', $req->getBindingInfo('securityHeader'));
     $this->assertContains('<ebl:Password>', $req->getBindingInfo('securityHeader'));
     $this->assertContains('<ebl:Signature>', $req->getBindingInfo('securityHeader'));
     // Test addition of 'subject' SOAP header for subject based third party auth
     $req = new PPRequest(new StdClass(), 'SOAP');
     $cred = new PPSignatureCredential('user', 'pass', 'sign');
     $cred->setThirdPartyAuthorization(new PPSubjectAuthorization('*****@*****.**'));
     $req->setCredential($cred);
     $handler->handle($httpConfig, $req, $options);
     $this->assertContains('<ebl:Username>', $req->getBindingInfo('securityHeader'));
     $this->assertContains('<ebl:Password>', $req->getBindingInfo('securityHeader'));
     $this->assertContains('<ebl:Signature>', $req->getBindingInfo('securityHeader'));
     $this->assertContains('<ebl:Subject>', $req->getBindingInfo('securityHeader'));
     // Test that no auth related HTTP headers (username, password, sign?) are
     // added for token based third party auth
     $req->getCredential()->setThirdPartyAuthorization(new PPTokenAuthorization('token', 'tokenSecret'));
     $handler->handle($httpConfig, $req, $options);
     $this->assertContains('<ns:RequesterCredentials/>', $req->getBindingInfo('securityHeader'));
     $this->assertEquals(0, count($httpConfig->getHeaders()));
 }
Example #2
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);
 }
 /**
  * @test
  */
 public function testSerializationWithCredentialCall()
 {
     $data = new MockSOAPObject();
     $request = new PPRequest($data, 'SOAP');
     $request->addBindingInfo("namespace", 'ns="http://myns"');
     $request->addBindingInfo("securityHeader", "<abc><xyz>1</xyz></abc>");
     $expected = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ns="http://myns" ><soapenv:Header><abc><xyz>1</xyz></abc></soapenv:Header><soapenv:Body>' . $data->toXMLString() . '</soapenv:Body></soapenv:Envelope>';
     $this->assertEquals($expected, $this->object->toString($request));
 }
 /**
  * @test
  */
 public function testModeBasedEndpointForSignatureCredential()
 {
     $httpConfig = new PPHttpConfig();
     $handler = new PPMerchantServiceHandler(null, 'sdkname', 'sdkversion');
     $req = new PPRequest(new StdClass(), 'SOAP');
     $req->setCredential(new PPSignatureCredential('a', 'b', 'c'));
     $handler->handle($httpConfig, $req, $this->options);
     $this->assertEquals(PPConstants::MERCHANT_SANDBOX_SIGNATURE_ENDPOINT, $httpConfig->getUrl());
     $options = $this->options;
     $options['config']['mode'] = 'live';
     $handler->handle($httpConfig, $req, $options);
     $this->assertEquals(PPConstants::MERCHANT_LIVE_SIGNATURE_ENDPOINT, $httpConfig->getUrl());
 }
 /**
  * @test
  */
 public function testValidConfiguration()
 {
     $credential = new PPSignatureCredential('user', 'pass', 'sign');
     $credential->setThirdPartyAuthorization(new PPTokenAuthorization('accessToken', 'tokenSecret'));
     $options = array('config' => array('mode' => 'sandbox'), 'serviceName' => 'DoExpressCheckout', 'port' => 'PayPalAPI');
     $req = new PPRequest(new StdClass(), 'SOAP');
     $req->setCredential($credential);
     $httpConfig = new PPHttpConfig('http://api.paypal.com');
     $handler = new PPAuthenticationHandler();
     $handler->handle($httpConfig, $req, $options);
     $this->assertArrayHasKey('X-PP-AUTHORIZATION', $httpConfig->getHeaders());
     $options['port'] = 'abc';
     $handler->handle($httpConfig, $req, $options);
     $this->assertArrayHasKey('X-PAYPAL-AUTHORIZATION', $httpConfig->getHeaders());
     unset($options['port']);
     $handler->handle($httpConfig, $req, $options);
     $this->assertArrayHasKey('X-PAYPAL-AUTHORIZATION', $httpConfig->getHeaders());
 }