/** * @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())); }
public function testThirdPartyAuthorization() { $authorizerEmail = "*****@*****.**"; $thirdPartyAuth = new PPSubjectAuthorization($authorizerEmail); $cred = new PPSignatureCredential("username", "pwd", "signature"); $cred->setThirdPartyAuthorization($thirdPartyAuth); $this->assertEquals($cred->getThirdPartyAuthorization()->getSubject(), $authorizerEmail); $accessToken = "atoken"; $tokenSecret = "asecret"; $thirdPartyAuth = new PPTokenAuthorization($accessToken, $tokenSecret); $cred->setThirdPartyAuthorization($thirdPartyAuth); $this->assertEquals($cred->getThirdPartyAuthorization()->getAccessToken(), $accessToken); $this->assertEquals($cred->getThirdPartyAuthorization()->getTokenSecret(), $tokenSecret); }
/** * @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()); }
* `Request Envelope` - Information common to each API operation, such as the language in which an error message is returned. * `Invoice ID` - ID of the invoice to send. */ $sendInvoiceRequest = new SendInvoiceRequest($requestEnvelope, $_POST['invoiceID']); /* * ## Creating service wrapper object Creating service wrapper object to make API call and loading configuration file for your credentials and endpoint */ $invoiceService = new InvoiceService(Configuration::getAcctAndConfig()); // required in third party permissioning if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) { $cred = new PPSignatureCredential(USERNAME, PASSWORD, SIGNATURE); $cred->setThirdPartyAuthorization(new PPTokenAuthorization($_POST['accessToken'], $_POST['tokenSecret'])); } try { /* * ## Making API call Invoke the appropriate method corresponding to API in service wrapper object */ if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) { $sendInvoiceResponse = $invoiceService->SendInvoice($sendInvoiceRequest, $cred); } else { $sendInvoiceResponse = $invoiceService->SendInvoice($sendInvoiceRequest); } } catch (Exception $ex) { require_once 'error.php'; exit;