Skip to content

Commit

Permalink
CS-258 Authorize.Net returning "deviceType is invalid" error (#15)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
anush authored and rushi committed Apr 29, 2016
1 parent e009033 commit c56f982
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/AIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
);
}

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Message/AIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Message/AIMAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
10 changes: 10 additions & 0 deletions src/Message/SIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/SIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/AIMGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions tests/CIMGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
24 changes: 22 additions & 2 deletions tests/DPMGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions tests/Message/AIMAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions tests/SIMGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c56f982

Please sign in to comment.