From 4bb8e184932ac437e6091815586c74e7713bc2fc Mon Sep 17 00:00:00 2001 From: Sam L Date: Mon, 15 Jan 2018 15:05:53 -0500 Subject: [PATCH 1/6] Add retail data to authOnlyTransactions and authCaptureTransactions --- src/Message/AIMAuthorizeRequest.php | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index a4f0a58e..aeea9d48 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -20,6 +20,7 @@ public function getData() $this->addSolutionId($data); $this->addBillingData($data); $this->addCustomerIP($data); + $this->addRetail($data); $this->addTransactionSettings($data); return $data; @@ -52,4 +53,33 @@ protected function addCustomerIP(\SimpleXMLElement $data) $data->transactionRequest->customerIP = $ip; } } + + protected function addRetail(\SimpleXMLElement $data) + { + $retail = $this->getParameter('retail'); + if (isset($retail)) { + $data->transactionRequest->retail = $this->getParameter('retail'); + } + } + + /** + * Gets the retail data of the request from the gateway. + * + * @return array + */ + public function getRetail() + { + return $this-getRetail(); + } + + /** + * Sets the retail data in this request + * + * @param array $value An associative arrray with keys marketType and/or deviceType + * @return AIMAuthorizeRequest Provides a fluent interface + */ + public function setRetail($value) + { + return $this->setParameter('retail', $value); + } } From eb59611f0d97ea42eadc925d78c69325b39a248e Mon Sep 17 00:00:00 2001 From: Sam L Date: Tue, 16 Jan 2018 09:13:04 -0500 Subject: [PATCH 2/6] Seperate retail into deviceType and marketType --- src/Message/AIMAuthorizeRequest.php | 59 ++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index aeea9d48..95f7fc60 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -3,6 +3,7 @@ namespace Omnipay\AuthorizeNet\Message; use Omnipay\Common\CreditCard; +use Omnipay\Common\Exception\InvalidRequestException; /** * Authorize.Net AIM Authorize Request @@ -56,30 +57,52 @@ protected function addCustomerIP(\SimpleXMLElement $data) protected function addRetail(\SimpleXMLElement $data) { - $retail = $this->getParameter('retail'); - if (isset($retail)) { - $data->transactionRequest->retail = $this->getParameter('retail'); + $deviceType = $this->getDeviceType(); + $marketType = $this->getMarketType(); + + if (!isset($deviceType) && !isset($marketType)) { + return; + } + + if (!isset($deviceType) && isset($marketType)) { + throw new InvalidRequestException(); + } + + if (isset($deviceType) && !isset($marketType)) { + $marketType = "2"; + } + + if (!in_array($deviceType, [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ])) { + throw new InvalidRequestException(); } + + if (!in_array($marketType, [ "0", "1", "2" ])) { + throw new InvalidRequestException(); + } + + $data->transactionRequest->retail = [ + 'marketType' => $marketType, + 'deviceType' => $deviceType, + ]; + } + + public function getDeviceType() + { + return $this->getParameter('deviceType'); } - /** - * Gets the retail data of the request from the gateway. - * - * @return array - */ - public function getRetail() + public function setDeviceType($value) + { + return $this->setParameter('deviceType', $value); + } + + public function getMarketType() { - return $this-getRetail(); + return $this->getParameter('marketType'); } - /** - * Sets the retail data in this request - * - * @param array $value An associative arrray with keys marketType and/or deviceType - * @return AIMAuthorizeRequest Provides a fluent interface - */ - public function setRetail($value) + public function setMarketType($value) { - return $this->setParameter('retail', $value); + return $this->setParameter('marketType', $value); } } From 898f7b02dc5f111e81a614c18631c55d599da046 Mon Sep 17 00:00:00 2001 From: Sam L Date: Wed, 17 Jan 2018 13:18:06 -0500 Subject: [PATCH 3/6] Make array object --- src/Message/AIMAuthorizeRequest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index 95f7fc60..a4872af6 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -80,10 +80,8 @@ protected function addRetail(\SimpleXMLElement $data) throw new InvalidRequestException(); } - $data->transactionRequest->retail = [ - 'marketType' => $marketType, - 'deviceType' => $deviceType, - ]; + $data->transactionRequest->retail->marketType = $marketType; + $data->transactionRequest->retail->deviceType = $deviceType; } public function getDeviceType() From d56df2060359387314d18670b8c4a7e0a530da0a Mon Sep 17 00:00:00 2001 From: Sam L Date: Wed, 17 Jan 2018 13:24:38 -0500 Subject: [PATCH 4/6] Add error messages --- src/Message/AIMAuthorizeRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index a4872af6..1fa2b2d6 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -65,7 +65,7 @@ protected function addRetail(\SimpleXMLElement $data) } if (!isset($deviceType) && isset($marketType)) { - throw new InvalidRequestException(); + throw new InvalidRequestException("deviceType is required if marketType is set"); } if (isset($deviceType) && !isset($marketType)) { @@ -73,11 +73,11 @@ protected function addRetail(\SimpleXMLElement $data) } if (!in_array($deviceType, [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ])) { - throw new InvalidRequestException(); + throw new InvalidRequestException("deviceType `{$deviceType}` is invalid"); } if (!in_array($marketType, [ "0", "1", "2" ])) { - throw new InvalidRequestException(); + throw new InvalidRequestException("marketType `{$marketType}` is invalid"); } $data->transactionRequest->retail->marketType = $marketType; From 5d0f9f643e8b78ed6e959b46ce9ca0e0726f9770 Mon Sep 17 00:00:00 2001 From: Sam L Date: Wed, 17 Jan 2018 13:35:46 -0500 Subject: [PATCH 5/6] Add test for retail values in AIMAuthorizeRequest --- tests/Message/AIMAuthorizeRequestTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Message/AIMAuthorizeRequestTest.php b/tests/Message/AIMAuthorizeRequestTest.php index e410a8f5..9d82fc6f 100644 --- a/tests/Message/AIMAuthorizeRequestTest.php +++ b/tests/Message/AIMAuthorizeRequestTest.php @@ -22,6 +22,8 @@ public function setUp() 'card' => $card, 'duplicateWindow' => 0, 'solutionId' => 'SOL12345ID', + 'marketType' => '2', + 'deviceType' => '1', ) ); } @@ -35,6 +37,8 @@ public function testGetData() $this->assertEquals('cust-id', $data->transactionRequest->customer->id); $this->assertEquals('example@example.net', $data->transactionRequest->customer->email); $this->assertEquals('SOL12345ID', $data->transactionRequest->solution->id); + $this->assertEquals('2', $data->transactionRequest->retail->marketType); + $this->assertEquals('1', $data->transactionRequest->retail->deviceType); // Issue #38 Make sure the transactionRequest properties are correctly ordered. // This feels messy, but works. @@ -51,6 +55,7 @@ public function testGetData() "billTo", "shipTo", "customerIP", + "retail", "transactionSettings" ); $this->assertEquals($keys, $transactionRequestProperties); From 202c660a71cdb1b3e6c9a21c70064e3b1984a1ab Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Mon, 31 Dec 2018 00:05:33 +0000 Subject: [PATCH 6/6] Move some mystery numbers to constants. These are parameters (market place and device type) that come up time and time again across gateways, but have different values for each gateway, e.g. 0, 1, 2 vs E, M, R. A mapping should be standardised. --- src/Message/AIMAuthorizeRequest.php | 36 ++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index 79ba07a7..8489f6f3 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -10,6 +10,21 @@ */ class AIMAuthorizeRequest extends AIMAbstractRequest { + const MARKET_TYPE_ECOMMERCE = '0'; + const MARKET_TYPE_MOTO = '1'; + const MARKET_TYPE_RETAIL = '2'; + + const DEVICE_TYPE_UNKNOWN = '1'; + const DEVICE_TYPE_UNATTENDED_TERMINAL = '2'; + const DEVICE_TYPE_SELF_SERVICE_TERMINAL = '3'; + const DEVICE_TYPE_ELECTRONIC_CASH_REGISTER = '4'; + const DEVICE_TYPE_PC_BASED_TERMINAL = '5'; + const DEVICE_TYPE_AIRPAY = '6'; + const DEVICE_TYPE_WIRELESS_POS = '7'; + const DEVICE_TYPE_WEBSITE = '8'; + const DEVICE_TYPE_DIAL_TERMINAL = '9'; + const DEVICE_TYPE_VIRTUAL_TERMINAL = '10'; + protected $action = 'authOnlyTransaction'; public function getData() @@ -71,14 +86,29 @@ protected function addRetail(\SimpleXMLElement $data) } if (isset($deviceType) && !isset($marketType)) { - $marketType = "2"; + $marketType = static::MARKET_TYPE_RETAIL; } - if (!in_array($deviceType, [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ])) { + if (!in_array($deviceType, [ + static::DEVICE_TYPE_UNKNOWN, + static::DEVICE_TYPE_UNATTENDED_TERMINAL, + static::DEVICE_TYPE_SELF_SERVICE_TERMINAL, + static::DEVICE_TYPE_ELECTRONIC_CASH_REGISTER, + static::DEVICE_TYPE_PC_BASED_TERMINAL, + static::DEVICE_TYPE_AIRPAY, + static::DEVICE_TYPE_WIRELESS_POS, + static::DEVICE_TYPE_WEBSITE, + static::DEVICE_TYPE_DIAL_TERMINAL, + static::DEVICE_TYPE_VIRTUAL_TERMINAL, + ])) { throw new InvalidRequestException("deviceType `{$deviceType}` is invalid"); } - if (!in_array($marketType, [ "0", "1", "2" ])) { + if (!in_array($marketType, [ + static::MARKET_TYPE_ECOMMERCE, + static::MARKET_TYPE_MOTO, + static::MARKET_TYPE_RETAIL, + ])) { throw new InvalidRequestException("marketType `{$marketType}` is invalid"); }