From c56f9821dc7c02738709b013f59909a39c931c59 Mon Sep 17 00:00:00 2001 From: Anush Ramani Date: Fri, 29 Apr 2016 15:25:31 +0530 Subject: [PATCH] CS-258 Authorize.Net returning "deviceType is invalid" error (#15) * Point to the origin omnipay-common * Fix code style * Peg to a proper omnipay-common version dependency * Use correct endpoints form DPM and SIM * Allow overriding the `deviceType` --- src/AIMGateway.php | 30 +++++++++++++++++++++++ src/Message/AIMAbstractRequest.php | 10 ++++++++ src/Message/AIMAuthorizeRequest.php | 2 +- src/Message/SIMAbstractRequest.php | 10 ++++++++ src/SIMGateway.php | 6 ++++- tests/AIMGatewayTest.php | 16 ++++++++++++ tests/CIMGatewayTest.php | 16 ++++++++++++ tests/DPMGatewayTest.php | 24 ++++++++++++++++-- tests/Message/AIMAuthorizeRequestTest.php | 6 +++-- tests/SIMGatewayTest.php | 16 ++++++++++++ 10 files changed, 130 insertions(+), 6 deletions(-) diff --git a/src/AIMGateway.php b/src/AIMGateway.php index fabfd05f..53b6eea1 100644 --- a/src/AIMGateway.php +++ b/src/AIMGateway.php @@ -28,6 +28,7 @@ public function getDefaultParameters() 'developerMode' => false, 'liveEndpoint' => 'https://api.authorize.net/xml/v1/request.api', 'developerEndpoint' => 'https://apitest.authorize.net/xml/v1/request.api', + 'deviceType' => 1 // Device used to make the transaction. Required for card present. "1" = Unknown. ); } @@ -97,6 +98,35 @@ public function setDuplicateWindow($value) return $this->setParameter('duplicateWindow', $value); } + public function getDeviceType() + { + return $this->getParameter('deviceType'); + } + + /** + * Sets the type of device used to collect the credit card data. A device type is required for card present + * transactions. + * + * 1 = Unknown + * 2 = Unattended Terminal + * 3 = Self Service Terminal + * 4 = Electronic Cash Register + * 5 = Personal Computer-Based Terminal + * 6 = AirPay + * 7 = Wireless POS + * 8 = Website + * 9 = Dial Terminal + * 10 = Virtual Terminal + * + * @see http://developer.authorize.net/api/reference/#payment-transactions-charge-a-credit-card + * @param $value + * @return $this + */ + public function setDeviceType($value) + { + return $this->setParameter('deviceType', $value); + } + /** * @param array $parameters * @return AIMAuthorizeRequest diff --git a/src/Message/AIMAbstractRequest.php b/src/Message/AIMAbstractRequest.php index 129b8d73..84f2d2f0 100644 --- a/src/Message/AIMAbstractRequest.php +++ b/src/Message/AIMAbstractRequest.php @@ -100,6 +100,16 @@ public function getEndpoint() return $this->getDeveloperMode() ? $this->getDeveloperEndpoint() : $this->getLiveEndpoint(); } + public function getDeviceType() + { + return $this->getParameter('deviceType'); + } + + public function setDeviceType($value) + { + return $this->setParameter('deviceType', $value); + } + /** * @return TransactionReference */ diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index f56135a0..7df44c8d 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -59,7 +59,7 @@ protected function addRetail(\SimpleXMLElement $data) if ($this->isCardPresent()) { // Retail element is required for card present transactions $data->transactionRequest->retail->marketType = 2; - $data->transactionRequest->retail->deviceType = 1; + $data->transactionRequest->retail->deviceType = $this->getDeviceType(); } } } diff --git a/src/Message/SIMAbstractRequest.php b/src/Message/SIMAbstractRequest.php index 6fb01c68..b8f52e6a 100644 --- a/src/Message/SIMAbstractRequest.php +++ b/src/Message/SIMAbstractRequest.php @@ -84,6 +84,16 @@ public function getDeveloperEndpoint() return $this->getParameter('developerEndpoint'); } + public function getDeviceType() + { + return $this->getParameter('deviceType'); + } + + public function setDeviceType($value) + { + return $this->setParameter('deviceType', $value); + } + /** * Base data used only for the AIM API. */ diff --git a/src/SIMGateway.php b/src/SIMGateway.php index 23f1941e..c5ccbe5c 100644 --- a/src/SIMGateway.php +++ b/src/SIMGateway.php @@ -15,7 +15,11 @@ public function getName() public function getDefaultParameters() { $parameters = parent::getDefaultParameters(); - $parameters['hashSecret'] = ''; + $parameters = array_merge($parameters, array( + 'hashSecret' => '', + 'liveEndpoint' => 'https://secure2.authorize.net/gateway/transact.dll', + 'developerEndpoint' => 'https://test.authorize.net/gateway/transact.dll' + )); return $parameters; } diff --git a/tests/AIMGatewayTest.php b/tests/AIMGatewayTest.php index f45478b0..81a51537 100644 --- a/tests/AIMGatewayTest.php +++ b/tests/AIMGatewayTest.php @@ -40,6 +40,22 @@ public function setUp() ); } + public function testLiveEndpoint() + { + $this->assertEquals( + 'https://api.authorize.net/xml/v1/request.api', + $this->gateway->getLiveEndpoint() + ); + } + + public function testDeveloperEndpoint() + { + $this->assertEquals( + 'https://apitest.authorize.net/xml/v1/request.api', + $this->gateway->getDeveloperEndpoint() + ); + } + private function getExpiry($card) { return str_pad($card['expiryMonth'] . $card['expiryYear'], 6, '0', STR_PAD_LEFT); diff --git a/tests/CIMGatewayTest.php b/tests/CIMGatewayTest.php index b76e1048..8c785f25 100644 --- a/tests/CIMGatewayTest.php +++ b/tests/CIMGatewayTest.php @@ -46,6 +46,22 @@ public function setUp() ); } + public function testLiveEndpoint() + { + $this->assertEquals( + 'https://api.authorize.net/xml/v1/request.api', + $this->gateway->getLiveEndpoint() + ); + } + + public function testDeveloperEndpoint() + { + $this->assertEquals( + 'https://apitest.authorize.net/xml/v1/request.api', + $this->gateway->getDeveloperEndpoint() + ); + } + public function testCreateCardSuccess() { $this->setMockHttpResponse(array('CIMCreateCardSuccess.txt','CIMGetPaymentProfileSuccess.txt')); diff --git a/tests/DPMGatewayTest.php b/tests/DPMGatewayTest.php index e9b3851d..3140ef62 100644 --- a/tests/DPMGatewayTest.php +++ b/tests/DPMGatewayTest.php @@ -3,10 +3,14 @@ namespace Omnipay\AuthorizeNet; use Omnipay\Tests\GatewayTestCase; -//use Omnipay\AuthorizeNet\SIMGatewayTest; -class DPMGatewayTest extends GatewayTestCase //SIMGatewayTest +class DPMGatewayTest extends GatewayTestCase { + /** @var DPMGateway */ + protected $gateway; + /** @var array */ + private $options; + public function setUp() { parent::setUp(); @@ -23,6 +27,22 @@ public function setUp() ); } + public function testLiveEndpoint() + { + $this->assertEquals( + 'https://secure2.authorize.net/gateway/transact.dll', + $this->gateway->getLiveEndpoint() + ); + } + + public function testDeveloperEndpoint() + { + $this->assertEquals( + 'https://test.authorize.net/gateway/transact.dll', + $this->gateway->getDeveloperEndpoint() + ); + } + public function testAuthorize() { $response = $this->gateway->authorize($this->options)->send(); diff --git a/tests/Message/AIMAuthorizeRequestTest.php b/tests/Message/AIMAuthorizeRequestTest.php index 7f457115..2bc0b80a 100644 --- a/tests/Message/AIMAuthorizeRequestTest.php +++ b/tests/Message/AIMAuthorizeRequestTest.php @@ -63,7 +63,8 @@ public function testGetDataCardPresentTrack1() $card['tracks'] = '%B4242424242424242^SMITH/JOHN ^2511126100000000000000444000000?;4242424242424242=25111269999944401?'; $this->request->initialize(array( 'amount' => '12.12', - 'card' => $card + 'card' => $card, + 'deviceType' => 1 )); $data = $this->request->getData(); @@ -83,7 +84,8 @@ public function testGetDataCardPresentTrack2() $card['tracks'] = ';4242424242424242=25111269999944401?'; $this->request->initialize(array( 'amount' => '12.12', - 'card' => $card + 'card' => $card, + 'deviceType' => 1 )); $data = $this->request->getData(); diff --git a/tests/SIMGatewayTest.php b/tests/SIMGatewayTest.php index 5ff89c69..7765eda9 100644 --- a/tests/SIMGatewayTest.php +++ b/tests/SIMGatewayTest.php @@ -24,6 +24,22 @@ public function setUp() ); } + public function testLiveEndpoint() + { + $this->assertEquals( + 'https://secure2.authorize.net/gateway/transact.dll', + $this->gateway->getLiveEndpoint() + ); + } + + public function testDeveloperEndpoint() + { + $this->assertEquals( + 'https://test.authorize.net/gateway/transact.dll', + $this->gateway->getDeveloperEndpoint() + ); + } + public function testAuthorize() { $response = $this->gateway->authorize($this->options)->send();