Skip to content

Commit

Permalink
Merge pull request #120 from thephpleague/issue101
Browse files Browse the repository at this point in the history
Issue101 - Support DeviceType and MarketType
  • Loading branch information
judgej authored Dec 31, 2018
2 parents 9ce6b52 + 202c660 commit a9738c3
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/Message/AIMAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@
namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\CreditCard;
use Omnipay\Common\Exception\InvalidRequestException;

/**
* Authorize.Net AIM Authorize Request
*/
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()
Expand All @@ -20,6 +36,7 @@ public function getData()
$this->addSolutionId($data);
$this->addBillingData($data);
$this->addCustomerIP($data);
$this->addRetail($data);
$this->addTransactionSettings($data);

return $data;
Expand Down Expand Up @@ -54,4 +71,68 @@ protected function addCustomerIP(\SimpleXMLElement $data)
$data->transactionRequest->customerIP = $ip;
}
}

protected function addRetail(\SimpleXMLElement $data)
{
$deviceType = $this->getDeviceType();
$marketType = $this->getMarketType();

if (!isset($deviceType) && !isset($marketType)) {
return;
}

if (!isset($deviceType) && isset($marketType)) {
throw new InvalidRequestException("deviceType is required if marketType is set");
}

if (isset($deviceType) && !isset($marketType)) {
$marketType = static::MARKET_TYPE_RETAIL;
}

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, [
static::MARKET_TYPE_ECOMMERCE,
static::MARKET_TYPE_MOTO,
static::MARKET_TYPE_RETAIL,
])) {
throw new InvalidRequestException("marketType `{$marketType}` is invalid");
}

$data->transactionRequest->retail->marketType = $marketType;
$data->transactionRequest->retail->deviceType = $deviceType;
}

public function getDeviceType()
{
return $this->getParameter('deviceType');
}

public function setDeviceType($value)
{
return $this->setParameter('deviceType', $value);
}

public function getMarketType()
{
return $this->getParameter('marketType');
}

public function setMarketType($value)
{
return $this->setParameter('marketType', $value);
}
}
5 changes: 5 additions & 0 deletions tests/Message/AIMAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function setUp()
'card' => $card,
'duplicateWindow' => 0,
'solutionId' => 'SOL12345ID',
'marketType' => '2',
'deviceType' => '1',
)
);
}
Expand All @@ -35,6 +37,8 @@ public function testGetData()
$this->assertEquals('cust-id', $data->transactionRequest->customer->id);
$this->assertEquals('[email protected]', $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.
Expand All @@ -51,6 +55,7 @@ public function testGetData()
"billTo",
"shipTo",
"customerIP",
"retail",
"transactionSettings"
);
$this->assertEquals($keys, $transactionRequestProperties);
Expand Down

0 comments on commit a9738c3

Please sign in to comment.