diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index 5b863feb..8489f6f3 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -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() @@ -20,6 +36,7 @@ public function getData() $this->addSolutionId($data); $this->addBillingData($data); $this->addCustomerIP($data); + $this->addRetail($data); $this->addTransactionSettings($data); return $data; @@ -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); + } } diff --git a/tests/Message/AIMAuthorizeRequestTest.php b/tests/Message/AIMAuthorizeRequestTest.php index e410a8f5..9d82fc6f 100644 --- a/tests/Message/AIMAuthorizeRequestTest.php +++ b/tests/Message/AIMAuthorizeRequestTest.php @@ -22,6 +22,8 @@ public function setUp() 'card' => $card, 'duplicateWindow' => 0, 'solutionId' => 'SOL12345ID', + 'marketType' => '2', + 'deviceType' => '1', ) ); } @@ -35,6 +37,8 @@ public function testGetData() $this->assertEquals('cust-id', $data->transactionRequest->customer->id); $this->assertEquals('example@example.net', $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. @@ -51,6 +55,7 @@ public function testGetData() "billTo", "shipTo", "customerIP", + "retail", "transactionSettings" ); $this->assertEquals($keys, $transactionRequestProperties);