Skip to content

Commit 5276ada

Browse files
committed
Merge branch 'issue-101' of https://github.com/samlitowitz/omnipay-authorizenet into issue101
2 parents 9ce6b52 + 5d0f9f6 commit 5276ada

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Message/AIMAuthorizeRequest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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
@@ -20,6 +21,7 @@ public function getData()
2021
$this->addSolutionId($data);
2122
$this->addBillingData($data);
2223
$this->addCustomerIP($data);
24+
$this->addRetail($data);
2325
$this->addTransactionSettings($data);
2426

2527
return $data;
@@ -54,4 +56,53 @@ protected function addCustomerIP(\SimpleXMLElement $data)
5456
$data->transactionRequest->customerIP = $ip;
5557
}
5658
}
59+
60+
protected function addRetail(\SimpleXMLElement $data)
61+
{
62+
$deviceType = $this->getDeviceType();
63+
$marketType = $this->getMarketType();
64+
65+
if (!isset($deviceType) && !isset($marketType)) {
66+
return;
67+
}
68+
69+
if (!isset($deviceType) && isset($marketType)) {
70+
throw new InvalidRequestException("deviceType is required if marketType is set");
71+
}
72+
73+
if (isset($deviceType) && !isset($marketType)) {
74+
$marketType = "2";
75+
}
76+
77+
if (!in_array($deviceType, [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ])) {
78+
throw new InvalidRequestException("deviceType `{$deviceType}` is invalid");
79+
}
80+
81+
if (!in_array($marketType, [ "0", "1", "2" ])) {
82+
throw new InvalidRequestException("marketType `{$marketType}` is invalid");
83+
}
84+
85+
$data->transactionRequest->retail->marketType = $marketType;
86+
$data->transactionRequest->retail->deviceType = $deviceType;
87+
}
88+
89+
public function getDeviceType()
90+
{
91+
return $this->getParameter('deviceType');
92+
}
93+
94+
public function setDeviceType($value)
95+
{
96+
return $this->setParameter('deviceType', $value);
97+
}
98+
99+
public function getMarketType()
100+
{
101+
return $this->getParameter('marketType');
102+
}
103+
104+
public function setMarketType($value)
105+
{
106+
return $this->setParameter('marketType', $value);
107+
}
57108
}

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)