/**
  * @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 testDefaultAPIAccount()
 {
     $req = new PPRequest(new StdClass(), 'NV');
     $httpConfig = new PPHttpConfig();
     $handler = new PPPlatformServiceHandler(null, 'sdkname', 'sdkversion');
     $handler->handle($httpConfig, $req, $this->options);
     $this->assertEquals($this->options['config']['acct1.Signature'], $req->getCredential()->getSignature());
     $cred = new PPSignatureCredential('user', 'pass', 'sig');
     $cred->setApplicationId('appId');
     $httpConfig = new PPHttpConfig();
     $handler = new PPPlatformServiceHandler($cred, 'sdkname', 'sdkversion');
     $handler->handle($httpConfig, $req, $this->options);
     $this->assertEquals($cred, $req->getCredential());
 }
 /**
  * @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());
 }
Example #5
0
 		 SendInvoiceRequest which takes mandatory params:
 		
 		 * `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';
Example #6
0
 *  ## MassPayReq
Details of each payment.
`Note:
A single MassPayRequest can include up to 250 MassPayItems.`
*/
$massPayReq = new MassPayReq();
$massPayReq->MassPayRequest = $massPayRequest;
/*
 * 	 ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Configuration::getAcctAndConfig() returns array that contains credential and config parameters
*/
$paypalService = new PayPalAPIInterfaceServiceService(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 {
    /* wrap API method calls on the service object with a try catch */
    if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) {
        $massPayResponse = $paypalService->MassPay($massPayReq, $cred);
    } else {
        $massPayResponse = $paypalService->MassPay($massPayReq);
    }
} catch (Exception $ex) {
    include_once "../Error.php";
    exit;
}
if (isset($massPayResponse)) {
    echo "<table>";
 $requestEnvelope = new RequestEnvelope("en_US");
 $refundDetails = new OtherPaymentRefundDetailsType();
 if ($_POST['note'] != "") {
     $refundDetails->note = $_POST['note'];
 }
 if ($_POST['refundDate'] != "") {
     $refundDetails->date = $_POST['refundDate'];
 }
 $markInvoiceAsRefundedRequest = new MarkInvoiceAsRefundedRequest($requestEnvelope, $_POST['invoiceID'], $refundDetails);
 /*
      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 {
     if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) {
         $markInvoiceAsRefundedResponse = $invoiceService->MarkInvoiceAsRefunded($markInvoiceAsRefundedRequest, $cred);
     } else {
         $markInvoiceAsRefundedResponse = $invoiceService->MarkInvoiceAsRefunded($markInvoiceAsRefundedRequest);
     }
 } catch (Exception $ex) {
     require_once 'error.php';
     exit;
 }
 echo "<table>";
 echo "<tr><td>Ack :</td><td><div id='Ack'>" . $markInvoiceAsRefundedResponse->responseEnvelope->ack . "</div> </td></tr>";
 echo "<tr><td>InvoiceID :</td><td><div id='InvoiceID'>" . $markInvoiceAsRefundedResponse->invoiceID . "</div> </td></tr>";
 /**
  * @test
  */
 public function testGetAppId()
 {
     $this->assertEquals('APP-80W284485P519543T', $this->object->getApplicationId());
 }
 *  GetInvoiceDetailsRequest which takes mandatory params:
 		
 		 * `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 retrieve.
 */
 $getInvoiceDetailsRequest = new GetInvoiceDetailsRequest($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) {
         $getInvoiceDetailsResponse = $invoiceService->GetInvoiceDetails($getInvoiceDetailsRequest, $cred);
     } else {
         $getInvoiceDetailsResponse = $invoiceService->GetInvoiceDetails($getInvoiceDetailsRequest);
     }
 } catch (Exception $ex) {
     require_once 'error.php';