From f4e09337d3227eda2ab65874c2da220ee385049f Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 4 Dec 2019 13:29:29 -0800 Subject: [PATCH 1/7] Add support for line items in transactions --- src/Item.php | 182 +++++++++++++++++++++++++ src/ItemBag.php | 24 ++++ src/Message/AbstractRequest.php | 37 ++++- src/Message/AuthorizeRequest.php | 1 + tests/Message/AuthorizeRequestTest.php | 41 ++++++ 5 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 src/Item.php create mode 100644 src/ItemBag.php diff --git a/src/Item.php b/src/Item.php new file mode 100644 index 0000000..73a83d2 --- /dev/null +++ b/src/Item.php @@ -0,0 +1,182 @@ +getParameter('commodityCode'); + } + + /** + * Set the item commodity code + */ + public function setCommodityCode($value) + { + return $this->setParameter('commodityCode', $value); + } + + /** + * {@inheritDoc} + */ + public function getDiscountAmount() + { + return $this->getParameter('discountAmount'); + } + + /** + * Set the item discount amount + */ + public function setDiscountAmount($value) + { + return $this->setParameter('discountAmount', $value); + } + + /** + * {@inheritDoc} + */ + public function getKind() + { + return $this->getParameter('kind'); + } + + /** + * Set the item kind + */ + public function setKind($value) + { + return $this->setParameter('kind', $value); + } + + /** + * {@inheritDoc} + */ + public function getPrice() + { + return $this->getParameter('totalAmount'); + } + + /** + * Set the item price + */ + public function setPrice($value) + { + return $this->setParameter('totalAmount', $value); + } + + /** + * {@inheritDoc} + */ + public function getProductCode() + { + return $this->getParameter('productCode'); + } + + /** + * Set the item product code + */ + public function setProductCode($value) + { + return $this->setParameter('productCode', $value); + } + + /** + * {@inheritDoc} + */ + public function getTaxAmount() + { + return $this->getParameter('taxAmount'); + } + + /** + * Set the item tax amount + */ + public function setTaxAmount($value) + { + return $this->setParameter('taxAmount', $value); + } + + /** + * {@inheritDoc} + */ + public function getTotalAmount() + { + return $this->getPrice(); + } + + /** + * Set the item price + */ + public function setTotalAmount($value) + { + return $this->setPrice($value); + } + + /** + * {@inheritDoc} + */ + public function getUnitAmount() + { + return $this->getParameter('unitAmount'); + } + + /** + * Set the item unit price + */ + public function setUnitAmount($value) + { + return $this->setParameter('unitAmount', $value); + } + + /** + * {@inheritDoc} + */ + public function getUnitOfMeasure() + { + return $this->getParameter('unitOfMeasure'); + } + + /** + * Set the item unit of measure + */ + public function setUnitOfMeasure($value) + { + return $this->setParameter('unitOfMeasure', $value); + } + + /** + * {@inheritDoc} + */ + public function getUnitTaxAmount() + { + return $this->getParameter('unitTaxAmount'); + } + + /** + * Set the item unit tax amount + */ + public function setUnitTaxAmount($value) + { + return $this->setParameter('unitTaxAmount', $value); + } + + /** + * {@inheritDoc} + */ + public function getUrl() + { + return $this->getParameter('url'); + } + + /** + * Set the item url + */ + public function setUrl($value) + { + return $this->setParameter('url', $value); + } +} diff --git a/src/ItemBag.php b/src/ItemBag.php new file mode 100644 index 0000000..591e62d --- /dev/null +++ b/src/ItemBag.php @@ -0,0 +1,24 @@ +items[] = $item; + } else { + $this->items[] = new Item($item); + } + } +} \ No newline at end of file diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 35eca0f..e10d11d 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -3,10 +3,11 @@ namespace Omnipay\Braintree\Message; use Braintree_Gateway; -use Omnipay\Common\Http\ClientInterface; +use Omnipay\Braintree\ItemBag; use Omnipay\Common\Exception\InvalidRequestException; -use Symfony\Component\HttpFoundation\Request as HttpRequest; +use Omnipay\Common\Http\ClientInterface; use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; +use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Abstract Request @@ -429,6 +430,38 @@ public function getOptionData() } } + /** + * Set the items in this order + * + * @param ItemBag|array $items An array of items in this order + * @return $this + */ + public function setItems($items) + { + if ($items && !$items instanceof ItemBag) { + $items = new ItemBag($items); + } + + return $this->setParameter('items', $items); + } + + public function getItems() + { + $itemBag = parent::getItems(); + + if (!$itemBag instanceof ItemBag || $itemBag->count() < 1) { + return null; + } + + $items = []; + + foreach ($itemBag as $item) { + $items[] = $item->getParameters(); + } + + return $items; + } + protected function createResponse($data) { return $this->response = new Response($this, $data); diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index 2c40b80..f898b0f 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -24,6 +24,7 @@ public function getData() 'descriptor' => $this->getDescriptor(), 'deviceData' => $this->getDeviceData(), 'deviceSessionId' => $this->getDeviceSessionId(), + 'lineItems' => $this->getItems(), 'merchantAccountId' => $this->getMerchantAccountId(), 'orderId' => $this->getTransactionId(), 'purchaseOrderNumber' => $this->getPurchaseOrderNumber(), diff --git a/tests/Message/AuthorizeRequestTest.php b/tests/Message/AuthorizeRequestTest.php index 5c9d84f..7c98115 100644 --- a/tests/Message/AuthorizeRequestTest.php +++ b/tests/Message/AuthorizeRequestTest.php @@ -2,6 +2,8 @@ namespace Omnipay\Braintree\Message; +use Omnipay\Braintree\Item; +use Omnipay\Braintree\ItemBag; use Omnipay\Tests\TestCase; class AuthorizeRequestTest extends TestCase @@ -194,4 +196,43 @@ public function testServiceFeeAmountWithIntStringThrowsException() $this->assertSame($this->request, $this->request->setServiceFeeAmount('10')); $this->request->getServiceFeeAmount(); } + + public function testPaymentWithItems() + { + $this->request->initialize( + array( + 'amount' => '10.00', + 'token' => 'abc123', + 'transactionId' => '684', + 'testMode' => false, + 'taxExempt' => false, + 'card' => array( + 'firstName' => 'Kayla', + 'shippingCompany' => 'League', + ), + 'items' => array( + array( + 'kind' => 'debit', + 'name' => 'Item Name', + 'quantity' => '2', + 'totalAmount' => '19.98', + 'unitAmount' => '9.99', + ) + ) + ) + ); + + $data = $this->request->getData(); + $this->assertTrue(is_array($data['lineItems'])); + $this->assertCount(1, $data['lineItems']); + + foreach ($data['lineItems'] as $lineItem) { + $this->assertTrue(is_array($lineItem)); + $this->assertEquals('debit', $lineItem['kind']); + $this->assertEquals('Item Name', $lineItem['name']); + $this->assertEquals('2', $lineItem['quantity']); + $this->assertEquals('19.98', $lineItem['totalAmount']); + $this->assertEquals('9.99', $lineItem['unitAmount']); + } + } } From 825b9bc2a8d65297cf74c376d1e4b9b604b6e4fc Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 4 Jun 2020 16:56:04 -0700 Subject: [PATCH 2/7] Add support for php 7.4 --- .idea/.gitignore | 8 +++ .idea/misc.xml | 6 ++ .idea/modules.xml | 8 +++ .idea/omnipay-braintree.iml | 68 ++++++++++++++++++ .idea/php.xml | 66 +++++++++++++++++ .idea/vcs.xml | 6 ++ composer.json | 3 +- src/Gateway.php | 45 ++++++++---- src/Message/AbstractRequest.php | 11 ++- tests/GatewayTest.php | 59 +++++++-------- tests/MerchantBusinessTest.php | 2 +- tests/MerchantFundingTest.php | 20 +++--- tests/MerchantIndividualTest.php | 2 +- .../AbstractMerchantAccountRequestTest.php | 36 +++++----- tests/Message/AbstractRequestTest.php | 2 +- tests/Message/AuthorizeRequestTest.php | 72 +++++++++---------- tests/Message/CaptureRequestTest.php | 11 +-- tests/Message/ClientTokenRequestTest.php | 17 ++--- tests/Message/ClientTokenResponseTest.php | 5 +- tests/Message/CreateCustomerRequestTest.php | 17 ++--- .../CreateMerchantAccountRequestTest.php | 50 ++++++------- .../CreatePaymentMethodRequestTest.php | 27 +++---- tests/Message/CustomerResponseTest.php | 5 +- tests/Message/DeleteCustomerRequestTest.php | 9 +-- .../DeletePaymentMethodRequestTest.php | 9 +-- tests/Message/FindCustomerRequestTest.php | 16 +++-- tests/Message/FindRequestTest.php | 9 +-- tests/Message/PlanRequestTest.php | 10 +-- tests/Message/PlanResponseTest.php | 5 +- tests/Message/PurchaseRequestTest.php | 9 +-- tests/Message/RefundRequestTest.php | 9 +-- .../Message/ReleaseFromEscrowRequestTest.php | 9 +-- tests/Message/ResponseTest.php | 13 ++-- tests/Message/SubscriptionResponseTest.php | 5 +- tests/Message/UpdateCustomerRequestTest.php | 21 +++--- .../UpdateMerchantAccountRequestTest.php | 54 +++++++------- .../UpdatePaymentMethodRequestTest.php | 29 ++++---- tests/Message/VoidRequestTest.php | 9 +-- 38 files changed, 478 insertions(+), 284 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/omnipay-braintree.iml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d42f32e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/omnipay-braintree.iml b/.idea/omnipay-braintree.iml new file mode 100644 index 0000000..ff42785 --- /dev/null +++ b/.idea/omnipay-braintree.iml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..d477124 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/composer.json b/composer.json index b2d7726..6b0617f 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,9 @@ "psr-4": { "Omnipay\\Braintree\\" : "src/" } }, "require": { + "php": "^7.1", "omnipay/common": "^3", - "braintree/braintree_php": "^3.0" + "braintree/braintree_php": "^5.0" }, "require-dev": { "omnipay/tests": "^3" diff --git a/src/Gateway.php b/src/Gateway.php index 9b7c1ae..2ec181c 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -2,31 +2,34 @@ namespace Omnipay\Braintree; +use Braintree\Configuration; +use Braintree\Exception\InvalidSignature; +use Braintree\Gateway as BraintreeGateway; +use Braintree\WebhookNotification; use Omnipay\Common\AbstractGateway; -use Braintree_Gateway; -use Braintree_Configuration; use Omnipay\Common\Http\ClientInterface; use Symfony\Component\HttpFoundation\Request as HttpRequest; + /** * Braintree Gateway */ class Gateway extends AbstractGateway { /** - * @var \Braintree_Gateway + * @var Gateway */ protected $braintree; /** * Create a new gateway instance * - * @param ClientInterface $httpClient A Guzzle client to make API calls with - * @param HttpRequest $httpRequest A Symfony HTTP request object - * @param Braintree_Gateway $braintree The Braintree gateway + * @param ClientInterface $httpClient A Guzzle client to make API calls with + * @param HttpRequest $httpRequest A Symfony HTTP request object + * @param BraintreeGateway $braintree The Braintree gateway */ - public function __construct(ClientInterface $httpClient = null, HttpRequest $httpRequest = null, Braintree_Gateway $braintree = null) + public function __construct(ClientInterface $httpClient = null, HttpRequest $httpRequest = null, BraintreeGateway $braintree = null) { - $this->braintree = $braintree ?: Braintree_Configuration::gateway(); + $this->braintree = $braintree ?: Configuration::gateway(); parent::__construct($httpClient, $httpRequest); } @@ -50,9 +53,9 @@ public function getDefaultParameters() { return array( 'merchantId' => '', - 'publicKey' => '', + 'publicKey' => '', 'privateKey' => '', - 'testMode' => false, + 'testMode' => false, ); } @@ -88,6 +91,7 @@ public function setPrivateKey($value) /** * @param array $parameters + * * @return Message\AuthorizeRequest */ public function authorize(array $parameters = array()) @@ -97,6 +101,7 @@ public function authorize(array $parameters = array()) /** * @param array $parameters + * * @return Message\PurchaseRequest */ public function capture(array $parameters = array()) @@ -106,6 +111,7 @@ public function capture(array $parameters = array()) /** * @param array $parameters + * * @return Message\ClientTokenRequest */ public function clientToken(array $parameters = array()) @@ -115,6 +121,7 @@ public function clientToken(array $parameters = array()) /** * @param string $id + * * @return Message\FindCustomerRequest */ public function findCustomer($id) @@ -124,6 +131,7 @@ public function findCustomer($id) /** * @param array $parameters + * * @return Message\CreateCustomerRequest */ public function createCustomer(array $parameters = array()) @@ -133,6 +141,7 @@ public function createCustomer(array $parameters = array()) /** * @param array $parameters + * * @return Message\DeleteCustomerRequest */ public function deleteCustomer(array $parameters = array()) @@ -142,6 +151,7 @@ public function deleteCustomer(array $parameters = array()) /** * @param array $parameters + * * @return Message\UpdateCustomerRequest */ public function updateCustomer(array $parameters = array()) @@ -151,6 +161,7 @@ public function updateCustomer(array $parameters = array()) /** * @param array $parameters + * * @return Message\PurchaseRequest */ public function find(array $parameters = array()) @@ -160,6 +171,7 @@ public function find(array $parameters = array()) /** * @param array $parameters + * * @return Message\CreateMerchantAccountRequest */ public function createMerchantAccount(array $parameters = array()) @@ -169,6 +181,7 @@ public function createMerchantAccount(array $parameters = array()) /** * @param array $parameters + * * @return Message\UpdateMerchantAccountRequest */ public function updateMerchantAccount(array $parameters = array()) @@ -178,6 +191,7 @@ public function updateMerchantAccount(array $parameters = array()) /** * @param array $parameters + * * @return Message\CreatePaymentMethodRequest */ public function createPaymentMethod(array $parameters = array()) @@ -187,6 +201,7 @@ public function createPaymentMethod(array $parameters = array()) /** * @param array $parameters + * * @return Message\DeletePaymentMethodRequest */ public function deletePaymentMethod(array $parameters = array()) @@ -196,6 +211,7 @@ public function deletePaymentMethod(array $parameters = array()) /** * @param array $parameters + * * @return Message\UpdatePaymentMethodRequest */ public function updatePaymentMethod(array $parameters = array()) @@ -205,6 +221,7 @@ public function updatePaymentMethod(array $parameters = array()) /** * @param array $parameters + * * @return Message\PurchaseRequest */ public function purchase(array $parameters = array()) @@ -214,6 +231,7 @@ public function purchase(array $parameters = array()) /** * @param array $parameters + * * @return Message\PurchaseRequest */ public function refund(array $parameters = array()) @@ -223,6 +241,7 @@ public function refund(array $parameters = array()) /** * @param array $parameters + * * @return Message\PurchaseRequest */ public function releaseFromEscrow(array $parameters = array()) @@ -232,6 +251,7 @@ public function releaseFromEscrow(array $parameters = array()) /** * @param array $parameters + * * @return Message\PurchaseRequest */ public function void(array $parameters = array()) @@ -270,9 +290,9 @@ public function plans() /** * @param array $parameters * - * @return \Braintree_WebhookNotification + * @return WebhookNotification * - * @throws \Braintree_Exception_InvalidSignature + * @throws InvalidSignature */ public function parseNotification(array $parameters = array()) { @@ -296,6 +316,7 @@ public function parseNotification(array $parameters = array()) /** * @param array $parameters + * * @return Message\FindRequest */ public function fetchTransaction(array $parameters = array()) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index e10d11d..7622fad 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -2,7 +2,7 @@ namespace Omnipay\Braintree\Message; -use Braintree_Gateway; +use Braintree\Gateway; use Omnipay\Braintree\ItemBag; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Http\ClientInterface; @@ -11,23 +11,22 @@ /** * Abstract Request - * */ abstract class AbstractRequest extends BaseAbstractRequest { /** - * @var \Braintree_Gateway + * @var Gateway */ protected $braintree; /** * Create a new Request * - * @param ClientInterface $httpClient A Guzzle client to make API calls with + * @param ClientInterface $httpClient A Guzzle client to make API calls with * @param HttpRequest $httpRequest A Symfony HTTP request object - * @param Braintree_Gateway $braintree The Braintree Gateway + * @param Gateway $braintree The Braintree Gateway */ - public function __construct(ClientInterface $httpClient, HttpRequest $httpRequest, Braintree_Gateway $braintree) + public function __construct(ClientInterface $httpClient, HttpRequest $httpRequest, Gateway $braintree) { $this->braintree = $braintree; diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 031e0e8..bbf0ff5 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -2,6 +2,9 @@ namespace Omnipay\Braintree; +use Braintree\Configuration; +use Braintree\Digest; +use Braintree\WebhookNotification; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase @@ -11,7 +14,7 @@ class GatewayTest extends GatewayTestCase */ protected $gateway; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -19,7 +22,7 @@ public function setUp() $this->options = array( 'amount' => '10.00', - 'token' => 'abcdef', + 'token' => 'abcdef', ); } @@ -67,7 +70,7 @@ public function testCreateMerchantAccount() $request = $this->gateway->createMerchantAccount(); $this->assertInstanceOf('Omnipay\Braintree\Message\CreateMerchantAccountRequest', $request); } - + public function testUpdateMerchantAccount() { $request = $this->gateway->updateMerchantAccount(); @@ -145,55 +148,41 @@ public function testCancelSubscription() public function testParseNotification() { - if(\Braintree_Version::MAJOR >= 3) { - $xml = ''; - $payload = base64_encode($xml); - $signature = \Braintree_Digest::hexDigestSha1(\Braintree_Configuration::privateKey(), $payload); - $gatewayMock = $this->buildGatewayMock($payload); - $gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest(), $gatewayMock); - $params = array( - 'bt_signature' => $payload.'|'.$signature, - 'bt_payload' => $payload - ); - $request = $gateway->parseNotification($params); - $this->assertInstanceOf('\Braintree_WebhookNotification', $request); - } else { - $xml = ''; - $payload = base64_encode($xml); - $signature = \Braintree_Digest::hexDigestSha1(\Braintree_Configuration::privateKey(), $payload); - $gatewayMock = $this->buildGatewayMock($payload); - $gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest(), $gatewayMock); - $params = array( - 'bt_signature' => $payload.'|'.$signature, - 'bt_payload' => $payload - ); - $request = $gateway->parseNotification($params); - $this->assertInstanceOf('\Braintree_WebhookNotification', $request); - } + $xml = ''; + $payload = base64_encode($xml); + $signature = Digest::hexDigestSha1(Configuration::privateKey(), $payload); + $gatewayMock = $this->buildGatewayMock($payload); + $gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest(), $gatewayMock); + $params = [ + 'bt_signature' => $payload . '|' . $signature, + 'bt_payload' => $payload + ]; + $request = $gateway->parseNotification($params); + $this->assertInstanceOf(WebhookNotification::class, $request); } /** * @param $payload * - * @return \Braintree_Gateway + * @return Gateway */ protected function buildGatewayMock($payload) { - $configuration = $this->getMockBuilder('\Braintree_Configuration') + $configuration = $this->getMockBuilder(Configuration::class) ->disableOriginalConstructor() - ->setMethods(array( + ->setMethods([ 'assertHasAccessTokenOrKeys' - )) + ]) ->getMock(); $configuration->expects($this->any()) ->method('assertHasAccessTokenOrKeys') ->will($this->returnValue(null)); - $configuration->setPublicKey($payload); - \Braintree_Configuration::$global = $configuration; - return \Braintree_Configuration::gateway(); + Configuration::$global = $configuration; + + return Configuration::gateway(); } } diff --git a/tests/MerchantBusinessTest.php b/tests/MerchantBusinessTest.php index a788c1a..af96f6c 100644 --- a/tests/MerchantBusinessTest.php +++ b/tests/MerchantBusinessTest.php @@ -8,7 +8,7 @@ class MerchantBusinessTest extends TestCase { - public function setUp() + public function setUp(): void { $this->business = new MerchantBusiness(); } diff --git a/tests/MerchantFundingTest.php b/tests/MerchantFundingTest.php index aa9f2c7..00c3711 100644 --- a/tests/MerchantFundingTest.php +++ b/tests/MerchantFundingTest.php @@ -2,43 +2,43 @@ namespace Omnipay\Braintree; -use Braintree_MerchantAccount; +use Braintree\MerchantAccount; use Omnipay\Tests\TestCase; class MerchantFundingTest extends TestCase { - public function setUp() + public function setUp(): void { $this->funding = new MerchantFunding(); } public function testConstructWithParams() { - $funding = new MerchantFunding(array('descriptor' => 'Millsburg National Bank')); + $funding = new MerchantFunding(['descriptor' => 'Millsburg National Bank']); $this->assertSame('Millsburg National Bank', $funding->getDescriptor()); } public function testInitializeWithParams() { $funding = new MerchantFunding; - $funding->initialize(array('descriptor' => 'Millsburg National Bank')); + $funding->initialize(['descriptor' => 'Millsburg National Bank']); $this->assertSame('Millsburg National Bank', $funding->getDescriptor()); } public function testGetParamters() { - $card = new MerchantFunding(array( + $card = new MerchantFunding([ 'descriptor' => 'Millsburg National Bank', - 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, + 'destination' => MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => 'payment@hoochiesdollarstore.com', 'mobilePhone' => '501.778.3151', 'accountNumber' => '1123581321', 'routingNumber' => '071101307' - )); + ]); $parameters = $card->getParameters(); $this->assertSame('Millsburg National Bank', $parameters['descriptor']); - $this->assertSame(Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, $parameters['destination']); + $this->assertSame(MerchantAccount::FUNDING_DESTINATION_BANK, $parameters['destination']); $this->assertSame('payment@hoochiesdollarstore.com', $parameters['email']); $this->assertSame('501.778.3151', $parameters['mobilePhone']); $this->assertSame('1123581321', $parameters['accountNumber']); @@ -71,8 +71,8 @@ public function testDescriptor() public function testDestination() { - $this->funding->setDestination(Braintree_MerchantAccount::FUNDING_DESTINATION_BANK); - $this->assertEquals(Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, $this->funding->getDestination()); + $this->funding->setDestination(MerchantAccount::FUNDING_DESTINATION_BANK); + $this->assertEquals(MerchantAccount::FUNDING_DESTINATION_BANK, $this->funding->getDestination()); } public function testEmail() diff --git a/tests/MerchantIndividualTest.php b/tests/MerchantIndividualTest.php index abf9349..7d5e75b 100644 --- a/tests/MerchantIndividualTest.php +++ b/tests/MerchantIndividualTest.php @@ -8,7 +8,7 @@ class MerchantIndividualTest extends TestCase { - public function setUp() + public function setUp(): void { $this->individual = new MerchantIndividual(); } diff --git a/tests/Message/AbstractMerchantAccountRequestTest.php b/tests/Message/AbstractMerchantAccountRequestTest.php index 1f49005..b5001b8 100644 --- a/tests/Message/AbstractMerchantAccountRequestTest.php +++ b/tests/Message/AbstractMerchantAccountRequestTest.php @@ -2,7 +2,7 @@ namespace Omnipay\Braintree\Message; -use Braintree_MerchantAccount; +use Braintree\MerchantAccount; use Mockery; use Omnipay\Tests\TestCase; @@ -13,9 +13,9 @@ class AbstractMerchantAccountRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { - $this->request = Mockery::mock('\Omnipay\Braintree\Message\AbstractMerchantAccountRequest')->makePartial(); + $this->request = Mockery::mock(AbstractMerchantAccountRequest::class)->makePartial(); $this->request->initialize(); } @@ -32,11 +32,11 @@ public function testKeepsData($field, $value) } public function provideKeepsData(){ - return array( - array('merchantAccountId', 'blue_ladders_store'), - array('masterMerchantAccountId', '14ladders_marketplace'), - array('tosAccepted', true), - ); + return [ + ['merchantAccountId', 'blue_ladders_store'], + ['masterMerchantAccountId', '14ladders_marketplace'], + ['tosAccepted', true], + ]; } /** @@ -55,14 +55,14 @@ public function testMakesBool($field) } public function provideMakesBool(){ - return array( - array('tosAccepted'), - ); + return [ + ['tosAccepted'], + ]; } public function testBusinessData() { - $business = array( + $business = [ 'legalName' => 'Jane\'s Ladders', 'dbaName' => 'Jane\'s Ladders', 'taxId' => '98-7654321', @@ -70,7 +70,7 @@ public function testBusinessData() 'city' => 'Chicago', 'state' => 'IL', 'postCode' => '60622', - ); + ]; $this->request->setBusiness($business); $data = $this->request->getBusinessData(); @@ -86,14 +86,14 @@ public function testBusinessData() public function testFundingData() { - $funding = array( + $funding = [ 'descriptor' => 'Blue Ladders', - 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, + 'destination' => MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => 'funding@blueladders.com', 'mobilePhone' => '5555555555', 'accountNumber' => '1123581321', 'routingNumber' => '071101307', - ); + ]; $this->request->setFunding($funding); $data = $this->request->getFundingData(); @@ -108,7 +108,7 @@ public function testFundingData() public function testIndividualData() { - $individual = array( + $individual = [ 'firstName' => 'Jane', 'lastName' => 'Doe', 'email' => 'jane@14ladders.com', @@ -119,7 +119,7 @@ public function testIndividualData() 'city' => 'Chicago', 'state' => 'IL', 'postCode' => '60622', - ); + ]; $this->request->setIndividual($individual); $data = $this->request->getIndividualData(); diff --git a/tests/Message/AbstractRequestTest.php b/tests/Message/AbstractRequestTest.php index ec64ae4..ccfba8d 100644 --- a/tests/Message/AbstractRequestTest.php +++ b/tests/Message/AbstractRequestTest.php @@ -12,7 +12,7 @@ class AbstractRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { $this->request = Mockery::mock('\Omnipay\Braintree\Message\AbstractRequest')->makePartial(); $this->request->initialize(); diff --git a/tests/Message/AuthorizeRequestTest.php b/tests/Message/AuthorizeRequestTest.php index 7c98115..dc3e30e 100644 --- a/tests/Message/AuthorizeRequestTest.php +++ b/tests/Message/AuthorizeRequestTest.php @@ -2,8 +2,8 @@ namespace Omnipay\Braintree\Message; -use Omnipay\Braintree\Item; -use Omnipay\Braintree\ItemBag; +use Braintree\Configuration; +use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Tests\TestCase; class AuthorizeRequestTest extends TestCase @@ -13,23 +13,23 @@ class AuthorizeRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'amount' => '10.00', 'token' => 'abc123', 'transactionId' => '684', 'testMode' => false, 'taxExempt' => false, - 'card' => array( + 'card' => [ 'firstName' => 'Kayla', 'shippingCompany' => 'League', - ) - ) + ] + ] ); } @@ -50,23 +50,23 @@ public function testGetData() $this->assertFalse(isset($data['billingAddressId'])); $this->request->configure(); - $this->assertSame('production', \Braintree_Configuration::environment()); + $this->assertSame('production', Configuration::environment()); } public function testPaymentMethodToken() { $this->request->initialize( - array( + [ 'amount' => '10.00', 'transactionId' => '684', 'testMode' => false, 'taxExempt' => false, - 'card' => array( + 'card' => [ 'firstName' => 'Kayla', 'shippingCompany' => 'League', - ), + ], 'paymentMethodToken' => 'fake-token-123' - ) + ] ); $data = $this->request->getData(); @@ -77,17 +77,17 @@ public function testPaymentMethodToken() public function testPaymentMethodNonce() { $this->request->initialize( - array( + [ 'amount' => '10.00', 'transactionId' => '684', 'testMode' => false, 'taxExempt' => false, - 'card' => array( + 'card' => [ 'firstName' => 'Kayla', 'shippingCompany' => 'League', - ), + ], 'paymentMethodNonce' => 'abc123' - ) + ] ); $data = $this->request->getData(); @@ -98,17 +98,17 @@ public function testPaymentMethodNonce() public function testCustomerId() { $this->request->initialize( - array( + [ 'amount' => '10.00', 'transactionId' => '684', 'testMode' => false, 'taxExempt' => false, - 'card' => array( + 'card' => [ 'firstName' => 'Kayla', 'shippingCompany' => 'League', - ), + ], 'customerId' => 'abc123' - ) + ] ); $data = $this->request->getData(); @@ -120,13 +120,13 @@ public function testCustomerId() public function testSubMerchantSale() { $this->request->initialize( - array( + [ 'amount' => '100.00', 'holdInEscrow' => true, 'merchantAccountId' => 'blue_ladders_store', 'paymentMethodToken' => 'fake-token-123', 'serviceFeeAmount' => '10.00', - ) + ] ); $data = $this->request->getData(); @@ -140,7 +140,7 @@ public function testSandboxEnvironment() $this->request->setTestMode(true); $this->request->configure(); - $this->assertSame('sandbox', \Braintree_Configuration::environment()); + $this->assertSame('sandbox', Configuration::environment()); } public function testServiceFeeAmount() @@ -177,21 +177,17 @@ public function testGetServiceFeeAmountNoDecimalsRounding() $this->assertSame('137', $this->request->getServiceFeeAmount()); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidRequestException - */ public function testServiceFeeAmountWithIntThrowsException() { + $this->expectException(InvalidRequestException::class); // ambiguous value, avoid errors upgrading from v0.9 $this->assertSame($this->request, $this->request->setServiceFeeAmount(10)); $this->request->getServiceFeeAmount(); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidRequestException - */ public function testServiceFeeAmountWithIntStringThrowsException() { + $this->expectException(InvalidRequestException::class); // ambiguous value, avoid errors upgrading from v0.9 $this->assertSame($this->request, $this->request->setServiceFeeAmount('10')); $this->request->getServiceFeeAmount(); @@ -200,26 +196,26 @@ public function testServiceFeeAmountWithIntStringThrowsException() public function testPaymentWithItems() { $this->request->initialize( - array( + [ 'amount' => '10.00', 'token' => 'abc123', 'transactionId' => '684', 'testMode' => false, 'taxExempt' => false, - 'card' => array( + 'card' => [ 'firstName' => 'Kayla', 'shippingCompany' => 'League', - ), - 'items' => array( - array( + ], + 'items' => [ + [ 'kind' => 'debit', 'name' => 'Item Name', 'quantity' => '2', 'totalAmount' => '19.98', 'unitAmount' => '9.99', - ) - ) - ) + ] + ] + ] ); $data = $this->request->getData(); diff --git a/tests/Message/CaptureRequestTest.php b/tests/Message/CaptureRequestTest.php index fe089a0..1f378ce 100644 --- a/tests/Message/CaptureRequestTest.php +++ b/tests/Message/CaptureRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class CaptureRequestTest extends TestCase @@ -11,16 +12,16 @@ class CaptureRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( - 'amount' => '10.00', + [ + 'amount' => '10.00', 'transactionReference' => 'abc123', - ) + ] ); } diff --git a/tests/Message/ClientTokenRequestTest.php b/tests/Message/ClientTokenRequestTest.php index 16eeb7c..08ad8c2 100644 --- a/tests/Message/ClientTokenRequestTest.php +++ b/tests/Message/ClientTokenRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class ClientTokenRequestTest extends TestCase @@ -11,11 +12,11 @@ class ClientTokenRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new ClientTokenRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new ClientTokenRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } public function testGetData() @@ -27,16 +28,16 @@ public function testGetData() public function testGetDataWithCustomer() { - $setData = array( + $setData = [ 'customerId' => '4815162342', 'failOnDuplicatePaymentMethod' => true, - ); - $expectedData = array( + ]; + $expectedData = [ 'customerId' => '4815162342', - 'options' => array( + 'options' => [ 'failOnDuplicatePaymentMethod' => true, - ), - ); + ], + ]; $this->request->initialize($setData); $this->assertSame('4815162342', $this->request->getCustomerId()); $this->assertSame($expectedData, $this->request->getData()); diff --git a/tests/Message/ClientTokenResponseTest.php b/tests/Message/ClientTokenResponseTest.php index e8b7327..e4d54ec 100644 --- a/tests/Message/ClientTokenResponseTest.php +++ b/tests/Message/ClientTokenResponseTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class ClientTokenResponseTest extends TestCase @@ -11,11 +12,11 @@ class ClientTokenResponseTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new ClientTokenRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new ClientTokenRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } public function testSuccess() diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 2b660c1..3bdfc97 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class CreateCustomerRequestTest extends TestCase @@ -11,19 +12,19 @@ class CreateCustomerRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( - 'customerData' => array( + [ + 'customerData' => [ 'firstName' => 'Mike', 'lastName' => 'Jones', 'email' => 'mike.jones@example.com', - ) - ) + ] + ] ); } @@ -40,11 +41,11 @@ public function testRequestData() { $this->assertNull($this->request->getCustomerId()); $this->assertSame( - array( + [ 'firstName' => 'Mike', 'lastName' => 'Jones', 'email' => 'mike.jones@example.com', - ), + ], $this->request->getCustomerData() ); } diff --git a/tests/Message/CreateMerchantAccountRequestTest.php b/tests/Message/CreateMerchantAccountRequestTest.php index 196fce5..04fb129 100644 --- a/tests/Message/CreateMerchantAccountRequestTest.php +++ b/tests/Message/CreateMerchantAccountRequestTest.php @@ -2,6 +2,8 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; +use Braintree\MerchantAccount; use Braintree_MerchantAccount; use Omnipay\Tests\TestCase; @@ -12,14 +14,14 @@ class CreateMerchantAccountRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new CreateMerchantAccountRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new CreateMerchantAccountRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( - 'individual' => array( + [ + 'individual' => [ 'firstName' => 'Jane', 'lastName' => 'Doe', 'email' => 'jane@14ladders.com', @@ -30,8 +32,8 @@ public function setUp() 'city' => 'Chicago', 'state' => 'IL', 'postCode' => '60622', - ), - 'business' => array( + ], + 'business' => [ 'legalName' => 'Jane\'s Ladders', 'dbaName' => 'Jane\'s Ladders', 'taxId' => '98-7654321', @@ -39,60 +41,60 @@ public function setUp() 'city' => 'Chicago', 'state' => 'IL', 'postCode' => '60622', - ), - 'funding' => array( + ], + 'funding' => [ 'descriptor' => 'Blue Ladders', - 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, + 'destination' => MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => 'funding@blueladders.com', 'mobilePhone' => '5555555555', 'accountNumber' => '1123581321', 'routingNumber' => '071101307', - ), + ], 'tosAccepted' => true, 'masterMerchantAccountId' => '14ladders_marketplace', - ) + ] ); } public function testGetData() { - $expected = array( - 'business' => array( - 'address' => array( + $expected = [ + 'business' => [ + 'address' => [ 'streetAddress' => '111 Main St', 'locality' => 'Chicago', 'postalCode' => '60622', 'region' => 'IL', - ), + ], 'dbaName' => 'Jane\'s Ladders', 'legalName' => 'Jane\'s Ladders', 'taxId' => '98-7654321', - ), - 'funding' => array( + ], + 'funding' => [ 'accountNumber' => '1123581321', 'descriptor' => 'Blue Ladders', - 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, + 'destination' => MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => 'funding@blueladders.com', 'mobilePhone' => '5555555555', 'routingNumber' => '071101307', - ), - 'individual' => array( - 'address' => array( + ], + 'individual' => [ + 'address' => [ 'streetAddress' => '111 Main St', 'locality' => 'Chicago', 'postalCode' => '60622', 'region' => 'IL', - ), + ], 'dateOfBirth' => '1981-11-19', 'email' => 'jane@14ladders.com', 'firstName' => 'Jane', 'lastName' => 'Doe', 'phone' => '5553334444', 'ssn' => '078-05-1120', - ), + ], 'masterMerchantAccountId' => "14ladders_marketplace", 'tosAccepted' => true, - ); + ]; $data = $this->request->getData(); diff --git a/tests/Message/CreatePaymentMethodRequestTest.php b/tests/Message/CreatePaymentMethodRequestTest.php index fc7a98d..f4507f5 100644 --- a/tests/Message/CreatePaymentMethodRequestTest.php +++ b/tests/Message/CreatePaymentMethodRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class CreatePaymentMethodRequestTest extends TestCase @@ -10,22 +11,22 @@ public function testGetData() { $request = $this->createPaymentMethodRequest(); $request->initialize( - array( + [ 'customerId' => '4815162342', 'token' => 'abc123', 'verifyCard' => true, 'verificationMerchantAccountId' => '123581321', - ) + ] ); - $expectedData = array( + $expectedData = [ 'customerId' => '4815162342', 'paymentMethodNonce' => 'abc123', - 'options' => array( + 'options' => [ 'verifyCard' => true, 'verificationMerchantAccountId' => '123581321', - ) - ); + ] + ]; $this->assertSame($expectedData, $request->getData()); } @@ -33,24 +34,24 @@ public function testGetDataWithCardholderName() { $request = $this->createPaymentMethodRequest(); $request->initialize( - array( + [ 'customerId' => '4815162342', 'token' => 'abc123', 'cardholderName' => 'John Yolo', 'verifyCard' => true, 'verificationMerchantAccountId' => '123581321', - ) + ] ); - $expectedData = array( + $expectedData = [ 'customerId' => '4815162342', 'paymentMethodNonce' => 'abc123', 'cardholderName' => 'John Yolo', - 'options' => array( + 'options' => [ 'verifyCard' => true, 'verificationMerchantAccountId' => '123581321', - ) - ); + ] + ]; $this->assertSame($expectedData, $request->getData()); } @@ -59,6 +60,6 @@ public function testGetDataWithCardholderName() */ private function createPaymentMethodRequest() { - return new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + return new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } } diff --git a/tests/Message/CustomerResponseTest.php b/tests/Message/CustomerResponseTest.php index 4dda5bd..b62aa21 100644 --- a/tests/Message/CustomerResponseTest.php +++ b/tests/Message/CustomerResponseTest.php @@ -5,6 +5,7 @@ */ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class CustomerResponseTest extends TestCase @@ -14,11 +15,11 @@ class CustomerResponseTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } public function testGetSubscriptionData() diff --git a/tests/Message/DeleteCustomerRequestTest.php b/tests/Message/DeleteCustomerRequestTest.php index f0b24c0..6bb8d1d 100644 --- a/tests/Message/DeleteCustomerRequestTest.php +++ b/tests/Message/DeleteCustomerRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class DeleteCustomerRequestTest extends TestCase @@ -11,15 +12,15 @@ class DeleteCustomerRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new DeleteCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new DeleteCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'customerId' => '4815162342' - ) + ] ); } diff --git a/tests/Message/DeletePaymentMethodRequestTest.php b/tests/Message/DeletePaymentMethodRequestTest.php index 039ee2b..883f032 100644 --- a/tests/Message/DeletePaymentMethodRequestTest.php +++ b/tests/Message/DeletePaymentMethodRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class DeletePaymentMethodRequestTest extends TestCase @@ -11,13 +12,13 @@ class DeletePaymentMethodRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { - $this->request = new DeletePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new DeletePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'token' => 'abcd1234', - ) + ] ); } diff --git a/tests/Message/FindCustomerRequestTest.php b/tests/Message/FindCustomerRequestTest.php index 60f2d00..0cdaff5 100644 --- a/tests/Message/FindCustomerRequestTest.php +++ b/tests/Message/FindCustomerRequestTest.php @@ -1,6 +1,8 @@ buildMockGateway(); $this->request = new FindCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), $gateway); - $this->request->initialize(array('customerId' => 1)); + $this->request->initialize(['customerId' => 1]); } public function testGetData() @@ -27,7 +29,7 @@ public function testGetData() public function testSendData() { - $data = array(); + $data = []; $response = $this->request->sendData($data); $this->assertInstanceOf('Omnipay\Braintree\Message\CustomerResponse', $response); @@ -35,14 +37,14 @@ public function testSendData() protected function buildMockGateway() { - $gateway = $this->getMockBuilder('\Braintree_Gateway') + $gateway = $this->getMockBuilder(Gateway::class) ->disableOriginalConstructor() - ->setMethods(array( + ->setMethods([ 'customer' - )) + ]) ->getMock(); - $customer = $this->getMockBuilder('\Braintree_CustomerGateway') + $customer = $this->getMockBuilder(CustomerGateway::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Message/FindRequestTest.php b/tests/Message/FindRequestTest.php index 87eebe0..2f9200b 100644 --- a/tests/Message/FindRequestTest.php +++ b/tests/Message/FindRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class FindRequestTest extends TestCase @@ -11,15 +12,15 @@ class FindRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new FindRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new FindRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'transactionReference' => 'abc123', - ) + ] ); } diff --git a/tests/Message/PlanRequestTest.php b/tests/Message/PlanRequestTest.php index 4cfaf49..9c96c79 100644 --- a/tests/Message/PlanRequestTest.php +++ b/tests/Message/PlanRequestTest.php @@ -8,6 +8,8 @@ namespace Omnipay\Braintree\Message; +use Braintree\Gateway; +use Braintree\PlanGateway; use Omnipay\Tests\TestCase; class PlanRequestTest extends TestCase @@ -15,7 +17,7 @@ class PlanRequestTest extends TestCase /** @var PlanRequest */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -35,19 +37,19 @@ public function testSendData() $data = array(); $response = $this->request->sendData($data); - $this->assertInstanceOf('Omnipay\BrainTree\Message\PlanResponse', $response); + $this->assertInstanceOf(PlanResponse::class, $response); } protected function buildMockGateway() { - $gateway = $this->getMockBuilder('\Braintree_Gateway') + $gateway = $this->getMockBuilder(Gateway::class) ->disableOriginalConstructor() ->setMethods(array( 'plan' )) ->getMock(); - $plan = $this->getMockBuilder('\Braintree_PlanGateway') + $plan = $this->getMockBuilder(PlanGateway::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Message/PlanResponseTest.php b/tests/Message/PlanResponseTest.php index 46b643e..cdd2c50 100644 --- a/tests/Message/PlanResponseTest.php +++ b/tests/Message/PlanResponseTest.php @@ -7,6 +7,7 @@ */ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class PlanResponseTest extends TestCase @@ -14,12 +15,12 @@ class PlanResponseTest extends TestCase /** @var PlanRequest */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); $this->request = new PlanRequest( - $this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway() + $this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway() ); } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 27809c0..28c4235 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase @@ -11,17 +12,17 @@ class PurchaseRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'amount' => '10.00', 'token' => 'abc123', 'testMode' => false, - ) + ] ); } diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index 39bc1f0..1c9ea53 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase @@ -11,16 +12,16 @@ class RefundRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'amount' => '10.00', 'transactionReference' => 'abc123', - ) + ] ); } diff --git a/tests/Message/ReleaseFromEscrowRequestTest.php b/tests/Message/ReleaseFromEscrowRequestTest.php index 7328612..10e7469 100644 --- a/tests/Message/ReleaseFromEscrowRequestTest.php +++ b/tests/Message/ReleaseFromEscrowRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class ReleaseFromEscrowRequestTest extends TestCase @@ -11,15 +12,15 @@ class ReleaseFromEscrowRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new ReleaseFromEscrowRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new ReleaseFromEscrowRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'transactionId' => 'abc123', - ) + ] ); } diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php index a0d47ee..36702be 100644 --- a/tests/Message/ResponseTest.php +++ b/tests/Message/ResponseTest.php @@ -2,9 +2,10 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; +use Braintree\Result\Error; +use Braintree\Result\Successful; use Omnipay\Tests\TestCase; -use Braintree_Result_Successful; -use Braintree_Result_Error; class ResponseTest extends TestCase { @@ -13,16 +14,16 @@ class ResponseTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } public function testSuccess() { - $data = new Braintree_Result_Successful(1, 'transaction'); + $data = new Successful(1, 'transaction'); $response = new Response($this->request, $data); @@ -33,7 +34,7 @@ public function testSuccess() public function testError() { - $data = new Braintree_Result_Error(array('errors' => array(), 'params' => array(), 'message' => 'short message')); + $data = new Error(array('errors' => array(), 'params' => array(), 'message' => 'short message')); $response = new Response($this->request, $data); diff --git a/tests/Message/SubscriptionResponseTest.php b/tests/Message/SubscriptionResponseTest.php index bae1bf8..08b04fc 100644 --- a/tests/Message/SubscriptionResponseTest.php +++ b/tests/Message/SubscriptionResponseTest.php @@ -5,6 +5,7 @@ */ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class SubscriptionResponseTest extends TestCase @@ -14,11 +15,11 @@ class SubscriptionResponseTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new CreateSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new CreateSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } public function testGetSubscriptionData() diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php index ea0bd95..2a17a68 100644 --- a/tests/Message/UpdateCustomerRequestTest.php +++ b/tests/Message/UpdateCustomerRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class UpdateCustomerRequestTest extends TestCase @@ -11,20 +12,20 @@ class UpdateCustomerRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new UpdateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new UpdateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'customerId' => '4815162342', - 'customerData' => array( + 'customerData' => [ 'firstName' => 'Mike', 'lastName' => 'Jones', 'email' => 'mike.jones@example.com', - ), - ) + ], + ] ); } @@ -34,11 +35,11 @@ public function testGetData() $this->assertSame('4815162342', $data['customerId']); $this->assertSame( - array( + [ 'firstName' => 'Mike', 'lastName' => 'Jones', 'email' => 'mike.jones@example.com', - ), + ], $data['customerData'] ); } @@ -47,11 +48,11 @@ public function testRequestData() { $this->assertSame('4815162342', $this->request->getCustomerId()); $this->assertSame( - array( + [ 'firstName' => 'Mike', 'lastName' => 'Jones', 'email' => 'mike.jones@example.com', - ), + ], $this->request->getCustomerData() ); } diff --git a/tests/Message/UpdateMerchantAccountRequestTest.php b/tests/Message/UpdateMerchantAccountRequestTest.php index 8740129..1a6dea2 100644 --- a/tests/Message/UpdateMerchantAccountRequestTest.php +++ b/tests/Message/UpdateMerchantAccountRequestTest.php @@ -2,6 +2,8 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; +use Braintree\MerchantAccount; use Braintree_MerchantAccount; use Omnipay\Tests\TestCase; @@ -12,14 +14,14 @@ class UpdateMerchantAccountRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new UpdateMerchantAccountRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new UpdateMerchantAccountRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( - 'individual' => array( + [ + 'individual' => [ 'firstName' => 'Jane', 'lastName' => 'Doe', 'email' => 'jane@14ladders.com', @@ -30,8 +32,8 @@ public function setUp() 'city' => 'Chicago', 'state' => 'IL', 'postCode' => '60622', - ), - 'business' => array( + ], + 'business' => [ 'legalName' => 'Jane\'s Ladders', 'dbaName' => 'Jane\'s Ladders', 'taxId' => '98-7654321', @@ -39,60 +41,60 @@ public function setUp() 'city' => 'Chicago', 'state' => 'IL', 'postCode' => '60622', - ), - 'funding' => array( + ], + 'funding' => [ 'descriptor' => 'Blue Ladders', - 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, + 'destination' => MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => 'funding@blueladders.com', 'mobilePhone' => '5555555555', 'accountNumber' => '1123581321', 'routingNumber' => '071101307', - ), + ], 'merchantAccountId' => "blue_ladders_store", - ) + ] ); } public function testGetData() { - $expected = array( - 'merchantData' => array( - 'business' => array( - 'address' => array( + $expected = [ + 'merchantData' => [ + 'business' => [ + 'address' => [ 'streetAddress' => '111 Main St', 'locality' => 'Chicago', 'postalCode' => '60622', 'region' => 'IL', - ), + ], 'dbaName' => 'Jane\'s Ladders', 'legalName' => 'Jane\'s Ladders', 'taxId' => '98-7654321', - ), - 'funding' => array( + ], + 'funding' => [ 'accountNumber' => '1123581321', 'descriptor' => 'Blue Ladders', - 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, + 'destination' => MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => 'funding@blueladders.com', 'mobilePhone' => '5555555555', 'routingNumber' => '071101307', - ), - 'individual' => array( - 'address' => array( + ], + 'individual' => [ + 'address' => [ 'streetAddress' => '111 Main St', 'locality' => 'Chicago', 'postalCode' => '60622', 'region' => 'IL', - ), + ], 'dateOfBirth' => '1981-11-19', 'email' => 'jane@14ladders.com', 'firstName' => 'Jane', 'lastName' => 'Doe', 'phone' => '5553334444', 'ssn' => '078-05-1120', - ), - ), + ], + ], 'merchantAccountId' => "blue_ladders_store", - ); + ]; $data = $this->request->getData(); $this->assertSame($expected, $data); diff --git a/tests/Message/UpdatePaymentMethodRequestTest.php b/tests/Message/UpdatePaymentMethodRequestTest.php index 1888dc8..6bc5c69 100644 --- a/tests/Message/UpdatePaymentMethodRequestTest.php +++ b/tests/Message/UpdatePaymentMethodRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class UpdatePaymentMethodRequestTest extends TestCase @@ -11,40 +12,40 @@ class UpdatePaymentMethodRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { - $this->request = new UpdatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new UpdatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); } public function testGetData() { $this->request->initialize( - array( + [ 'paymentMethodToken' => 'abcd1234', - 'options' => array( + 'options' => [ 'makeDefault' => true, - ) - ) + ] + ] ); - $expected = array( + $expected = [ 'token' => 'abcd1234', - 'options' => array( + 'options' => [ 'makeDefault' => true, - ), - ); + ], + ]; $this->assertSame($expected, $this->request->getData()); } public function testGetDataNoParameters() { $this->request->initialize( - array( + [ 'paymentMethodToken' => 'abcd1234', - ) + ] ); - $expected = array( + $expected = [ 'token' => 'abcd1234', - ); + ]; $this->assertSame($expected, $this->request->getData()); } } diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php index 9c7ab3b..9bb78fb 100644 --- a/tests/Message/VoidRequestTest.php +++ b/tests/Message/VoidRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Braintree\Message; +use Braintree\Configuration; use Omnipay\Tests\TestCase; class VoidRequestTest extends TestCase @@ -11,15 +12,15 @@ class VoidRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); - $this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway()); + $this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest(), Configuration::gateway()); $this->request->initialize( - array( + [ 'transactionReference' => 'abc123', - ) + ] ); } From 986aea229adb2e460a614d4f6e86a149db2b6877 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 29 Dec 2020 15:05:30 -0800 Subject: [PATCH 3/7] Add support for skipping advanced fraud checking --- src/Message/AbstractRequest.php | 74 +++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 7622fad..4437abc 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -187,7 +187,7 @@ public function getRecurring() public function setRecurring($value) { - return $this->setParameter('recurring', (bool) $value); + return $this->setParameter('recurring', (bool)$value); } public function getAddBillingAddressToPaymentMethod() @@ -197,7 +197,7 @@ public function getAddBillingAddressToPaymentMethod() public function setAddBillingAddressToPaymentMethod($value) { - return $this->setParameter('addBillingAddressToPaymentMethod', (bool) $value); + return $this->setParameter('addBillingAddressToPaymentMethod', (bool)$value); } public function getHoldInEscrow() @@ -207,7 +207,7 @@ public function getHoldInEscrow() public function setHoldInEscrow($value) { - return $this->setParameter('holdInEscrow', (bool) $value); + return $this->setParameter('holdInEscrow', (bool)$value); } public function getServiceFeeAmount() @@ -233,6 +233,16 @@ public function setServiceFeeAmount($value) return $this->setParameter('serviceFeeAmount', $value); } + public function setSkipAdvancedFraudChecking($value) + { + return $this->setParameter('skipAdvancedFraudChecking', (bool)$value); + } + + public function getSkipAdvancedFraudChecking() + { + return (bool)$this->getParameter('skipAdvancedFraudChecking'); + } + public function getStoreInVault() { return $this->getParameter('storeInVault'); @@ -240,7 +250,7 @@ public function getStoreInVault() public function setStoreInVault($value) { - return $this->setParameter('storeInVault', (bool) $value); + return $this->setParameter('storeInVault', (bool)$value); } public function getStoreInVaultOnSuccess() @@ -250,7 +260,7 @@ public function getStoreInVaultOnSuccess() public function setStoreInVaultOnSuccess($value) { - return $this->setParameter('storeInVaultOnSuccess', (bool) $value); + return $this->setParameter('storeInVaultOnSuccess', (bool)$value); } public function getStoreShippingAddressInVault() @@ -260,7 +270,7 @@ public function getStoreShippingAddressInVault() public function setStoreShippingAddressInVault($value) { - return $this->setParameter('storeShippingAddressInVault', (bool) $value); + return $this->setParameter('storeShippingAddressInVault', (bool)$value); } public function getShippingAddressId() @@ -300,7 +310,7 @@ public function getTaxExempt() public function setTaxExempt($value) { - return $this->setParameter('taxExempt', (bool) $value); + return $this->setParameter('taxExempt', (bool)$value); } public function getPaymentMethodToken() @@ -330,7 +340,7 @@ public function getFailOnDuplicatePaymentMethod() public function setFailOnDuplicatePaymentMethod($value) { - return $this->setParameter('failOnDuplicatePaymentMethod', (bool) $value); + return $this->setParameter('failOnDuplicatePaymentMethod', (bool)$value); } public function getMakeDefault() @@ -340,7 +350,7 @@ public function getMakeDefault() public function setMakeDefault($value) { - return $this->setParameter('makeDefault', (bool) $value); + return $this->setParameter('makeDefault', (bool)$value); } public function getVerifyCard() @@ -350,7 +360,7 @@ public function getVerifyCard() public function setVerifyCard($value) { - return $this->setParameter('verifyCard', (bool) $value); + return $this->setParameter('verifyCard', (bool)$value); } public function getVerificationMerchantAccountId() @@ -375,27 +385,27 @@ public function getCardData() } return array( - 'billing' => array( - 'company' => $card->getBillingCompany(), - 'firstName' => $card->getBillingFirstName(), - 'lastName' => $card->getBillingLastName(), - 'streetAddress' => $card->getBillingAddress1(), - 'extendedAddress' => $card->getBillingAddress2(), - 'locality' => $card->getBillingCity(), - 'postalCode' => $card->getBillingPostcode(), - 'region' => $card->getBillingState(), - 'countryName' => $card->getBillingCountry(), + 'billing' => array( + 'company' => $card->getBillingCompany(), + 'firstName' => $card->getBillingFirstName(), + 'lastName' => $card->getBillingLastName(), + 'streetAddress' => $card->getBillingAddress1(), + 'extendedAddress' => $card->getBillingAddress2(), + 'locality' => $card->getBillingCity(), + 'postalCode' => $card->getBillingPostcode(), + 'region' => $card->getBillingState(), + 'countryName' => $card->getBillingCountry(), ), 'shipping' => array( - 'company' => $card->getShippingCompany(), - 'firstName' => $card->getShippingFirstName(), - 'lastName' => $card->getShippingLastName(), - 'streetAddress' => $card->getShippingAddress1(), - 'extendedAddress' => $card->getShippingAddress2(), - 'locality' => $card->getShippingCity(), - 'postalCode' => $card->getShippingPostcode(), - 'region' => $card->getShippingState(), - 'countryName' => $card->getShippingCountry(), + 'company' => $card->getShippingCompany(), + 'firstName' => $card->getShippingFirstName(), + 'lastName' => $card->getShippingLastName(), + 'streetAddress' => $card->getShippingAddress1(), + 'extendedAddress' => $card->getShippingAddress2(), + 'locality' => $card->getShippingCity(), + 'postalCode' => $card->getShippingPostcode(), + 'region' => $card->getShippingState(), + 'countryName' => $card->getShippingCountry(), ) ); } @@ -410,6 +420,7 @@ public function getOptionData() 'failOnDuplicatePaymentMethod' => $this->getFailOnDuplicatePaymentMethod(), 'holdInEscrow' => $this->getHoldInEscrow(), 'makeDefault' => $this->getMakeDefault(), + 'skipAdvancedFraudChecking' => $this->getSkipAdvancedFraudChecking(), 'storeInVault' => $this->getStoreInVault(), 'storeInVaultOnSuccess' => $this->getStoreInVaultOnSuccess(), 'storeShippingAddressInVault' => $this->getStoreShippingAddressInVault(), @@ -418,8 +429,8 @@ public function getOptionData() ); // Remove null values - $data = array_filter($data, function($value){ - return ! is_null($value); + $data = array_filter($data, function ($value) { + return !is_null($value); }); if (empty($data)) { @@ -433,6 +444,7 @@ public function getOptionData() * Set the items in this order * * @param ItemBag|array $items An array of items in this order + * * @return $this */ public function setItems($items) From a5049e588de974c2dc5b0d0b4815d5488b575b04 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 29 Dec 2020 15:13:29 -0800 Subject: [PATCH 4/7] Add support for skipping advanced fraud checking --- src/Message/AbstractRequest.php | 11 ----------- src/Message/PurchaseRequest.php | 14 +++++++++++++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 4437abc..19a7fe8 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -233,16 +233,6 @@ public function setServiceFeeAmount($value) return $this->setParameter('serviceFeeAmount', $value); } - public function setSkipAdvancedFraudChecking($value) - { - return $this->setParameter('skipAdvancedFraudChecking', (bool)$value); - } - - public function getSkipAdvancedFraudChecking() - { - return (bool)$this->getParameter('skipAdvancedFraudChecking'); - } - public function getStoreInVault() { return $this->getParameter('storeInVault'); @@ -420,7 +410,6 @@ public function getOptionData() 'failOnDuplicatePaymentMethod' => $this->getFailOnDuplicatePaymentMethod(), 'holdInEscrow' => $this->getHoldInEscrow(), 'makeDefault' => $this->getMakeDefault(), - 'skipAdvancedFraudChecking' => $this->getSkipAdvancedFraudChecking(), 'storeInVault' => $this->getStoreInVault(), 'storeInVaultOnSuccess' => $this->getStoreInVaultOnSuccess(), 'storeShippingAddressInVault' => $this->getStoreShippingAddressInVault(), diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 857f326..7f530da 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -1,4 +1,5 @@ getSkipAdvancedFraudChecking(); return $data; } + + public function setSkipAdvancedFraudChecking($value) + { + return $this->setParameter('skipAdvancedFraudChecking', (bool)$value); + } + + public function getSkipAdvancedFraudChecking() + { + return (bool)$this->getParameter('skipAdvancedFraudChecking'); + } } From 612bf06991b13415a7d6bd737c62387699dfc9b9 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 12 Apr 2021 10:33:32 -0700 Subject: [PATCH 5/7] Add support for billing address in CreatePaymentMethodRequest --- src/Message/CreatePaymentMethodRequest.php | 16 ++++++ .../CreatePaymentMethodRequestTest.php | 49 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/Message/CreatePaymentMethodRequest.php b/src/Message/CreatePaymentMethodRequest.php index 95b5f5f..4b33ed7 100644 --- a/src/Message/CreatePaymentMethodRequest.php +++ b/src/Message/CreatePaymentMethodRequest.php @@ -21,6 +21,22 @@ public function getData() $data['cardholderName'] = $cardholderName; } $data += $this->getOptionData(); + + $creditCard = $this->getCardData(); + + if (array_key_exists('billing', $creditCard) && !empty($billingAddress = $creditCard['billing'])) { + $data['billingAddress'] = [ + 'company' => $billingAddress['company'], + 'countryCodeAlpha3' => $billingAddress['countryName'], + 'extendedAddress' => $billingAddress['extendedAddress'], + 'firstName' => $billingAddress['firstName'], + 'lastName' => $billingAddress['lastName'], + 'locality' => $billingAddress['locality'], + 'postalCode' => $billingAddress['postalCode'], + 'region' => $billingAddress['region'], + 'streetAddress' => $billingAddress['streetAddress'], + ]; + } return $data; } diff --git a/tests/Message/CreatePaymentMethodRequestTest.php b/tests/Message/CreatePaymentMethodRequestTest.php index f4507f5..e31b303 100644 --- a/tests/Message/CreatePaymentMethodRequestTest.php +++ b/tests/Message/CreatePaymentMethodRequestTest.php @@ -55,6 +55,55 @@ public function testGetDataWithCardholderName() $this->assertSame($expectedData, $request->getData()); } + public function testGetDataWithAVS() + { + $request = $this->createPaymentMethodRequest(); + $request->initialize( + [ + 'customerId' => '4815162342', + 'token' => 'abc123', + 'addBillingAddressToPaymentMethod' => true, + 'failOnDuplicatePaymentMethod' => false, + 'makeDefault' => true, + 'verifyCard' => true, + 'card' => [ + 'billingFirstName' => 'John', + 'billingLastName' => 'Doe', + 'billingAddress1' => '123 Main Street', + 'billingAddress2' => 'Suite 101', + 'billingCity' => 'Los Angeles', + 'billingState' => 'CA', + 'billingPostcode' => '90210', + 'billingCountry' => 'USA', + 'billingCompany' => 'Apple Inc', + ], + ] + ); + + $expectedData = [ + 'customerId' => '4815162342', + 'paymentMethodNonce' => 'abc123', + 'options' => [ + 'addBillingAddressToPaymentMethod' => true, + 'failOnDuplicatePaymentMethod' => false, + 'makeDefault' => true, + 'verifyCard' => true, + ], + 'billingAddress' => [ + 'company' => 'Apple Inc', + 'countryCodeAlpha3' => 'USA', + 'extendedAddress' => 'Suite 101', + 'firstName' => 'John', + 'lastName' => 'Doe', + 'locality' => 'Los Angeles', + 'postalCode' => '90210', + 'region' => 'CA', + 'streetAddress' => '123 Main Street', + ], + ]; + $this->assertSame($expectedData, $request->getData()); + } + /** * @return CreatePaymentMethodRequest */ From 94393c23a9f0104be9a58f73812647c426a18083 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 12 Apr 2021 16:01:44 -0700 Subject: [PATCH 6/7] Add support for billing address in CreatePaymentMethodRequest --- src/Message/CreateCustomerRequest.php | 22 ++++++++- tests/Message/CreateCustomerRequestTest.php | 53 +++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index abacc6c..00bf91a 100644 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -10,7 +10,27 @@ class CreateCustomerRequest extends AbstractRequest { public function getData() { - return $this->getCustomerData(); + $data = $this->getCustomerData(); + + $data += $this->getOptionData(); + + $creditCard = $this->getCardData(); + + if (array_key_exists('billing', $creditCard) && !empty($billingAddress = $creditCard['billing'])) { + $data['billingAddress'] = [ + 'company' => $billingAddress['company'], + 'countryCodeAlpha3' => $billingAddress['countryName'], + 'extendedAddress' => $billingAddress['extendedAddress'], + 'firstName' => $billingAddress['firstName'], + 'lastName' => $billingAddress['lastName'], + 'locality' => $billingAddress['locality'], + 'postalCode' => $billingAddress['postalCode'], + 'region' => $billingAddress['region'], + 'streetAddress' => $billingAddress['streetAddress'], + ]; + } + + return $data; } /** diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 3bdfc97..f6f17be 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -49,4 +49,57 @@ public function testRequestData() $this->request->getCustomerData() ); } + + public function testGetDataWithAVS() + { + $this->request->initialize([ + 'customerData' => [ + 'firstName' => 'Mike', + 'lastName' => 'Jones', + 'email' => 'mike.jones@example.com', + 'paymentMethodNonce' => 'testnonce', + ], + 'addBillingAddressToPaymentMethod' => true, + 'failOnDuplicatePaymentMethod' => false, + 'makeDefault' => true, + 'verifyCard' => true, + 'card' => [ + 'billingFirstName' => 'John', + 'billingLastName' => 'Doe', + 'billingAddress1' => '123 Main Street', + 'billingAddress2' => 'Suite 101', + 'billingCity' => 'Los Angeles', + 'billingState' => 'CA', + 'billingPostcode' => '90210', + 'billingCountry' => 'USA', + 'billingCompany' => 'Apple Inc', + ], + ]); + + $expectedData = [ + 'firstName' => 'Mike', + 'lastName' => 'Jones', + 'email' => 'mike.jones@example.com', + 'paymentMethodNonce' => 'testnonce', + 'options' => [ + 'addBillingAddressToPaymentMethod' => true, + 'failOnDuplicatePaymentMethod' => false, + 'makeDefault' => true, + 'verifyCard' => true, + ], + 'billingAddress' => [ + 'company' => 'Apple Inc', + 'countryCodeAlpha3' => 'USA', + 'extendedAddress' => 'Suite 101', + 'firstName' => 'John', + 'lastName' => 'Doe', + 'locality' => 'Los Angeles', + 'postalCode' => '90210', + 'region' => 'CA', + 'streetAddress' => '123 Main Street', + ], + ]; + $this->assertSame($expectedData, $this->request->getData()); + } + } From 1473f770f5ef86c6a6c98146e93f758abaa66dde Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 12 Apr 2021 16:23:03 -0700 Subject: [PATCH 7/7] Add support for billing address in CreatePaymentMethodRequest --- src/Message/CreateCustomerRequest.php | 8 ++--- tests/Message/CreateCustomerRequestTest.php | 34 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index 00bf91a..c5ac5a7 100644 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -11,13 +11,13 @@ class CreateCustomerRequest extends AbstractRequest public function getData() { $data = $this->getCustomerData(); - - $data += $this->getOptionData(); - + + $data['creditCard'] = $this->getOptionData(); + $creditCard = $this->getCardData(); if (array_key_exists('billing', $creditCard) && !empty($billingAddress = $creditCard['billing'])) { - $data['billingAddress'] = [ + $data['creditCard']['billingAddress'] = [ 'company' => $billingAddress['company'], 'countryCodeAlpha3' => $billingAddress['countryName'], 'extendedAddress' => $billingAddress['extendedAddress'], diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index f6f17be..97f07ee 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -81,22 +81,24 @@ public function testGetDataWithAVS() 'lastName' => 'Jones', 'email' => 'mike.jones@example.com', 'paymentMethodNonce' => 'testnonce', - 'options' => [ - 'addBillingAddressToPaymentMethod' => true, - 'failOnDuplicatePaymentMethod' => false, - 'makeDefault' => true, - 'verifyCard' => true, - ], - 'billingAddress' => [ - 'company' => 'Apple Inc', - 'countryCodeAlpha3' => 'USA', - 'extendedAddress' => 'Suite 101', - 'firstName' => 'John', - 'lastName' => 'Doe', - 'locality' => 'Los Angeles', - 'postalCode' => '90210', - 'region' => 'CA', - 'streetAddress' => '123 Main Street', + 'creditCard' => [ + 'options' => [ + 'addBillingAddressToPaymentMethod' => true, + 'failOnDuplicatePaymentMethod' => false, + 'makeDefault' => true, + 'verifyCard' => true, + ], + 'billingAddress' => [ + 'company' => 'Apple Inc', + 'countryCodeAlpha3' => 'USA', + 'extendedAddress' => 'Suite 101', + 'firstName' => 'John', + 'lastName' => 'Doe', + 'locality' => 'Los Angeles', + 'postalCode' => '90210', + 'region' => 'CA', + 'streetAddress' => '123 Main Street', + ], ], ]; $this->assertSame($expectedData, $this->request->getData());