Skip to content

Commit

Permalink
Move some mystery numbers to constants.
Browse files Browse the repository at this point in the history
These are parameters (market place and device type) that come up time
and time again across gateways, but have different values for each
gateway, e.g. 0, 1, 2 vs E, M, R. A mapping should be standardised.
  • Loading branch information
judgej committed Dec 31, 2018
1 parent 5276ada commit 202c660
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/Message/AIMAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
*/
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 Down Expand Up @@ -71,14 +86,29 @@ protected function addRetail(\SimpleXMLElement $data)
}

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

if (!in_array($deviceType, [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ])) {
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, [ "0", "1", "2" ])) {
if (!in_array($marketType, [
static::MARKET_TYPE_ECOMMERCE,
static::MARKET_TYPE_MOTO,
static::MARKET_TYPE_RETAIL,
])) {
throw new InvalidRequestException("marketType `{$marketType}` is invalid");
}

Expand Down

0 comments on commit 202c660

Please sign in to comment.