allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

View File

@@ -0,0 +1,218 @@
<?php
namespace Omnipay\PayPal;
use Omnipay\Tests\GatewayTestCase;
class ExpressGatewayTest extends GatewayTestCase
{
/**
* @var \Omnipay\PayPal\ExpressGateway
*/
protected $gateway;
/**
* @var array
*/
protected $options;
/**
* @var array
*/
protected $voidOptions;
public function setUp()
{
parent::setUp();
$this->gateway = new ExpressGateway($this->getHttpClient(), $this->getHttpRequest());
$this->options = array(
'amount' => '10.00',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
);
$this->voidOptions = array(
'transactionReference' => 'ASDFASDFASDF',
);
}
public function testAuthorizeSuccess()
{
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt');
$response = $this->gateway->authorize($this->options)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response);
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
}
public function testAuthorizeFailure()
{
$this->setMockHttpResponse('ExpressPurchaseFailure.txt');
$response = $this->gateway->authorize($this->options)->send();
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
}
public function testPurchaseSuccess()
{
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt');
$response = $this->gateway->purchase($this->options)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response);
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
}
public function testPurchaseFailure()
{
$this->setMockHttpResponse('ExpressPurchaseFailure.txt');
$response = $this->gateway->purchase($this->options)->send();
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
}
public function testOrderSuccess()
{
$this->setMockHttpResponse('ExpressOrderSuccess.txt');
$response = $this->gateway->order($this->options)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressAuthorizeResponse', $response);
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
}
public function testOrderFailure()
{
$this->setMockHttpResponse('ExpressOrderFailure.txt');
$response = $this->gateway->order($this->options)->send();
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
}
public function testVoidSuccess()
{
$this->setMockHttpResponse('ExpressVoidSuccess.txt');
$response = $this->gateway->void($this->voidOptions)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\Response', $response);
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('ASDFASDFASDF', $response->getTransactionReference());
}
public function testVoidFailure()
{
$this->setMockHttpResponse('ExpressVoidFailure.txt');
$response = $this->gateway->void($this->voidOptions)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\Response', $response);
$this->assertFalse($response->isSuccessful());
}
public function testFetchCheckout()
{
$options = array('token' => 'abc123');
$request = $this->gateway->fetchCheckout($options);
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressFetchCheckoutRequest', $request);
$this->assertSame('abc123', $request->getToken());
}
public function testCompletePurchaseFailureRedirect()
{
$this->setMockHttpResponse('ExpressCompletePurchaseFailureRedirect.txt');
$response = $this->gateway->completePurchase($this->options)->send();
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('ASDFASDFASDF', $response->getTransactionReference());
$this->assertSame('This transaction couldn\'t be completed. Please redirect your customer to PayPal.', $response->getMessage());
}
public function testCompletePurchaseHttpOptions()
{
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt');
$this->getHttpRequest()->query->replace(array(
'token' => 'GET_TOKEN',
'PayerID' => 'GET_PAYERID',
));
$response = $this->gateway->completePurchase(array(
'amount' => '10.00',
'currency' => 'EUR',
))->send();
$httpRequests = $this->getMockedRequests();
$httpRequest = $httpRequests[0];
parse_str((string)$httpRequest->getBody(), $postData);
$this->assertSame('GET_TOKEN', $postData['TOKEN']);
$this->assertSame('GET_PAYERID', $postData['PAYERID']);
}
public function testCompletePurchaseCustomOptions()
{
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt');
// Those values should not be used if custom token or payerid are passed
$this->getHttpRequest()->query->replace(array(
'token' => 'GET_TOKEN',
'PayerID' => 'GET_PAYERID',
));
$response = $this->gateway->completePurchase(array(
'amount' => '10.00',
'currency' => 'EUR',
'token' => 'CUSTOM_TOKEN',
'payerid' => 'CUSTOM_PAYERID',
))->send();
$httpRequests = $this->getMockedRequests();
$httpRequest = $httpRequests[0];
parse_str((string)$httpRequest->getBody(), $postData);
$this->assertSame('CUSTOM_TOKEN', $postData['TOKEN']);
$this->assertSame('CUSTOM_PAYERID', $postData['PAYERID']);
}
public function testTransactionSearch()
{
$transactionSearch = $this->gateway->transactionSearch(array(
'startDate' => '2015-01-01',
'endDate' => '2015-12-31',
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressTransactionSearchRequest', $transactionSearch);
$this->assertInstanceOf('\DateTime', $transactionSearch->getStartDate());
$this->assertInstanceOf('\DateTime', $transactionSearch->getEndDate());
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace Omnipay\PayPal;
use Omnipay\Tests\GatewayTestCase;
class ExpressInContextGatewayTest extends GatewayTestCase
{
/**
* @var \Omnipay\PayPal\ExpressInContextGateway
*/
protected $gateway;
/**
* @var array
*/
protected $options;
/**
* @var array
*/
protected $voidOptions;
public function setUp()
{
parent::setUp();
$this->gateway = new ExpressInContextGateway($this->getHttpClient(), $this->getHttpRequest());
$this->options = array(
'amount' => '10.00',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
);
$this->voidOptions = array(
'transactionReference' => 'ASDFASDFASDF',
);
}
public function testAuthorizeSuccess()
{
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt');
$response = $this->gateway->authorize($this->options)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response);
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
}
public function testPurchaseSuccess()
{
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt');
$response = $this->gateway->purchase($this->options)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response);
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
}
public function testOrderSuccess()
{
$this->setMockHttpResponse('ExpressOrderSuccess.txt');
$response = $this->gateway->order($this->options)->send();
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response);
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\PayPal\Message\CaptureRequest;
use Omnipay\Tests\TestCase;
class CaptureRequestTest extends TestCase
{
/**
* @var \Omnipay\PayPal\Message\CaptureRequest
*/
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new CaptureRequest($client, $request);
}
public function testGetData()
{
$this->request->setTransactionReference('ABC-123');
$this->request->setAmount('1.23');
$this->request->setCurrency('USD');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$this->request->setButtonSource('BNCode_PP');
$expected = array();
$expected['METHOD'] = 'DoCapture';
$expected['AUTHORIZATIONID'] = 'ABC-123';
$expected['AMT'] = '1.23';
$expected['CURRENCYCODE'] = 'USD';
$expected['COMPLETETYPE'] = 'Complete';
$expected['USER'] = 'testuser';
$expected['PWD'] = 'testpass';
$expected['SIGNATURE'] = 'SIG';
$expected['SUBJECT'] = 'SUB';
$expected['BUTTONSOURCE'] = 'BNCode_PP';
$expected['VERSION'] = CaptureRequest::API_VERSION;
$this->assertEquals($expected, $this->request->getData());
}
}

View File

@@ -0,0 +1,416 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\PayPal\Message\ExpressAuthorizeRequest;
use Omnipay\PayPal\Support\InstantUpdateApi\BillingAgreement;
use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption;
use Omnipay\Tests\TestCase;
class ExpressAuthorizeRequestTest extends TestCase
{
/**
* @var ExpressAuthorizeRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new ExpressAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '10.00',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
)
);
}
public function testGetDataWithoutCard()
{
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'noShipping' => 0,
'localeCode' => 'EN',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Inc.',
'customerServiceNumber' => '1-801-FLOWERS',
));
$data = $this->request->getData();
$this->assertSame('10.00', $data['PAYMENTREQUEST_0_AMT']);
$this->assertSame('AUD', $data['PAYMENTREQUEST_0_CURRENCYCODE']);
$this->assertSame('111', $data['PAYMENTREQUEST_0_INVNUM']);
$this->assertSame('Order Description', $data['PAYMENTREQUEST_0_DESC']);
$this->assertSame('https://www.example.com/return', $data['RETURNURL']);
$this->assertSame('https://www.example.com/cancel', $data['CANCELURL']);
$this->assertSame('demo@example.com', $data['SUBJECT']);
$this->assertSame('https://www.example.com/header.jpg', $data['HDRIMG']);
$this->assertSame(0, $data['NOSHIPPING']);
$this->assertSame(0, $data['ALLOWNOTE']);
$this->assertSame('EN', $data['LOCALECODE']);
$this->assertSame(0, $data['ADDROVERRIDE']);
$this->assertSame('Dunder Mifflin Paper Company, Inc.', $data['BRANDNAME']);
$this->assertSame('1-801-FLOWERS', $data['CUSTOMERSERVICENUMBER']);
}
public function testGetDataWithCard()
{
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'noShipping' => 2,
'allowNote' => 1,
'addressOverride' => 1,
'brandName' => 'Dunder Mifflin Paper Company, Inc.',
'maxAmount' => 123.45,
'logoImageUrl' => 'https://www.example.com/logo.jpg',
'borderColor' => 'CCCCCC',
'localeCode' => 'EN',
'customerServiceNumber' => '1-801-FLOWERS',
'sellerPaypalAccountId' => 'billing@example.com',
));
$card = new CreditCard(array(
'name' => 'John Doe',
'address1' => '123 NW Blvd',
'address2' => 'Lynx Lane',
'city' => 'Topeka',
'state' => 'KS',
'country' => 'USA',
'postcode' => '66605',
'phone' => '555-555-5555',
'email' => 'test@email.com',
));
$this->request->setCard($card);
$expected = array(
'METHOD' => 'SetExpressCheckout',
'VERSION' => ExpressAuthorizeRequest::API_VERSION,
'USER' => null,
'PWD' => null,
'SIGNATURE' => null,
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization',
'SOLUTIONTYPE' => null,
'LANDINGPAGE' => null,
'NOSHIPPING' => 2,
'ALLOWNOTE' => 1,
'ADDROVERRIDE' => 1,
'PAYMENTREQUEST_0_AMT' => '10.00',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'AUD',
'PAYMENTREQUEST_0_INVNUM' => '111',
'PAYMENTREQUEST_0_DESC' => 'Order Description',
'RETURNURL' => 'https://www.example.com/return',
'CANCELURL' => 'https://www.example.com/cancel',
'SUBJECT' => 'demo@example.com',
'HDRIMG' => 'https://www.example.com/header.jpg',
'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe',
'PAYMENTREQUEST_0_SHIPTOSTREET' => '123 NW Blvd',
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Lynx Lane',
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Topeka',
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'KS',
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
'PAYMENTREQUEST_0_SHIPTOZIP' => '66605',
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '555-555-5555',
'EMAIL' => 'test@email.com',
'BRANDNAME' => 'Dunder Mifflin Paper Company, Inc.',
'MAXAMT' => 123.45,
'PAYMENTREQUEST_0_TAXAMT' => null,
'PAYMENTREQUEST_0_SHIPPINGAMT' => null,
'PAYMENTREQUEST_0_HANDLINGAMT' => null,
'PAYMENTREQUEST_0_SHIPDISCAMT' => null,
'PAYMENTREQUEST_0_INSURANCEAMT' => null,
'LOGOIMG' => 'https://www.example.com/logo.jpg',
'CARTBORDERCOLOR' => 'CCCCCC',
'LOCALECODE' => 'EN',
'CUSTOMERSERVICENUMBER' => '1-801-FLOWERS',
'PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID' => 'billing@example.com',
);
$this->assertEquals($expected, $this->request->getData());
}
public function testGetDataWithItems()
{
$this->request->setItems(array(
array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10, 'code' => '123456'),
array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40),
));
$data = $this->request->getData();
$this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']);
$this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']);
$this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']);
$this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']);
$this->assertSame('123456', $data['L_PAYMENTREQUEST_0_NUMBER0']);
$this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']);
$this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']);
$this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']);
$this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']);
$this->assertSame('60.00', $data['PAYMENTREQUEST_0_ITEMAMT']);
}
public function testGetDataWithExtraOrderDetails()
{
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'noShipping' => 0,
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Inc.',
'taxAmount' => '2.00',
'shippingAmount' => '5.00',
'handlingAmount' => '1.00',
'shippingDiscount' => '-1.00',
'insuranceAmount' => '3.00',
));
$data = $this->request->getData();
$this->assertSame('2.00', $data['PAYMENTREQUEST_0_TAXAMT']);
$this->assertSame('5.00', $data['PAYMENTREQUEST_0_SHIPPINGAMT']);
$this->assertSame('1.00', $data['PAYMENTREQUEST_0_HANDLINGAMT']);
$this->assertSame('-1.00', $data['PAYMENTREQUEST_0_SHIPDISCAMT']);
$this->assertSame('3.00', $data['PAYMENTREQUEST_0_INSURANCEAMT']);
}
public function testHeaderImageUrl()
{
$this->assertSame($this->request, $this->request->setHeaderImageUrl('https://www.example.com/header.jpg'));
$this->assertSame('https://www.example.com/header.jpg', $this->request->getHeaderImageUrl());
$data = $this->request->getData();
$this->assertEquals('https://www.example.com/header.jpg', $data['HDRIMG']);
}
public function testMaxAmount()
{
$this->request->setMaxAmount(321.54);
$this->assertSame(321.54, $this->request->getMaxAmount());
$data = $this->request->getData();
$this->assertSame(321.54, $data['MAXAMT']);
}
public function testDataWithCallback()
{
$baseData = array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Incy.',
);
$shippingOptions = array(
new ShippingOption('First Class', 1.20, true, '1-2 days'),
new ShippingOption('Second Class', 0.70, false, '3-5 days'),
new ShippingOption('International', 3.50),
);
// with a default callback timeout
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
'shippingOptions' => $shippingOptions,
)));
$data = $this->request->getData();
$this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']);
$this->assertSame(ExpressAuthorizeRequest::DEFAULT_CALLBACK_TIMEOUT, $data['CALLBACKTIMEOUT']);
$this->assertSame('First Class', $data['L_SHIPPINGOPTIONNAME0']);
$this->assertSame('1.20', $data['L_SHIPPINGOPTIONAMOUNT0']);
$this->assertSame('1', $data['L_SHIPPINGOPTIONISDEFAULT0']);
$this->assertSame('1-2 days', $data['L_SHIPPINGOPTIONLABEL0']);
$this->assertSame('Second Class', $data['L_SHIPPINGOPTIONNAME1']);
$this->assertSame('0.70', $data['L_SHIPPINGOPTIONAMOUNT1']);
$this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT1']);
$this->assertSame('3-5 days', $data['L_SHIPPINGOPTIONLABEL1']);
$this->assertSame('International', $data['L_SHIPPINGOPTIONNAME2']);
$this->assertSame('3.50', $data['L_SHIPPINGOPTIONAMOUNT2']);
$this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT2']);
// with a defined callback timeout
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
'callbackTimeout' => 10,
'shippingOptions' => $shippingOptions,
)));
$data = $this->request->getData();
$this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']);
$this->assertSame(10, $data['CALLBACKTIMEOUT']);
}
public function testDataWithCallbackAndNoDefaultShippingOption()
{
$baseData = array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Incy.',
);
$shippingOptions = array(
new ShippingOption('First Class', 1.20, false, '1-2 days'),
new ShippingOption('Second Class', 0.70, false, '3-5 days'),
new ShippingOption('International', 3.50),
);
// with a default callback timeout
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
'shippingOptions' => $shippingOptions,
)));
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('One of the supplied shipping options must be set as default');
$this->request->getData();
}
public function testNoAmount()
{
$baseData = array(// nothing here - should cause a certain exception
);
$this->request->initialize($baseData);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('The amount parameter is required');
$this->request->getData();
}
public function testAmountButNoReturnUrl()
{
$baseData = array(
'amount' => 10.00,
);
$this->request->initialize($baseData);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('The returnUrl parameter is required');
$this->request->getData();
}
public function testBadCallbackConfiguration()
{
$baseData = array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Incy.',
);
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
)));
// from the docblock on this exception -
// Thrown when a request is invalid or missing required fields.
// callback has been set but no shipping options so expect one of these:
$this->expectException(InvalidRequestException::class);
$this->request->getData();
}
public function testGetDataWithSingleBillingAgreement()
{
$billingAgreement = new BillingAgreement(false, 'Some Stuff');
$this->request->setBillingAgreement($billingAgreement);
$data = $this->request->getData();
$this->assertSame('MerchantInitiatedBillingSingleAgreement', $data['L_BILLINGTYPE0']);
$this->assertSame('Some Stuff', $data['L_BILLINGAGREEMENTDESCRIPTION0']);
}
public function testGetDataWithRecurringBillingAgreement()
{
$billingAgreement = new BillingAgreement(true, 'Some Stuff');
$this->request->setBillingAgreement($billingAgreement);
$data = $this->request->getData();
$this->assertSame('MerchantInitiatedBilling', $data['L_BILLINGTYPE0']);
$this->assertSame('Some Stuff', $data['L_BILLINGAGREEMENTDESCRIPTION0']);
}
public function testGetDataWithBillingAgreementOptionalParameters()
{
$billingAgreement = new BillingAgreement(true, 'Some Stuff', 'InstantOnly', 'Some custom annotation');
$this->request->setBillingAgreement($billingAgreement);
$data = $this->request->getData();
$this->assertSame('MerchantInitiatedBilling', $data['L_BILLINGTYPE0']);
$this->assertSame('Some Stuff', $data['L_BILLINGAGREEMENTDESCRIPTION0']);
$this->assertSame('InstantOnly', $data['L_PAYMENTTYPE0']);
$this->assertSame('Some custom annotation', $data['L_BILLINGAGREEMENTCUSTOM0']);
}
/**
*
*/
public function testGetDataWithBillingAgreementWrongPaymentType()
{
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage("The 'paymentType' parameter can be only 'Any' or 'InstantOnly'");
$billingAgreement = new BillingAgreement(false, 'Some Stuff', 'BadType', 'Some custom annotation');
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\Message\ExpressAuthorizeResponse;
class ExpressAuthorizeResponseTest extends TestCase
{
public function testConstruct()
{
// response should decode URL format data
$response = new ExpressAuthorizeResponse($this->getMockRequest(), 'example=value&foo=bar');
$this->assertEquals(array('example' => 'value', 'foo' => 'bar'), $response->getData());
}
public function testExpressPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('ExpressPurchaseSuccess.txt');
$request = $this->getMockRequest();
$request->shouldReceive('getTestMode')->once()->andReturn(true);
$response = new ExpressAuthorizeResponse($request, $httpResponse->getBody());
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertSame('EC-42721413K79637829', $response->getTransactionReference());
$this->assertNull($response->getMessage());
$this->assertNull($response->getRedirectData());
$this->assertSame('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
$this->assertSame('GET', $response->getRedirectMethod());
}
public function testExpressPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('ExpressPurchaseFailure.txt');
$response = new ExpressAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody());
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\PayPal\Message\ExpressCompleteAuthorizeRequest;
use Omnipay\Tests\TestCase;
class ExpressCompleteAuthorizeRequestTest extends TestCase
{
/**
* @var \Omnipay\PayPal\Message\ExpressCompleteAuthorizeRequest
*/
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$request->query->set('PayerID', 'Payer-1234');
$request->query->set('token', 'TOKEN1234');
$this->request = new ExpressCompleteAuthorizeRequest($client, $request);
}
public function testGetData()
{
$this->request->setAmount('1.23');
$this->request->setCurrency('USD');
$this->request->setTransactionId('ABC-123');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$this->request->setDescription('DESC');
$this->request->setNotifyUrl('https://www.example.com/notify');
$this->request->setMaxAmount('0.00');
$this->request->setTaxAmount('0.00');
$this->request->setShippingAmount('0.00');
$this->request->setHandlingAmount('0.00');
$this->request->setShippingDiscount('0.00');
$this->request->setInsuranceAmount('0.00');
$expected = array();
$expected['METHOD'] = 'DoExpressCheckoutPayment';
$expected['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization';
$expected['PAYMENTREQUEST_0_AMT'] = '1.23';
$expected['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
$expected['PAYMENTREQUEST_0_INVNUM'] = 'ABC-123';
$expected['PAYMENTREQUEST_0_DESC'] = 'DESC';
$expected['PAYMENTREQUEST_0_NOTIFYURL'] = 'https://www.example.com/notify';
$expected['USER'] = 'testuser';
$expected['PWD'] = 'testpass';
$expected['SIGNATURE'] = 'SIG';
$expected['SUBJECT'] = 'SUB';
$expected['VERSION'] = ExpressCompleteAuthorizeRequest::API_VERSION;
$expected['TOKEN'] = 'TOKEN1234';
$expected['PAYERID'] = 'Payer-1234';
$expected['MAXAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_TAXAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_HANDLINGAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00';
$this->assertEquals($expected, $this->request->getData());
}
public function testGetDataWithItems()
{
$this->request->setAmount('50.00');
$this->request->setCurrency('USD');
$this->request->setTransactionId('ABC-123');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$this->request->setDescription('DESC');
$this->request->setItems(array(
array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10),
array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40),
));
$data = $this->request->getData();
$this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']);
$this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']);
$this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']);
$this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']);
$this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']);
$this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']);
$this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']);
$this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']);
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\PayPal\Message\ExpressCompletePurchaseRequest;
use Omnipay\Tests\TestCase;
class ExpressCompletePurchaseRequestTest extends TestCase
{
/**
* @var \Omnipay\PayPal\Message\ExpressCompletePurchaseRequest
*/
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$request->query->set('PayerID', 'Payer-1234');
$request->query->set('token', 'TOKEN1234');
$this->request = new ExpressCompletePurchaseRequest($client, $request);
}
public function testGetData()
{
$this->request->setAmount('1.23');
$this->request->setCurrency('USD');
$this->request->setTransactionId('ABC-123');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$this->request->setDescription('DESC');
$this->request->setNotifyUrl('https://www.example.com/notify');
$this->request->setMaxAmount('0.00');
$this->request->setTaxAmount('0.00');
$this->request->setShippingAmount('0.00');
$this->request->setHandlingAmount('0.00');
$this->request->setShippingDiscount('0.00');
$this->request->setInsuranceAmount('0.00');
$expected = array();
$expected['METHOD'] = 'DoExpressCheckoutPayment';
$expected['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale';
$expected['PAYMENTREQUEST_0_AMT'] = '1.23';
$expected['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
$expected['PAYMENTREQUEST_0_INVNUM'] = 'ABC-123';
$expected['PAYMENTREQUEST_0_DESC'] = 'DESC';
$expected['PAYMENTREQUEST_0_NOTIFYURL'] = 'https://www.example.com/notify';
$expected['USER'] = 'testuser';
$expected['PWD'] = 'testpass';
$expected['SIGNATURE'] = 'SIG';
$expected['SUBJECT'] = 'SUB';
$expected['VERSION'] = ExpressCompletePurchaseRequest::API_VERSION;
$expected['TOKEN'] = 'TOKEN1234';
$expected['PAYERID'] = 'Payer-1234';
$expected['MAXAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_TAXAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_HANDLINGAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00';
$expected['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00';
$this->assertEquals($expected, $this->request->getData());
}
public function testGetDataWithItems()
{
$this->request->setAmount('50.00');
$this->request->setCurrency('USD');
$this->request->setTransactionId('ABC-123');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$this->request->setDescription('DESC');
$this->request->setItems(array(
array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10),
array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40),
));
$data = $this->request->getData();
$this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']);
$this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']);
$this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']);
$this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']);
$this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']);
$this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']);
$this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']);
$this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']);
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\PayPal\Message\ExpressFetchCheckoutRequest;
use Omnipay\Tests\TestCase;
class ExpressFetchCheckoutRequestTest extends TestCase
{
/**
* @var \Omnipay\PayPal\Message\ExpressFetchCheckoutRequest
*/
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$request->query->set('token', 'TOKEN1234');
$this->request = new ExpressFetchCheckoutRequest($client, $request);
}
public function testGetData()
{
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$expected = array();
$expected['METHOD'] = 'GetExpressCheckoutDetails';
$expected['USER'] = 'testuser';
$expected['PWD'] = 'testpass';
$expected['SIGNATURE'] = 'SIG';
$expected['SUBJECT'] = null;
$expected['VERSION'] = ExpressCompletePurchaseRequest::API_VERSION;
$expected['TOKEN'] = 'TOKEN1234';
$this->assertEquals($expected, $this->request->getData());
}
public function testGetDataTokenOverride()
{
$this->request->setToken('TOKEN2000');
$data = $this->request->getData();
$this->assertSame('TOKEN2000', $data['TOKEN']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('ExpressFetchCheckoutSuccess.txt');
$response = $this->request->send();
$this->assertFalse($response->isPending());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
}
public function testSendFailure()
{
$this->setMockHttpResponse('ExpressFetchCheckoutFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('The amount exceeds the maximum amount for a single transaction.', $response->getMessage());
}
}

View File

@@ -0,0 +1,369 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\PayPal\Message\ExpressInContextAuthorizeRequest;
use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption;
use Omnipay\Tests\TestCase;
class ExpressInContextAuthorizeRequestTest extends TestCase
{
/**
* @var ExpressInContextAuthorizeRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new ExpressInContextAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '10.00',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
)
);
}
public function testGetDataWithoutCard()
{
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'noShipping' => 0,
'localeCode' => 'EN',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Inc.',
'customerServiceNumber' => '1-801-FLOWERS',
));
$data = $this->request->getData();
$this->assertSame('10.00', $data['PAYMENTREQUEST_0_AMT']);
$this->assertSame('AUD', $data['PAYMENTREQUEST_0_CURRENCYCODE']);
$this->assertSame('111', $data['PAYMENTREQUEST_0_INVNUM']);
$this->assertSame('Order Description', $data['PAYMENTREQUEST_0_DESC']);
$this->assertSame('https://www.example.com/return', $data['RETURNURL']);
$this->assertSame('https://www.example.com/cancel', $data['CANCELURL']);
$this->assertSame('demo@example.com', $data['SUBJECT']);
$this->assertSame('https://www.example.com/header.jpg', $data['HDRIMG']);
$this->assertSame(0, $data['NOSHIPPING']);
$this->assertSame(0, $data['ALLOWNOTE']);
$this->assertSame('EN', $data['LOCALECODE']);
$this->assertSame(0, $data['ADDROVERRIDE']);
$this->assertSame('Dunder Mifflin Paper Company, Inc.', $data['BRANDNAME']);
$this->assertSame('1-801-FLOWERS', $data['CUSTOMERSERVICENUMBER']);
}
public function testGetDataWithCard()
{
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'noShipping' => 2,
'allowNote' => 1,
'addressOverride' => 1,
'brandName' => 'Dunder Mifflin Paper Company, Inc.',
'maxAmount' => 123.45,
'logoImageUrl' => 'https://www.example.com/logo.jpg',
'borderColor' => 'CCCCCC',
'localeCode' => 'EN',
'customerServiceNumber' => '1-801-FLOWERS',
'sellerPaypalAccountId' => 'billing@example.com',
));
$card = new CreditCard(array(
'name' => 'John Doe',
'address1' => '123 NW Blvd',
'address2' => 'Lynx Lane',
'city' => 'Topeka',
'state' => 'KS',
'country' => 'USA',
'postcode' => '66605',
'phone' => '555-555-5555',
'email' => 'test@email.com',
));
$this->request->setCard($card);
$expected = array(
'METHOD' => 'SetExpressCheckout',
'VERSION' => ExpressInContextAuthorizeRequest::API_VERSION,
'USER' => null,
'PWD' => null,
'SIGNATURE' => null,
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization',
'SOLUTIONTYPE' => null,
'LANDINGPAGE' => null,
'NOSHIPPING' => 2,
'ALLOWNOTE' => 1,
'ADDROVERRIDE' => 1,
'PAYMENTREQUEST_0_AMT' => '10.00',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'AUD',
'PAYMENTREQUEST_0_INVNUM' => '111',
'PAYMENTREQUEST_0_DESC' => 'Order Description',
'RETURNURL' => 'https://www.example.com/return',
'CANCELURL' => 'https://www.example.com/cancel',
'SUBJECT' => 'demo@example.com',
'HDRIMG' => 'https://www.example.com/header.jpg',
'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe',
'PAYMENTREQUEST_0_SHIPTOSTREET' => '123 NW Blvd',
'PAYMENTREQUEST_0_SHIPTOSTREET2' => 'Lynx Lane',
'PAYMENTREQUEST_0_SHIPTOCITY' => 'Topeka',
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'KS',
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'USA',
'PAYMENTREQUEST_0_SHIPTOZIP' => '66605',
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '555-555-5555',
'EMAIL' => 'test@email.com',
'BRANDNAME' => 'Dunder Mifflin Paper Company, Inc.',
'MAXAMT' => 123.45,
'PAYMENTREQUEST_0_TAXAMT' => null,
'PAYMENTREQUEST_0_SHIPPINGAMT' => null,
'PAYMENTREQUEST_0_HANDLINGAMT' => null,
'PAYMENTREQUEST_0_SHIPDISCAMT' => null,
'PAYMENTREQUEST_0_INSURANCEAMT' => null,
'LOGOIMG' => 'https://www.example.com/logo.jpg',
'CARTBORDERCOLOR' => 'CCCCCC',
'LOCALECODE' => 'EN',
'CUSTOMERSERVICENUMBER' => '1-801-FLOWERS',
'PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID' => 'billing@example.com',
);
$this->assertEquals($expected, $this->request->getData());
}
public function testGetDataWithItems()
{
$this->request->setItems(array(
array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10, 'code' => '123456'),
array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40),
));
$data = $this->request->getData();
$this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']);
$this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']);
$this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']);
$this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']);
$this->assertSame('123456', $data['L_PAYMENTREQUEST_0_NUMBER0']);
$this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']);
$this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']);
$this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']);
$this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']);
$this->assertSame('60.00', $data['PAYMENTREQUEST_0_ITEMAMT']);
}
public function testGetDataWithExtraOrderDetails()
{
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'noShipping' => 0,
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Inc.',
'taxAmount' => '2.00',
'shippingAmount' => '5.00',
'handlingAmount' => '1.00',
'shippingDiscount' => '-1.00',
'insuranceAmount' => '3.00',
));
$data = $this->request->getData();
$this->assertSame('2.00', $data['PAYMENTREQUEST_0_TAXAMT']);
$this->assertSame('5.00', $data['PAYMENTREQUEST_0_SHIPPINGAMT']);
$this->assertSame('1.00', $data['PAYMENTREQUEST_0_HANDLINGAMT']);
$this->assertSame('-1.00', $data['PAYMENTREQUEST_0_SHIPDISCAMT']);
$this->assertSame('3.00', $data['PAYMENTREQUEST_0_INSURANCEAMT']);
}
public function testHeaderImageUrl()
{
$this->assertSame($this->request, $this->request->setHeaderImageUrl('https://www.example.com/header.jpg'));
$this->assertSame('https://www.example.com/header.jpg', $this->request->getHeaderImageUrl());
$data = $this->request->getData();
$this->assertEquals('https://www.example.com/header.jpg', $data['HDRIMG']);
}
public function testMaxAmount()
{
$this->request->setMaxAmount(321.54);
$this->assertSame(321.54, $this->request->getMaxAmount());
$data = $this->request->getData();
$this->assertSame(321.54, $data['MAXAMT']);
}
public function testDataWithCallback()
{
$baseData = array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Incy.',
);
$shippingOptions = array(
new ShippingOption('First Class', 1.20, true, '1-2 days'),
new ShippingOption('Second Class', 0.70, false, '3-5 days'),
new ShippingOption('International', 3.50),
);
// with a default callback timeout
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
'shippingOptions' => $shippingOptions,
)));
$data = $this->request->getData();
$this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']);
$this->assertSame(ExpressInContextAuthorizeRequest::DEFAULT_CALLBACK_TIMEOUT, $data['CALLBACKTIMEOUT']);
$this->assertSame('First Class', $data['L_SHIPPINGOPTIONNAME0']);
$this->assertSame('1.20', $data['L_SHIPPINGOPTIONAMOUNT0']);
$this->assertSame('1', $data['L_SHIPPINGOPTIONISDEFAULT0']);
$this->assertSame('1-2 days', $data['L_SHIPPINGOPTIONLABEL0']);
$this->assertSame('Second Class', $data['L_SHIPPINGOPTIONNAME1']);
$this->assertSame('0.70', $data['L_SHIPPINGOPTIONAMOUNT1']);
$this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT1']);
$this->assertSame('3-5 days', $data['L_SHIPPINGOPTIONLABEL1']);
$this->assertSame('International', $data['L_SHIPPINGOPTIONNAME2']);
$this->assertSame('3.50', $data['L_SHIPPINGOPTIONAMOUNT2']);
$this->assertSame('0', $data['L_SHIPPINGOPTIONISDEFAULT2']);
// with a defined callback timeout
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
'callbackTimeout' => 10,
'shippingOptions' => $shippingOptions,
)));
$data = $this->request->getData();
$this->assertSame('https://www.example.com/calculate-shipping', $data['CALLBACK']);
$this->assertSame(10, $data['CALLBACKTIMEOUT']);
}
public function testDataWithCallbackAndNoDefaultShippingOption()
{
$baseData = array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Incy.',
);
$shippingOptions = array(
new ShippingOption('First Class', 1.20, false, '1-2 days'),
new ShippingOption('Second Class', 0.70, false, '3-5 days'),
new ShippingOption('International', 3.50),
);
// with a default callback timeout
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
'shippingOptions' => $shippingOptions,
)));
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('One of the supplied shipping options must be set as default');
$this->request->getData();
}
public function testNoAmount()
{
$baseData = array(// nothing here - should cause a certain exception
);
$this->request->initialize($baseData);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('The amount parameter is required');
$this->request->getData();
}
public function testAmountButNoReturnUrl()
{
$baseData = array(
'amount' => 10.00,
);
$this->request->initialize($baseData);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('The returnUrl parameter is required');
$this->request->getData();
}
public function testBadCallbackConfiguration()
{
$baseData = array(
'amount' => '10.00',
'currency' => 'AUD',
'transactionId' => '111',
'description' => 'Order Description',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'subject' => 'demo@example.com',
'headerImageUrl' => 'https://www.example.com/header.jpg',
'allowNote' => 0,
'addressOverride' => 0,
'brandName' => 'Dunder Mifflin Paper Company, Incy.',
);
$this->request->initialize(array_merge($baseData, array(
'callback' => 'https://www.example.com/calculate-shipping',
)));
// from the docblock on this exception -
// Thrown when a request is invalid or missing required fields.
// callback has been set but no shipping options so expect one of these:
$this->expectException(InvalidRequestException::class);
$this->request->getData();
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse;
class ExpressInContextAuthorizeResponseTest extends TestCase
{
public function testConstruct()
{
// response should decode URL format data
$response = new ExpressInContextAuthorizeResponse($this->getMockRequest(), 'example=value&foo=bar');
$this->assertEquals(array('example' => 'value', 'foo' => 'bar'), $response->getData());
}
public function testExpressPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('ExpressPurchaseSuccess.txt');
$request = $this->getMockRequest();
$request->shouldReceive('getTestMode')->once()->andReturn(true);
$response = new ExpressInContextAuthorizeResponse($request, $httpResponse->getBody());
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertSame('EC-42721413K79637829', $response->getTransactionReference());
$this->assertNull($response->getMessage());
$this->assertNull($response->getRedirectData());
$this->assertSame('https://www.sandbox.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl());
$this->assertSame('GET', $response->getRedirectMethod());
}
public function testExpressPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('ExpressPurchaseFailure.txt');
$response = new ExpressInContextAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody());
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Tests\TestCase;
class ExpressTransactionSearchRequestTest extends TestCase
{
/**
* @var ExpressTransactionSearchRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new ExpressTransactionSearchRequest($this->getHttpClient(), $this->getHttpRequest());
}
public function testGetData()
{
$startDate = '2015-01-01';
$endDate = '2016-01-01';
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'USD',
'startDate' => $startDate,
'endDate' => $endDate,
'salutation' => 'Mr.',
'firstName' => 'Jhon',
'middleName' => 'Carter',
'lastName' => 'Macgiver',
'suffix' => 'Jh',
'email' => 'test@email.com',
'receiver' => 'Patt Doret',
'receiptId' => '1111',
'transactionId' => 'XKCD',
'invoiceNumber' => '123456789',
'card' => array('number' => '376449047333005'),
'auctionItemNumber' => '321564',
'transactionClass' => 'Received',
'status' => 'Success',
'profileId' => '00000000000'
));
$data = $this->request->getData();
$startDate = new \DateTime($startDate);
$endDate = new \DateTime($endDate);
$this->assertSame('10.00', $data['AMT']);
$this->assertSame('USD', $data['CURRENCYCODE']);
$this->assertSame($startDate->format(\DateTime::ISO8601), $data['STARTDATE']);
$this->assertSame($endDate->format(\DateTime::ISO8601), $data['ENDDATE']);
$this->assertSame('Mr.', $data['SALUTATION']);
$this->assertSame('Jhon', $data['FIRSTNAME']);
$this->assertSame('Carter', $data['MIDDLENAME']);
$this->assertSame('Macgiver', $data['LASTNAME']);
$this->assertSame('Jh', $data['SUFFIX']);
$this->assertSame('test@email.com', $data['EMAIL']);
$this->assertSame('XKCD', $data['TRANSACTIONID']);
$this->assertSame('123456789', $data['INVNUM']);
$this->assertSame('376449047333005', $data['ACCT']);
$this->assertSame('321564', $data['AUCTIONITEMNUMBER']);
$this->assertSame('Received', $data['TRANSACTIONCLASS']);
$this->assertSame('Success', $data['STATUS']);
$this->assertSame('00000000000', $data['PROFILEID']);
}
public function testWithoutStartDate()
{
$this->request->initialize(array());
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('The startDate parameter is required');
$this->request->getData();
}
public function testAmountWithoutCurrency()
{
$this->request->setStartDate('2015-01-01');
$this->request->setAmount(150.00);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('The currency parameter is required');
$this->request->getData();
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class ExpressTransactionSearchResponseTest extends TestCase
{
public function testConstruct()
{
// response should decode URL format data
$response = new ExpressTransactionSearchResponse($this->getMockRequest(), 'ACK=Success&BUILD=18308778');
$this->assertEquals(
array('ACK' => 'Success', 'BUILD' => '18308778', 'payments' => array()),
$response->getData()
);
}
public function testExpressTransactionSearch()
{
$httpResponse = $this->getMockHttpResponse('ExpressTransactionSearchResponse.txt');
$response = new ExpressTransactionSearchResponse($this->getMockRequest(), $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertNull($response->getMessage());
$this->assertArrayHasKey('payments', $response->getData());
foreach ($response->getPayments() as $payment) {
$this->assertArrayHasKey('TIMESTAMP', $payment);
$this->assertArrayHasKey('TIMEZONE', $payment);
$this->assertArrayHasKey('TYPE', $payment);
$this->assertArrayHasKey('EMAIL', $payment);
$this->assertArrayHasKey('NAME', $payment);
$this->assertArrayHasKey('TRANSACTIONID', $payment);
$this->assertArrayHasKey('STATUS', $payment);
$this->assertArrayHasKey('AMT', $payment);
$this->assertArrayHasKey('CURRENCYCODE', $payment);
$this->assertArrayHasKey('FEEAMT', $payment);
$this->assertArrayHasKey('NETAMT', $payment);
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class ExpressVoidRequestTest extends TestCase
{
/**
* @var ExpressVoidRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new ExpressVoidRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'transactionReference' => 'ASDFASDFASDF',
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame('ASDFASDFASDF', $data['AUTHORIZATIONID']);
$this->assertSame('DoVoid', $data['METHOD']);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\PayPal\Message\FetchTransactionRequest;
use Omnipay\Tests\TestCase;
class FetchTransactionRequestTest extends TestCase
{
/**
* @var \Omnipay\PayPal\Message\FetchTransactionRequest
*/
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new FetchTransactionRequest($client, $request);
}
public function testGetData()
{
$this->request->setTransactionReference('ABC-123');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$expected = array();
$expected['METHOD'] = 'GetTransactionDetails';
$expected['TRANSACTIONID'] = 'ABC-123';
$expected['USER'] = 'testuser';
$expected['PWD'] = 'testpass';
$expected['SIGNATURE'] = 'SIG';
$expected['SUBJECT'] = 'SUB';
$expected['VERSION'] = RefundRequest::API_VERSION;
$this->assertEquals($expected, $this->request->getData());
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class ProAuthorizeRequestTest extends TestCase
{
/**
* @var ProAuthorizeRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new ProAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '10.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
)
);
}
public function testGetData()
{
$card = new CreditCard($this->getValidCard());
$card->setStartMonth(1);
$card->setStartYear(2000);
$this->request->setCard($card);
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$this->request->setClientIp('127.0.0.1');
$data = $this->request->getData();
$this->assertSame('DoDirectPayment', $data['METHOD']);
$this->assertSame('Authorization', $data['PAYMENTACTION']);
$this->assertSame('10.00', $data['AMT']);
$this->assertSame('USD', $data['CURRENCYCODE']);
$this->assertSame('abc123', $data['INVNUM']);
$this->assertSame('Sheep', $data['DESC']);
$this->assertSame('127.0.0.1', $data['IPADDRESS']);
$this->assertSame($card->getNumber(), $data['ACCT']);
$this->assertSame($card->getBrand(), $data['CREDITCARDTYPE']);
$this->assertSame($card->getExpiryDate('mY'), $data['EXPDATE']);
$this->assertSame('012000', $data['STARTDATE']);
$this->assertSame($card->getCvv(), $data['CVV2']);
$this->assertSame($card->getIssueNumber(), $data['ISSUENUMBER']);
$this->assertSame($card->getFirstName(), $data['FIRSTNAME']);
$this->assertSame($card->getLastName(), $data['LASTNAME']);
$this->assertSame($card->getEmail(), $data['EMAIL']);
$this->assertSame($card->getAddress1(), $data['STREET']);
$this->assertSame($card->getAddress2(), $data['STREET2']);
$this->assertSame($card->getCity(), $data['CITY']);
$this->assertSame($card->getState(), $data['STATE']);
$this->assertSame($card->getPostcode(), $data['ZIP']);
$this->assertSame($card->getCountry(), $data['COUNTRYCODE']);
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class ProPurchaseRequestTest extends TestCase
{
/**
* @var ProPurchaseRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new ProPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '10.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
)
);
}
public function testGetData()
{
$card = new CreditCard($this->getValidCard());
$card->setStartMonth(1);
$card->setStartYear(2000);
$this->request->setCard($card);
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$this->request->setClientIp('127.0.0.1');
$data = $this->request->getData();
$this->assertSame('DoDirectPayment', $data['METHOD']);
$this->assertSame('Sale', $data['PAYMENTACTION']);
$this->assertSame('10.00', $data['AMT']);
$this->assertSame('USD', $data['CURRENCYCODE']);
$this->assertSame('abc123', $data['INVNUM']);
$this->assertSame('Sheep', $data['DESC']);
$this->assertSame('127.0.0.1', $data['IPADDRESS']);
$this->assertSame($card->getNumber(), $data['ACCT']);
$this->assertSame($card->getBrand(), $data['CREDITCARDTYPE']);
$this->assertSame($card->getExpiryDate('mY'), $data['EXPDATE']);
$this->assertSame('012000', $data['STARTDATE']);
$this->assertSame($card->getCvv(), $data['CVV2']);
$this->assertSame($card->getIssueNumber(), $data['ISSUENUMBER']);
$this->assertSame($card->getFirstName(), $data['FIRSTNAME']);
$this->assertSame($card->getLastName(), $data['LASTNAME']);
$this->assertSame($card->getEmail(), $data['EMAIL']);
$this->assertSame($card->getAddress1(), $data['STREET']);
$this->assertSame($card->getAddress2(), $data['STREET2']);
$this->assertSame($card->getCity(), $data['CITY']);
$this->assertSame($card->getState(), $data['STATE']);
$this->assertSame($card->getPostcode(), $data['ZIP']);
$this->assertSame($card->getCountry(), $data['COUNTRYCODE']);
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\PayPal\Message\RefundRequest;
use Omnipay\Tests\TestCase;
class RefundRequestTest extends TestCase
{
/**
* @var \Omnipay\PayPal\Message\RefundRequest
*/
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RefundRequest($client, $request);
}
/**
* @dataProvider provideRefundTypes
*/
public function testGetData($type, $amount)
{
$this->request->setAmount($amount);
$this->request->setCurrency('USD');
$this->request->setTransactionReference('ABC-123');
$this->request->setUsername('testuser');
$this->request->setPassword('testpass');
$this->request->setSignature('SIG');
$this->request->setSubject('SUB');
$expected = array();
$expected['REFUNDTYPE'] = $type;
$expected['METHOD'] = 'RefundTransaction';
$expected['TRANSACTIONID'] = 'ABC-123';
$expected['USER'] = 'testuser';
$expected['PWD'] = 'testpass';
$expected['SIGNATURE'] = 'SIG';
$expected['SUBJECT'] = 'SUB';
$expected['VERSION'] = RefundRequest::API_VERSION;
// $amount will be a formatted string, and '0.00' evaluates to true
if ((float)$amount) {
$expected['AMT'] = $amount;
$expected['CURRENCYCODE'] = 'USD';
}
$this->assertEquals($expected, $this->request->getData());
}
public function provideRefundTypes()
{
return array(
'Partial' => array('Partial', '1.23'),
// All amounts must include decimals or be a float if the currency supports decimals.
'Full' => array('Full', '0.00'),
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class ResponseTest extends TestCase
{
public function testConstruct()
{
// response should decode URL format data
$response = new Response($this->getMockRequest(), 'example=value&foo=bar');
$this->assertEquals(array('example' => 'value', 'foo' => 'bar'), $response->getData());
}
public function testProPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('ProPurchaseSuccess.txt');
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
$this->assertFalse($response->isPending());
$this->assertTrue($response->isSuccessful());
$this->assertSame('96U93778BD657313D', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testProPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('ProPurchaseFailure.txt');
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
$this->assertFalse($response->isPending());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This transaction cannot be processed. Please enter a valid credit card expiration year.', $response->getMessage());
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class RestAuthorizeRequestTest extends TestCase
{
/**
* @var ProPurchaseRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new RestAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '10.00',
'currency' => 'USD',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
)
);
}
public function testGetDataWithoutCard()
{
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$data = $this->request->getData();
$this->assertSame('authorize', $data['intent']);
$this->assertSame('paypal', $data['payer']['payment_method']);
$this->assertSame('10.00', $data['transactions'][0]['amount']['total']);
$this->assertSame('USD', $data['transactions'][0]['amount']['currency']);
$this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']);
// Funding instruments must not be set, otherwise paypal API will give error 500.
$this->assertArrayNotHasKey('funding_instruments', $data['payer']);
$this->assertSame('https://www.example.com/return', $data['redirect_urls']['return_url']);
$this->assertSame('https://www.example.com/cancel', $data['redirect_urls']['cancel_url']);
}
public function testGetDataWithCard()
{
$card = new CreditCard($this->getValidCard());
$card->setStartMonth(1);
$card->setStartYear(2000);
$this->request->setCard($card);
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$this->request->setClientIp('127.0.0.1');
$data = $this->request->getData();
$this->assertSame('authorize', $data['intent']);
$this->assertSame('credit_card', $data['payer']['payment_method']);
$this->assertSame('10.00', $data['transactions'][0]['amount']['total']);
$this->assertSame('USD', $data['transactions'][0]['amount']['currency']);
$this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']);
$this->assertSame($card->getNumber(), $data['payer']['funding_instruments'][0]['credit_card']['number']);
$this->assertSame($card->getBrand(), $data['payer']['funding_instruments'][0]['credit_card']['type']);
$this->assertSame($card->getExpiryMonth(), $data['payer']['funding_instruments'][0]['credit_card']['expire_month']);
$this->assertSame($card->getExpiryYear(), $data['payer']['funding_instruments'][0]['credit_card']['expire_year']);
$this->assertSame($card->getCvv(), $data['payer']['funding_instruments'][0]['credit_card']['cvv2']);
$this->assertSame($card->getFirstName(), $data['payer']['funding_instruments'][0]['credit_card']['first_name']);
$this->assertSame($card->getLastName(), $data['payer']['funding_instruments'][0]['credit_card']['last_name']);
$this->assertSame($card->getAddress1(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line1']);
$this->assertSame($card->getAddress2(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line2']);
$this->assertSame($card->getCity(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['city']);
$this->assertSame($card->getState(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['state']);
$this->assertSame($card->getPostcode(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['postal_code']);
$this->assertSame($card->getCountry(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['country_code']);
}
public function testGetDataWithItems()
{
$this->request->setAmount('50.00');
$this->request->setCurrency('USD');
$this->request->setItems(array(
array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10),
array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40),
));
$data = $this->request->getData();
$transactionData = $data['transactions'][0];
$this->assertSame('Floppy Disk', $transactionData['item_list']['items'][0]['name']);
$this->assertSame('MS-DOS', $transactionData['item_list']['items'][0]['description']);
$this->assertSame(2, $transactionData['item_list']['items'][0]['quantity']);
$this->assertSame('10.00', $transactionData['item_list']['items'][0]['price']);
$this->assertSame('CD-ROM', $transactionData['item_list']['items'][1]['name']);
$this->assertSame('Windows 95', $transactionData['item_list']['items'][1]['description']);
$this->assertSame(1, $transactionData['item_list']['items'][1]['quantity']);
$this->assertSame('40.00', $transactionData['item_list']['items'][1]['price']);
$this->assertSame('50.00', $transactionData['amount']['total']);
$this->assertSame('USD', $transactionData['amount']['currency']);
}
public function testDescription()
{
$this->request->setTransactionId('');
$this->request->setDescription('');
$this->assertEmpty($this->request->getDescription());
$this->request->setTransactionId('');
$this->request->setDescription('Sheep');
$this->assertEquals('Sheep', $this->request->getDescription());
$this->request->setTransactionId('abc123');
$this->request->setDescription('');
$this->assertEquals('abc123', $this->request->getDescription());
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$this->assertEquals('abc123 : Sheep', $this->request->getDescription());
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class RestAuthorizeResponseTest extends TestCase
{
public function testRestPurchaseWithoutCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestPurchaseWithoutCardSuccess.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestAuthorizeResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('PAY-3TJ47806DA028052TKTQGVYI', $response->getTransactionReference());
$this->assertNull($response->getMessage());
$this->assertNull($response->getRedirectData());
$this->assertSame('GET', $response->getRedirectMethod());
$this->assertSame('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5KV58254GL528393N', $response->getRedirectUrl());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestCancelSubscriptionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestCancelSubscriptionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestCancelSubscriptionRequest($client, $request);
$this->request->initialize(array(
'transactionReference' => 'ABC-123',
'description' => 'Cancel this subscription',
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('Cancel this subscription', $data['note']);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class RestCompletePurchaseRequestTest extends TestCase
{
/**
* @var RestCompletePurchaseRequest
*/
private $request;
public function setUp()
{
parent::setUp();
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestCompletePurchaseRequest($client, $request);
$this->request->initialize(array());
}
public function testGetData()
{
$this->request->setTransactionReference('abc123');
$this->request->setPayerId('Payer12345');
$data = $this->request->getData();
$this->assertSame('Payer12345', $data['payer_id']);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestCompleteSubscriptionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestCompleteSubscriptionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestCompleteSubscriptionRequest($client, $request);
$this->request->initialize(array(
'transactionReference' => 'ABC-123',
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals(array(), $data);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class RestCreateCardRequestTest extends TestCase
{
/** @var RestCreateCardRequest */
protected $request;
/** @var CreditCard */
protected $card;
public function setUp()
{
parent::setUp();
$this->request = new RestCreateCardRequest($this->getHttpClient(), $this->getHttpRequest());
$card = $this->getValidCard();
$this->card = new CreditCard($card);
$this->request->initialize(array('card' => $card));
}
public function testGetData()
{
$card = $this->card;
$data = $this->request->getData();
$this->assertSame($card->getNumber(), $data['number']);
$this->assertSame($card->getBrand(), $data['type']);
$this->assertSame($card->getExpiryMonth(), $data['expire_month']);
$this->assertSame($card->getExpiryYear(), $data['expire_year']);
$this->assertSame($card->getCvv(), $data['cvv2']);
$this->assertSame($card->getFirstName(), $data['first_name']);
$this->assertSame($card->getLastName(), $data['last_name']);
$this->assertSame($card->getAddress1(), $data['billing_address']['line1']);
$this->assertSame($card->getAddress2(), $data['billing_address']['line2']);
$this->assertSame($card->getCity(), $data['billing_address']['city']);
$this->assertSame($card->getState(), $data['billing_address']['state']);
$this->assertSame($card->getPostcode(), $data['billing_address']['postal_code']);
$this->assertSame($card->getCountry(), $data['billing_address']['country_code']);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestCreatePlanRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestCreatePlanRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestCreatePlanRequest($client, $request);
$this->request->initialize(array(
'name' => 'Super Duper Billing Plan',
'description' => 'Test Billing Plan',
'type' => RestGateway::BILLING_PLAN_TYPE_FIXED,
'paymentDefinitions' => array(
array(
'name' => 'Monthly Payments',
'type' => RestGateway::PAYMENT_REGULAR,
'frequency' => RestGateway::BILLING_PLAN_FREQUENCY_MONTH,
'frequency_interval' => 1,
'cycles' => 12,
'amount' => array(
'value' => 10.00,
'currency' => 'USD',
)
)
),
'merchantPreferences' => array(
'name' => 'asdf',
),
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('Super Duper Billing Plan', $data['name']);
$this->assertEquals(RestGateway::BILLING_PLAN_TYPE_FIXED, $data['type']);
$this->assertEquals('Monthly Payments', $data['payment_definitions'][0]['name']);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestCreateSubscriptionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestCreateSubscriptionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestCreateSubscriptionRequest($client, $request);
$this->request->initialize(array(
'name' => 'Test Subscription',
'description' => 'Test Billing Subscription',
'startDate' => new \DateTime('now', new \DateTimeZone('UTC')),
'planId' => 'ABC-123',
'payerDetails' => array(
'payment_method' => 'paypal',
),
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('Test Subscription', $data['name']);
$this->assertEquals('Test Billing Subscription', $data['description']);
$this->assertEquals('ABC-123', $data['plan']['id']);
$this->assertEquals('paypal', $data['payer']['payment_method']);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class RestDeleteCardRequestTest extends TestCase
{
/** @var RestDeleteCardRequest */
private $request;
/** @var CreditCard */
private $card;
public function setUp()
{
parent::setUp();
$this->request = new RestDeleteCardRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array('cardReference' => 'CARD-TEST123'));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertTrue(is_array($data));
$this->assertEmpty($data);
}
public function testEndpoint()
{
$this->assertStringEndsWith('/vault/credit-cards/CARD-TEST123', $this->request->getEndpoint());
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class RestFetchPurchaseRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestFetchPurchaseRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestFetchPurchaseRequest($client, $request);
}
public function testEndpoint()
{
$this->request->setTransactionReference('ABC-123');
$this->assertStringEndsWith('/payments/payment/ABC-123', $this->request->getEndpoint());
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class RestFetchTransactionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestFetchTransactionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestFetchTransactionRequest($client, $request);
}
public function testGetData()
{
$this->request->setTransactionReference('ABC-123');
$data = $this->request->getData();
$this->assertEquals(array(), $data);
}
public function testEndpoint()
{
$this->request->setTransactionReference('ABC-123');
$this->assertStringEndsWith('/payments/sale/ABC-123', $this->request->getEndpoint());
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class RestListPlanRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestListPlanRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestListPlanRequest($client, $request);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertArrayHasKey('page',$data);
$this->assertArrayHasKey('status',$data);
$this->assertArrayHasKey('page_size',$data);
$this->assertArrayHasKey('total_required',$data);
}
public function testEndpoint()
{
$this->assertStringEndsWith('/payments/billing-plans', $this->request->getEndpoint());
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;
class RestPurchaseRequestTest extends TestCase
{
/** @var RestPurchaseRequest */
private $request;
public function testGetData()
{
$card = new CreditCard($this->getValidCard());
$card->setStartMonth(1);
$card->setStartYear(2000);
$this->request = new RestPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'USD',
'card' => $card
));
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$this->request->setClientIp('127.0.0.1');
$data = $this->request->getData();
$this->assertSame('sale', $data['intent']);
$this->assertSame('credit_card', $data['payer']['payment_method']);
$this->assertSame('10.00', $data['transactions'][0]['amount']['total']);
$this->assertSame('USD', $data['transactions'][0]['amount']['currency']);
$this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']);
$this->assertSame($card->getNumber(), $data['payer']['funding_instruments'][0]['credit_card']['number']);
$this->assertSame($card->getBrand(), $data['payer']['funding_instruments'][0]['credit_card']['type']);
$this->assertSame($card->getExpiryMonth(), $data['payer']['funding_instruments'][0]['credit_card']['expire_month']);
$this->assertSame($card->getExpiryYear(), $data['payer']['funding_instruments'][0]['credit_card']['expire_year']);
$this->assertSame($card->getCvv(), $data['payer']['funding_instruments'][0]['credit_card']['cvv2']);
$this->assertSame($card->getFirstName(), $data['payer']['funding_instruments'][0]['credit_card']['first_name']);
$this->assertSame($card->getLastName(), $data['payer']['funding_instruments'][0]['credit_card']['last_name']);
$this->assertSame($card->getAddress1(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line1']);
$this->assertSame($card->getAddress2(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line2']);
$this->assertSame($card->getCity(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['city']);
$this->assertSame($card->getState(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['state']);
$this->assertSame($card->getPostcode(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['postal_code']);
$this->assertSame($card->getCountry(), $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['country_code']);
}
public function testGetDataWithCardRef()
{
$this->request = new RestPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array(
'amount' => '10.00',
'currency' => 'USD',
'cardReference' => 'CARD-123',
));
$this->request->setTransactionId('abc123');
$this->request->setDescription('Sheep');
$this->request->setClientIp('127.0.0.1');
$data = $this->request->getData();
$this->assertSame('sale', $data['intent']);
$this->assertSame('credit_card', $data['payer']['payment_method']);
$this->assertSame('10.00', $data['transactions'][0]['amount']['total']);
$this->assertSame('USD', $data['transactions'][0]['amount']['currency']);
$this->assertSame('abc123 : Sheep', $data['transactions'][0]['description']);
$this->assertSame('CARD-123', $data['payer']['funding_instruments'][0]['credit_card_token']['credit_card_id']);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestReactivateSubscriptionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestReactivateSubscriptionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestReactivateSubscriptionRequest($client, $request);
$this->request->initialize(array(
'transactionReference' => 'ABC-123',
'description' => 'Reactivate this subscription',
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('Reactivate this subscription', $data['note']);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
class RestResponseTest extends TestCase
{
public function testPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestPurchaseSuccess.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('RestPurchaseFailure.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertSame('Invalid request - see details', $response->getMessage());
}
public function testCompletePurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestCompletePurchaseSuccess.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('9EA05739TH369572R', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testCompletePurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('RestCompletePurchaseFailure.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertSame('This request is invalid due to the current state of the payment', $response->getMessage());
}
public function testTokenFailure()
{
$httpResponse = $this->getMockHttpResponse('RestTokenFailure.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertFalse($response->isSuccessful());
$this->assertSame('Client secret does not match for this client', $response->getMessage());
}
public function testAuthorizeSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestAuthorizationSuccess.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('58N7596879166930B', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testCreateCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestCreateCardSuccess.txt');
$data = json_decode($httpResponse->getBody()->getContents(), true);
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());
$this->assertNull($response->getMessage());
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestSearchTransactionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestSearchTransactionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestSearchTransactionRequest($client, $request);
$this->request->initialize(array(
'agreementId' => 'ABC-123',
'startDate' => '2015-09-01',
'endDate' => '2015-09-30',
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('2015-09-01', $data['start_date']);
$this->assertEquals('2015-09-30', $data['end_date']);
}
public function testEndpoint()
{
$this->assertStringEndsWith('/payments/billing-agreements/ABC-123/transactions', $this->request->getEndpoint());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestSuspendSubscriptionRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestSuspendSubscriptionRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestSuspendSubscriptionRequest($client, $request);
$this->request->initialize(array(
'transactionReference' => 'ABC-123',
'description' => 'Suspend this subscription',
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('Suspend this subscription', $data['note']);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Omnipay\PayPal\Message;
use Omnipay\Tests\TestCase;
use Omnipay\PayPal\RestGateway;
class RestUpdatePlanRequestTest extends TestCase
{
/** @var \Omnipay\PayPal\Message\RestUpdatePlanRequest */
private $request;
public function setUp()
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
$this->request = new RestUpdatePlanRequest($client, $request);
$this->request->initialize(array(
'transactionReference' => 'ABC-123',
'state' => 'ACTIVE',
));
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertEquals('/', $data[0]['path']);
$this->assertEquals('ACTIVE', $data[0]['value']['state']);
}
}

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Wed, 20 Feb 2013 13:55:50 GMT
Server: Apache
Content-Length: 214
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2013%2d02%2d20T13%3a55%3a50Z&CORRELATIONID=73310039452e7&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10410&L_SHORTMESSAGE0=Invalid%20token&L_LONGMESSAGE0=Invalid%20token%2e&L_SEVERITYCODE0=Error

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Wed, 20 Feb 2013 13:55:50 GMT
Server: Apache
Content-Length: 214
Connection: close
Content-Type: text/plain; charset=utf-8
TOKEN=ASDFASDFASDF&SUCCESSPAGEREDIRECTREQUESTED=false&TIMESTAMP=2016%2d09%2d12T14%3a06%3a12Z&CORRELATIONID=31e509fc8f6a8&ACK=Failure&VERSION=119%2e0&BUILD=25037053&L_ERRORCODE0=10486&L_SHORTMESSAGE0=This%20transaction%20couldn%27t%20be%20completed%2e&L_LONGMESSAGE0=This%20transaction%20couldn%27t%20be%20completed%2e%20Please%20redirect%20your%20customer%20to%20PayPal%2e&L_SEVERITYCODE0=Error

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Wed, 20 Feb 2013 13:54:27 GMT
Server: Apache
Content-Length: 869
Connection: close
Content-Type: text/plain; charset=utf-8
TOKEN=EC%2d96V667110D1727015&SUCCESSPAGEREDIRECTREQUESTED=true&TIMESTAMP=2013%2d02%2d20T13%3a54%3a28Z&CORRELATIONID=f78b888897f8a&ACK=Success&VERSION=85%2e0&BUILD=5060305&INSURANCEOPTIONSELECTED=false&SHIPPINGOPTIONISDEFAULT=false&PAYMENTINFO_0_TRANSACTIONID=8RM57414KW761861W&PAYMENTINFO_0_RECEIPTID=0368%2d2088%2d8643%2d7560&PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&PAYMENTINFO_0_PAYMENTTYPE=instant&PAYMENTINFO_0_ORDERTIME=2013%2d02%2d20T13%3a54%3a03Z&PAYMENTINFO_0_AMT=10%2e00&PAYMENTINFO_0_FEEAMT=0%2e59&PAYMENTINFO_0_TAXAMT=0%2e00&PAYMENTINFO_0_CURRENCYCODE=USD&PAYMENTINFO_0_PAYMENTSTATUS=Completed&PAYMENTINFO_0_PENDINGREASON=None&PAYMENTINFO_0_REASONCODE=None&PAYMENTINFO_0_PROTECTIONELIGIBILITY=Ineligible&PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=None&PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=VZTRGMSKHHAEW&PAYMENTINFO_0_ERRORCODE=0&PAYMENTINFO_0_ACK=Success

View File

@@ -0,0 +1,7 @@
HTTP/1.1 200 OK
Date: 05 Apr 2007 23:44:11 GMT
Server: Apache
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2007%2d04%2d05T23%3a44%3a11Z&CORRELATIONID=6b174e9bac3b3&ACK=Failure&VERSION=85.0&BUILD=11235635&L_ERRORCODE0=10414&L_SHORTMESSAGE0=Transaction%20refused%20because%20of%20an%20invalid%20argument.%20See%20additional%20error%20messages%20for%20details.&L_LONGMESSAGE0=The%20amount%20exceeds%20the%20maximum%20amount%20for%20a%20single%20transaction.&L_SEVERITYCODE0=Error

View File

@@ -0,0 +1,7 @@
HTTP/1.1 200 OK
Date: 05 Apr 2007 23:44:11 GMT
Server: Apache
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2007%2d04%2d05T23%3a44%3a11Z&CORRELATIONID=6b174e9bac3b3&ACK=Success&VERSION=XX%2e000000&BUILD=1%2e0006&TOKEN=EC%2d1NK66318YB717835M&EMAIL=YourSandboxBuyerAccountEmail&PAYERID=7AKUSARZ7SAT8&PAYERSTATUS=verified&FIRSTNAME=Bernard&LASTNAME=Black&COUNTRYCODE=UK&BUSINESS=Black%20Books&PAYMENTREQUEST_0_SHIPTONAME=Bernard%20Black&PAYMENTREQUEST_0_SHIPTOSTREET=13%20Little%20Bevan%20Street&PAYMENTREQUEST_0_SHIPTOCITY=London&PAYMENTREQUEST_0_SHIPTOSTATE=&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=UK&PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United%20Kingdom&PAYMENTREQUEST_0_SHIPTOZIP=WC1&PAYMENTREQUEST_0_ADDRESSID=1234&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 19:21:05 GMT
Server: Apache
Content-Length: 292
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2013%2d02%2d15T19%3a21%3a06Z&CORRELATIONID=2b58be2b8e60e&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10525&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20The%20amount%20to%20be%20charged%20is%20zero%2e&L_SEVERITYCODE0=Error

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 19:19:21 GMT
Server: Apache
Content-Length: 136
Connection: close
Content-Type: text/plain; charset=utf-8
TOKEN=EC%2d42721413K79637829&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 19:21:05 GMT
Server: Apache
Content-Length: 292
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2013%2d02%2d15T19%3a21%3a06Z&CORRELATIONID=2b58be2b8e60e&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10525&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20The%20amount%20to%20be%20charged%20is%20zero%2e&L_SEVERITYCODE0=Error

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 19:19:21 GMT
Server: Apache
Content-Length: 136
Connection: close
Content-Type: text/plain; charset=utf-8
TOKEN=EC%2d42721413K79637829&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 19:19:21 GMT
Server: Apache
Content-Length: 136
Connection: close
Content-Type: text/plain; charset=utf-8
AUTHORIZATIONID=ASDFASDFASDF&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Failure&VERSION=85%2e0&BUILD=5060305

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 19:19:21 GMT
Server: Apache
Content-Length: 136
Connection: close
Content-Type: text/plain; charset=utf-8
AUTHORIZATIONID=ASDFASDFASDF&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 18:49:26 GMT
Server: Apache
Content-Length: 340
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2013%2d02%2d15T18%3a49%3a27Z&CORRELATIONID=ec641b50c33b0&ACK=Failure&VERSION=85%2e0&BUILD=5060305&L_ERRORCODE0=10562&L_SHORTMESSAGE0=Invalid%20Data&L_LONGMESSAGE0=This%20transaction%20cannot%20be%20processed%2e%20Please%20enter%20a%20valid%20credit%20card%20expiration%20year%2e&L_SEVERITYCODE0=Error&AMT=150%2e04&CURRENCYCODE=USD

View File

@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Date: Fri, 15 Feb 2013 18:38:31 GMT
Server: Apache
Content-Length: 190
Connection: close
Content-Type: text/plain; charset=utf-8
TIMESTAMP=2013%2d02%2d15T18%3a38%3a36Z&CORRELATIONID=541737dc565cb&ACK=Success&VERSION=85%2e0&BUILD=5060305&AMT=10%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=96U93778BD657313D

View File

@@ -0,0 +1,12 @@
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=3224
Paypal-Debug-Id: 2a1b9202663bc
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=206&TopLevelTxnStartTime=14701b4cb42&Host=slcsbjm1.slc.paypal.com&pid=20119
CORRELATION-ID: 2a1b9202663bc
Content-Language: *
Date: Fri, 04 Jul 2014 14:09:00 GMT
Content-Type: application/json
Content-Length: 1435
{"id":"PAY-66G66446716792522KO3LK4Y","create_time":"2014-07-04T14:08:51Z","update_time":"2014-07-04T14:09:01Z","state":"approved","intent":"authorize","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"mastercard","number":"xxxxxxxxxxxx5559","expire_month":"12","expire_year":"2018","first_name":"Betsy","last_name":"Buyer"}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment transaction description.","related_resources":[{"authorization":{"id":"58N7596879166930B","create_time":"2014-07-04T14:08:51Z","update_time":"2014-07-04T14:09:01Z","state":"authorized","amount":{"total":"7.47","currency":"USD"},"parent_payment":"PAY-66G66446716792522KO3LK4Y","valid_until":"2014-08-02T14:08:51Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B/capture","rel":"capture","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B/void","rel":"void","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-66G66446716792522KO3LK4Y","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-66G66446716792522KO3LK4Y","rel":"self","method":"GET"}]}

View File

@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=127
Paypal-Debug-Id: 030d6a098c7c5
SERVER_INFO: paymentsplatformserv:v1.payments.authorization&CalThreadId=15946&TopLevelTxnStartTime=14701ba0b41&Host=slcsbjm3.slc.paypal.com&pid=15797
CORRELATION-ID: 030d6a098c7c5
Content-Language: *
Date: Fri, 04 Jul 2014 14:14:42 GMT
Content-Type: application/json
Content-Length: 724
{"id":"9EP22596VU4085001","create_time":"2014-07-04T14:14:35Z","update_time":"2014-07-04T14:14:42Z","amount":{"total":"7.47","currency":"USD"},"is_final_capture":false,"state":"completed","parent_payment":"PAY-66G66446716792522KO3LK4Y","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/capture/9EP22596VU4085001","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/capture/9EP22596VU4085001/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/authorization/58N7596879166930B","rel":"authorization","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-66G66446716792522KO3LK4Y","rel":"parent_payment","method":"GET"}]}

View File

@@ -0,0 +1,12 @@
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbplatformapiserv3002.slc.paypal.com;threadId=533
Paypal-Debug-Id: 65f24674659dc
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=166&TopLevelTxnStartTime=14b8c851ff1&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=12653
Content-Language: *
Date: Sun, 15 Feb 2015 09:15:09 GMT
Connection: close, close
Content-Type: application/json
Content-Length: 235
{"name":"PAYMENT_STATE_INVALID","message":"This request is invalid due to the current state of the payment","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID","debug_id":"65f24674659dc"}

View File

@@ -0,0 +1,11 @@
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=216
Paypal-Debug-Id: 539b1c0678b08
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=4342&TopLevelTxnStartTime=14b8c84b1f3&Host=slcsbpaymentsplatformserv3002.slc.paypal.com&pid=8929
Content-Language: *
Date: Sun, 15 Feb 2015 09:14:43 GMT
Content-Type: application/json
Content-Length: 1632
{"id":"PAY-4BF374015W374910XKTQGGBZ","create_time":"2015-02-15T09:12:36Z","update_time":"2015-02-15T09:14:43Z","state":"approved","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"email":"test.buyer@example.com","first_name":"Betsy","last_name":"Buyer","payer_id":"Payer12345","shipping_address":{"line1":"test","city":"","state":"","postal_code":"123456","country_code":"US","recipient_name":"Buyer Betsy"}}},"transactions":[{"amount":{"total":"100.00","currency":"USD","details":{"subtotal":"100.00","fee":"3.90"}},"description":"The product description","item_list":{"items":[{"name":"Item 1","price":"100.00","currency":"USD","quantity":"1","description":"Standard Item"}],"shipping_address":{"recipient_name":"Buyer Betsy","line1":"test","city":"","state":"","postal_code":"123456","country_code":"US"}},"related_resources":[{"sale":{"id":"9EA05739TH369572R","create_time":"2015-02-15T09:12:36Z","update_time":"2015-02-15T09:14:43Z","amount":{"total":"100.00","currency":"USD"},"payment_mode":"INSTANT_TRANSFER","state":"completed","protection_eligibility":"INELIGIBLE","parent_payment":"PAY-4BF374015W374910XKTQGGBZ","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/9EA05739TH369572R","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/9EA05739TH369572R/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4BF374015W374910XKTQGGBZ","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4BF374015W374910XKTQGGBZ","rel":"self","method":"GET"}]}

View File

@@ -0,0 +1,12 @@
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=39734
Paypal-Debug-Id: 17a8320884bba
Content-Language: *
CORRELATION-ID: 17a8320884bba
Date: Fri, 04 Jul 2014 14:50:33 GMT
SERVER_INFO: vaultplatformserv:v1.vault.credit-card&CalThreadId=76352&TopLevelTxnStartTime=14701dafae7&Host=slcsbvaultplatformserv501.slc.paypal.com&pid=19516
Content-Type: application/json
Content-Length: 690
{"id":"CARD-70E78145XN686604FKO3L6OQ","state":"ok","payer_id":"user12345","type":"visa","number":"xxxxxxxxxxxx0331","expire_month":"11","expire_year":"2018","first_name":"Betsy","last_name":"Buyer","valid_until":"2017-07-03T00:00:00Z","create_time":"2014-07-04T14:50:34Z","update_time":"2014-07-04T14:50:34Z","links":[{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-70E78145XN686604FKO3L6OQ","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-70E78145XN686604FKO3L6OQ","rel":"delete","method":"DELETE"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-70E78145XN686604FKO3L6OQ","rel":"patch","method":"PATCH"}]}

View File

@@ -0,0 +1,20 @@
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=76018
Paypal-Debug-Id: 965491cb1a1e5
SERVER_INFO: paymentsplatformserv:v1.payments.sale&CalThreadId=129&TopLevelTxnStartTime=14701c36ef9&Host=slcsbjm3.slc.paypal.com&pid=15797
CORRELATION-ID: 965491cb1a1e5
Content-Language: *
Date: Fri, 04 Jul 2014 14:24:52 GMT
Content-Type: application/json
{
"id": "I-0LN988D3JACS",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS",
"rel": "self",
"method": "GET"
}
]
}

View File

@@ -0,0 +1,53 @@
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=1534
Paypal-Debug-Id: 98cbd3ab19dfe
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=129&TopLevelTxnStartTime=146fc9074ec&Host=slcsbjm3.slc.paypal.com&pid=15797
CORRELATION-ID: 98cbd3ab19dfe
Content-Language: *
Date: Thu, 03 Jul 2014 14:11:10 GMT
Content-Type: application/json
{
"id": "PAY-0WB587530N302915SKXWVCSQ",
"create_time": "2015-09-07T08:56:42Z",
"update_time": "2015-09-07T08:56:42Z",
"state": "created",
"intent": "sale",
"payer": {
"payment_method": "paypal",
"payer_info": {
"shipping_address": []
}
},
"transactions": [
{
"amount": {
"total": "10.00",
"currency": "AUD",
"details": {
"subtotal": "10.00"
}
},
"description": "This is a test purchase transaction.",
"related_resources": []
}
],
"links": [
{
"href": "https:\/\/api.sandbox.paypal.com\/v1\/payments\/payment\/PAY-0WB587530N302915SKXWVCSQ",
"rel": "self",
"method": "GET"
},
{
"href": "https:\/\/www.sandbox.paypal.com\/cgi-bin\/webscr?cmd=_express-checkout&token=EC-3DR71034MD528800J",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "https:\/\/api.sandbox.paypal.com\/v1\/payments\/payment\/PAY-0WB587530N302915SKXWVCSQ\/execute",
"rel": "execute",
"method": "POST"
}
]
}

View File

@@ -0,0 +1,7 @@
HTTP/1.1 204 OK
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=3205
Paypal-Debug-Id: 217a9ddefd384
SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=91&TopLevelTxnStartTime=146fbfe679a&Host=slcsbidensectoken502.slc.paypal.com&pid=29059
CORRELATION-ID: 217a9ddefd384
Date: Thu, 03 Jul 2014 11:31:32 GMT

View File

@@ -0,0 +1,14 @@
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=38554
Paypal-Debug-Id: b31c6360606e6
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=235&TopLevelTxnStartTime=146fc97eb2a&Host=slcsbjm2.slc.paypal.com&pid=14594
CORRELATION-ID: b31c6360606e6
Content-Language: *
Date: Thu, 03 Jul 2014 14:19:12 GMT
Connection: close
Content-Type: application/json
Content-Length: 290
Connection: close
{"name":"VALIDATION_ERROR","details":[{"field":"payer.funding_instruments[0].credit_card.number","issue":"Value is invalid"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"b31c6360606e6"}

View File

@@ -0,0 +1,12 @@
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=1534
Paypal-Debug-Id: 98cbd3ab19dfe
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=129&TopLevelTxnStartTime=146fc9074ec&Host=slcsbjm3.slc.paypal.com&pid=15797
CORRELATION-ID: 98cbd3ab19dfe
Content-Language: *
Date: Thu, 03 Jul 2014 14:11:10 GMT
Content-Type: application/json
Content-Length: 1243
{"id":"PAY-6RT04683U7444573DKO2WI6A","create_time":"2014-07-03T14:11:04Z","update_time":"2014-07-03T14:11:10Z","state":"approved","intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"mastercard","number":"xxxxxxxxxxxx5559","expire_month":"12","expire_year":"2018","first_name":"Betsy","last_name":"Buyer"}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment transaction description.","related_resources":[{"sale":{"id":"44E89981F8714392Y","create_time":"2014-07-03T14:11:04Z","update_time":"2014-07-03T14:11:10Z","state":"completed","amount":{"total":"7.47","currency":"USD"},"parent_payment":"PAY-6RT04683U7444573DKO2WI6A","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/44E89981F8714392Y","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/44E89981F8714392Y/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RT04683U7444573DKO2WI6A","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RT04683U7444573DKO2WI6A","rel":"self","method":"GET"}]}

View File

@@ -0,0 +1,11 @@
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=383
Paypal-Debug-Id: b4dc1c6623f68
SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=166&TopLevelTxnStartTime=14b8ca1806f&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=12653
Content-Language: *
Date: Sun, 15 Feb 2015 09:46:09 GMT
Content-Type: application/json
Content-Length: 894
{"id":"PAY-3TJ47806DA028052TKTQGVYI","create_time":"2015-02-15T09:46:09Z","update_time":"2015-02-15T09:46:09Z","state":"created","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"shipping_address":{}}},"transactions":[{"amount":{"total":"199.00","currency":"USD","details":{"subtotal":"199.00"}},"description":"Product 1","item_list":{"items":[{"name":"Item 1","price":"199.00","currency":"USD","quantity":"1","description":"Item Description"}]},"related_resources":[]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3TJ47806DA028052TKTQGVYI","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5KV58254GL528393N","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3TJ47806DA028052TKTQGVYI/execute","rel":"execute","method":"POST"}]}

View File

@@ -0,0 +1,12 @@
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=76018
Paypal-Debug-Id: 965491cb1a1e5
SERVER_INFO: paymentsplatformserv:v1.payments.sale&CalThreadId=129&TopLevelTxnStartTime=14701c36ef9&Host=slcsbjm3.slc.paypal.com&pid=15797
CORRELATION-ID: 965491cb1a1e5
Content-Language: *
Date: Fri, 04 Jul 2014 14:24:52 GMT
Content-Type: application/json
Content-Length: 592
{"id":"7G199247NK652674M","create_time":"2014-07-04T14:24:52Z","update_time":"2014-07-04T14:24:52Z","state":"completed","amount":{"total":"2.34","currency":"USD"},"sale_id":"44E89981F8714392Y","parent_payment":"PAY-6RT04683U7444573DKO2WI6A","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/refund/7G199247NK652674M","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RT04683U7444573DKO2WI6A","rel":"parent_payment","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/44E89981F8714392Y","rel":"sale","method":"GET"}]}

View File

@@ -0,0 +1,11 @@
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=3683
Paypal-Debug-Id: f115dd7f08d14
SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=126527&TopLevelTxnStartTime=146fc214a29&Host=slcsbidensectoken502.slc.paypal.com&pid=29059
CORRELATION-ID: f115dd7f08d14
Date: Thu, 03 Jul 2014 12:09:38 GMT
Content-Type: application/json
Content-Length: 93
{"error":"invalid_client","error_description":"Client secret does not match for this client"}

View File

@@ -0,0 +1,11 @@
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=3205
Paypal-Debug-Id: 217a9ddefd384
SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=91&TopLevelTxnStartTime=146fbfe679a&Host=slcsbidensectoken502.slc.paypal.com&pid=29059
CORRELATION-ID: 217a9ddefd384
Date: Thu, 03 Jul 2014 11:31:32 GMT
Content-Type: application/json
Content-Length: 328
{"scope":"openid https://uri.paypal.com/services/invoicing https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/vault/credit-card","access_token":"A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":28800}

View File

@@ -0,0 +1,58 @@
<?php
namespace Omnipay\PayPal;
use Omnipay\Tests\GatewayTestCase;
use Omnipay\Common\CreditCard;
class ProGatewayTest extends GatewayTestCase
{
public function setUp()
{
parent::setUp();
$this->gateway = new ProGateway($this->getHttpClient(), $this->getHttpRequest());
$this->options = array(
'amount' => '10.00',
'card' => new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '12',
'expiryYear' => date('Y'),
'cvv' => '123',
)),
);
}
public function testAuthorize()
{
$this->setMockHttpResponse('ProPurchaseSuccess.txt');
$response = $this->gateway->authorize($this->options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('96U93778BD657313D', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testPurchase()
{
$this->setMockHttpResponse('ProPurchaseSuccess.txt');
$response = $this->gateway->purchase($this->options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('96U93778BD657313D', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testFetchTransaction()
{
$request = $this->gateway->fetchTransaction(array('transactionReference' => 'abc123'));
$this->assertInstanceOf('\Omnipay\PayPal\Message\FetchTransactionRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
}
}

View File

@@ -0,0 +1,303 @@
<?php
namespace Omnipay\PayPal;
use Omnipay\Tests\GatewayTestCase;
use Omnipay\Common\CreditCard;
class RestGatewayTest extends GatewayTestCase
{
/** @var RestGateway */
public $gateway;
/** @var array */
public $options;
/** @var array */
public $subscription_options;
public function setUp()
{
parent::setUp();
$this->gateway = new RestGateway($this->getHttpClient(), $this->getHttpRequest());
$this->gateway->setToken('TEST-TOKEN-123');
$this->gateway->setTokenExpires(time() + 600);
$this->options = array(
'amount' => '10.00',
'card' => new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '12',
'expiryYear' => date('Y'),
'cvv' => '123',
)),
);
$this->subscription_options = array(
'transactionReference' => 'ABC-1234',
'description' => 'Description goes here',
);
}
public function testBearerToken()
{
$this->gateway->setToken('');
$this->setMockHttpResponse('RestTokenSuccess.txt');
$this->assertFalse($this->gateway->hasToken());
$this->assertEquals('A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0', $this->gateway->getToken()); // triggers request
$this->assertEquals(time() + 28800, $this->gateway->getTokenExpires());
$this->assertTrue($this->gateway->hasToken());
}
public function testBearerTokenReused()
{
$this->setMockHttpResponse('RestTokenSuccess.txt');
$this->gateway->setToken('MYTOKEN');
$this->gateway->setTokenExpires(time() + 60);
$this->assertTrue($this->gateway->hasToken());
$this->assertEquals('MYTOKEN', $this->gateway->getToken());
}
public function testBearerTokenExpires()
{
$this->setMockHttpResponse('RestTokenSuccess.txt');
$this->gateway->setToken('MYTOKEN');
$this->gateway->setTokenExpires(time() - 60);
$this->assertFalse($this->gateway->hasToken());
$this->assertEquals('A015GQlKQ6uCRzLHSGRliANi59BHw6egNVKEWRnxvTwvLr0', $this->gateway->getToken());
}
public function testAuthorize()
{
$this->setMockHttpResponse('RestPurchaseSuccess.txt');
$response = $this->gateway->authorize($this->options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testPurchase()
{
$this->setMockHttpResponse('RestPurchaseSuccess.txt');
$response = $this->gateway->purchase($this->options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
public function testCapture()
{
$request = $this->gateway->capture(array(
'transactionReference' => 'abc123',
'amount' => 10.00,
'currency' => 'AUD',
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestCaptureRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/authorization/abc123/capture', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}
public function testRefund()
{
$request = $this->gateway->refund(array(
'transactionReference' => 'abc123',
'amount' => 10.00,
'currency' => 'AUD',
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestRefundRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/sale/abc123/refund', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}
public function testFullRefund()
{
$request = $this->gateway->refund(array(
'transactionReference' => 'abc123',
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestRefundRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/sale/abc123/refund', $endPoint);
$data = $request->getData();
// we're expecting an empty object here
$json = json_encode($data);
$this->assertEquals('{}', $json);
}
public function testFetchTransaction()
{
$request = $this->gateway->fetchTransaction(array('transactionReference' => 'abc123'));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestFetchTransactionRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$data = $request->getData();
$this->assertEmpty($data);
}
public function testListPlan()
{
$request = $this->gateway->listPlan(array(
'page' => 0,
'status' => 'ACTIVE',
'pageSize' => 10, //number of plans in a single page
'totalRequired' => 'yes'
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestListPlanRequest', $request);
$this->assertSame(0, $request->getPage());
$this->assertSame('ACTIVE', $request->getStatus());
$this->assertSame(10, $request->getPageSize());
$this->assertSame('yes', $request->getTotalRequired());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/billing-plans', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}
public function testFetchPurchase()
{
$request = $this->gateway->fetchPurchase(array('transactionReference' => 'abc123'));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestFetchPurchaseRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$data = $request->getData();
$this->assertEmpty($data);
}
public function testListPurchase()
{
$request = $this->gateway->listPurchase(array(
'count' => 15,
'startId' => 'PAY123',
'startIndex' => 1,
'startTime' => '2015-09-07T00:00:00Z',
'endTime' => '2015-09-08T00:00:00Z',
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestListPurchaseRequest', $request);
$this->assertSame(15, $request->getCount());
$this->assertSame('PAY123', $request->getStartId());
$this->assertSame(1, $request->getStartIndex());
$this->assertSame('2015-09-07T00:00:00Z', $request->getStartTime());
$this->assertSame('2015-09-08T00:00:00Z', $request->getEndTime());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/payment', $endPoint);
$data = $request->getData();
$this->assertNotEmpty($data);
}
public function testCreateCard()
{
$this->setMockHttpResponse('RestCreateCardSuccess.txt');
$response = $this->gateway->createCard($this->options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testPayWithSavedCard()
{
$this->setMockHttpResponse('RestCreateCardSuccess.txt');
$response = $this->gateway->createCard($this->options)->send();
$cardRef = $response->getCardReference();
$this->setMockHttpResponse('RestPurchaseSuccess.txt');
$response = $this->gateway->purchase(array('amount'=>'10.00', 'cardReference'=>$cardRef))->send();
$this->assertTrue($response->isSuccessful());
$this->assertEquals('44E89981F8714392Y', $response->getTransactionReference());
$this->assertNull($response->getMessage());
}
// Incomplete generic tests for subscription payments
public function testCompleteSubscription()
{
$this->setMockHttpResponse('RestExecuteSubscriptionSuccess.txt');
$response = $this->gateway->completeSubscription($this->subscription_options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertNull($response->getMessage());
$this->assertEquals('I-0LN988D3JACS', $response->getTransactionReference());
}
public function testCancelSubscription()
{
$this->setMockHttpResponse('RestGenericSubscriptionSuccess.txt');
$response = $this->gateway->cancelSubscription($this->subscription_options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertNull($response->getMessage());
}
public function testSuspendSubscription()
{
$this->setMockHttpResponse('RestGenericSubscriptionSuccess.txt');
$response = $this->gateway->suspendSubscription($this->subscription_options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertNull($response->getMessage());
}
public function testReactivateSubscription()
{
$this->setMockHttpResponse('RestGenericSubscriptionSuccess.txt');
$response = $this->gateway->reactivateSubscription($this->subscription_options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertNull($response->getMessage());
}
public function testRefundCapture()
{
$request = $this->gateway->refundCapture(array(
'transactionReference' => 'abc123'
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestRefundCaptureRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/capture/abc123/refund', $endPoint);
$request->setAmount('15.99');
$request->setCurrency('BRL');
$request->setDescription('Test Description');
$data = $request->getData();
// we're expecting an empty object here
$json = json_encode($data);
$this->assertEquals('{"amount":{"currency":"BRL","total":"15.99"},"description":"Test Description"}', $json);
}
public function testVoid()
{
$request = $this->gateway->void(array(
'transactionReference' => 'abc123'
));
$this->assertInstanceOf('\Omnipay\PayPal\Message\RestVoidRequest', $request);
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/authorization/abc123/void', $endPoint);
$data = $request->getData();
$this->assertEmpty($data);
}
}