Skip to content

Commit a9738c3

Browse files
authored
Merge pull request #120 from thephpleague/issue101
Issue101 - Support DeviceType and MarketType
2 parents 9ce6b52 + 202c660 commit a9738c3

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

src/Message/AIMAuthorizeRequest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,28 @@
33
namespace Omnipay\AuthorizeNet\Message;
44

55
use Omnipay\Common\CreditCard;
6+
use Omnipay\Common\Exception\InvalidRequestException;
67

78
/**
89
* Authorize.Net AIM Authorize Request
910
*/
1011
class AIMAuthorizeRequest extends AIMAbstractRequest
1112
{
13+
const MARKET_TYPE_ECOMMERCE = '0';
14+
const MARKET_TYPE_MOTO = '1';
15+
const MARKET_TYPE_RETAIL = '2';
16+
17+
const DEVICE_TYPE_UNKNOWN = '1';
18+
const DEVICE_TYPE_UNATTENDED_TERMINAL = '2';
19+
const DEVICE_TYPE_SELF_SERVICE_TERMINAL = '3';
20+
const DEVICE_TYPE_ELECTRONIC_CASH_REGISTER = '4';
21+
const DEVICE_TYPE_PC_BASED_TERMINAL = '5';
22+
const DEVICE_TYPE_AIRPAY = '6';
23+
const DEVICE_TYPE_WIRELESS_POS = '7';
24+
const DEVICE_TYPE_WEBSITE = '8';
25+
const DEVICE_TYPE_DIAL_TERMINAL = '9';
26+
const DEVICE_TYPE_VIRTUAL_TERMINAL = '10';
27+
1228
protected $action = 'authOnlyTransaction';
1329

1430
public function getData()
@@ -20,6 +36,7 @@ public function getData()
2036
$this->addSolutionId($data);
2137
$this->addBillingData($data);
2238
$this->addCustomerIP($data);
39+
$this->addRetail($data);
2340
$this->addTransactionSettings($data);
2441

2542
return $data;
@@ -54,4 +71,68 @@ protected function addCustomerIP(\SimpleXMLElement $data)
5471
$data->transactionRequest->customerIP = $ip;
5572
}
5673
}
74+
75+
protected function addRetail(\SimpleXMLElement $data)
76+
{
77+
$deviceType = $this->getDeviceType();
78+
$marketType = $this->getMarketType();
79+
80+
if (!isset($deviceType) && !isset($marketType)) {
81+
return;
82+
}
83+
84+
if (!isset($deviceType) && isset($marketType)) {
85+
throw new InvalidRequestException("deviceType is required if marketType is set");
86+
}
87+
88+
if (isset($deviceType) && !isset($marketType)) {
89+
$marketType = static::MARKET_TYPE_RETAIL;
90+
}
91+
92+
if (!in_array($deviceType, [
93+
static::DEVICE_TYPE_UNKNOWN,
94+
static::DEVICE_TYPE_UNATTENDED_TERMINAL,
95+
static::DEVICE_TYPE_SELF_SERVICE_TERMINAL,
96+
static::DEVICE_TYPE_ELECTRONIC_CASH_REGISTER,
97+
static::DEVICE_TYPE_PC_BASED_TERMINAL,
98+
static::DEVICE_TYPE_AIRPAY,
99+
static::DEVICE_TYPE_WIRELESS_POS,
100+
static::DEVICE_TYPE_WEBSITE,
101+
static::DEVICE_TYPE_DIAL_TERMINAL,
102+
static::DEVICE_TYPE_VIRTUAL_TERMINAL,
103+
])) {
104+
throw new InvalidRequestException("deviceType `{$deviceType}` is invalid");
105+
}
106+
107+
if (!in_array($marketType, [
108+
static::MARKET_TYPE_ECOMMERCE,
109+
static::MARKET_TYPE_MOTO,
110+
static::MARKET_TYPE_RETAIL,
111+
])) {
112+
throw new InvalidRequestException("marketType `{$marketType}` is invalid");
113+
}
114+
115+
$data->transactionRequest->retail->marketType = $marketType;
116+
$data->transactionRequest->retail->deviceType = $deviceType;
117+
}
118+
119+
public function getDeviceType()
120+
{
121+
return $this->getParameter('deviceType');
122+
}
123+
124+
public function setDeviceType($value)
125+
{
126+
return $this->setParameter('deviceType', $value);
127+
}
128+
129+
public function getMarketType()
130+
{
131+
return $this->getParameter('marketType');
132+
}
133+
134+
public function setMarketType($value)
135+
{
136+
return $this->setParameter('marketType', $value);
137+
}
57138
}

tests/Message/AIMAuthorizeRequestTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function setUp()
2222
'card' => $card,
2323
'duplicateWindow' => 0,
2424
'solutionId' => 'SOL12345ID',
25+
'marketType' => '2',
26+
'deviceType' => '1',
2527
)
2628
);
2729
}
@@ -35,6 +37,8 @@ public function testGetData()
3537
$this->assertEquals('cust-id', $data->transactionRequest->customer->id);
3638
$this->assertEquals('[email protected]', $data->transactionRequest->customer->email);
3739
$this->assertEquals('SOL12345ID', $data->transactionRequest->solution->id);
40+
$this->assertEquals('2', $data->transactionRequest->retail->marketType);
41+
$this->assertEquals('1', $data->transactionRequest->retail->deviceType);
3842

3943
// Issue #38 Make sure the transactionRequest properties are correctly ordered.
4044
// This feels messy, but works.
@@ -51,6 +55,7 @@ public function testGetData()
5155
"billTo",
5256
"shipTo",
5357
"customerIP",
58+
"retail",
5459
"transactionSettings"
5560
);
5661
$this->assertEquals($keys, $transactionRequestProperties);

0 commit comments

Comments
 (0)