GatewayManager extends AppModel
Gateway manager. Handles installing/uninstalling and configuring payment gateways.
Table of Contents
Methods
| __construct() | Initialize GatewayManager |
| add() | Adds the gateway to the system |
| currencyExists() | Verifies that the currency given exists for this gateway |
| delete() | Permanently and completely removes the gateway specified by $gateway_id |
| edit() | Updates the gateway installed on the system |
| get() | Fetches a single installed gateway including meta data and currency association |
| getAll() | Lists all installed gateways |
| getAllInstalledNonmerchant() | Fetches all requested installed nonmerchant gateways including meta data and currency association for each. Fetches based on company_id and currency. |
| getAvailable() | Lists all available gateways (those that exist on the file system) |
| getByClass() | Fetches a gateway for a given company, or all gateways installed in the system for the given gateway class |
| getCurrencies() | Fetches all currencies configured to be accepted by the given gateway |
| getInstalled() | Fetches all gateways installed in the system |
| getInstalledMerchant() | Fetches a single installed merchant gateway including meta data and currency association. Fetches based on $company_id and optionally by specifying a specific gateway ID. |
| getInstalledNonmerchant() | Fetches the requested installed nonmerchant gateway including meta data and currency association. Fetches based on company_id and gateway name. |
| isInstalled() | Checks whether the given gateway is installed for the specificed company |
| upgrade() | Runs the gateway's upgrade method to upgrade the gateway to match that of the gateway's file version. |
| validateCurrencyNotDefault() | Validates that currencies being removed from a merchant gateway are not set as default |
| verifyCurrency() | Verifies whether or not the given currency is already in use by a merchant gateway for this company |
| getCurrencyRules() | Fetches the rules for adding/editing currencies for a gateway |
| getGatewayInfo() | Fetch information about the given gateway object |
| getMeta() | Fetches all meta data associated with the given gateway |
| loadGateway() | Instantiates the given gateway and returns its instance |
| setCurrencies() | Sets accepted currencies for the given gateway |
| setDefaultCurrencies() | Sets the gateway as default for currencies that don't have a default assigned |
| setGatewayFields() | Sets additional info on the given gateway object |
| setGatewayInfo() | Sets additional info on the given gateway object |
| setMeta() | Sets meta data for the given gateway, overwriting all existing meta data |
| setVersion() | Updates all installed gateways with the version given |
Methods
__construct()
Initialize GatewayManager
public
__construct() : mixed
add()
Adds the gateway to the system
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of gateway data including:
- company_id The ID of the company the gateway belongs to
- class The class name for this gateway (in /components/gateways/)
- type The type of gateway ('merchant', 'nonmerchant', 'hybrid')
Return values
int —The ID of the gateway installed, void on error
currencyExists()
Verifies that the currency given exists for this gateway
public
currencyExists(string $currency, mixed $gateway) : bool
Parameters
- $currency : string
-
The currency code to verify
- $gateway : mixed
-
A reference to the gateway object to verify the currency against
Return values
bool —True if the currency exists for the gateway, false otherwise
delete()
Permanently and completely removes the gateway specified by $gateway_id
public
delete(int $gateway_id) : mixed
Parameters
- $gateway_id : int
-
The ID of the gateway to permanently remove
edit()
Updates the gateway installed on the system
public
edit(int $gateway_id, array<string|int, mixed> $vars) : mixed
Parameters
- $gateway_id : int
-
The ID of the gateway to update
- $vars : array<string|int, mixed>
-
An array of gateway data including:
- name The name of the gateway - optional
- class The class name for this gateway (in /components/gateways/) - optional
- type The type of gateway ('merchant', 'nonmerchant', 'hybrid') - optional
- currencies A numerically indexed array of accepted currencies codes (ISO 4217) - optional
- meta A key/value array of meta data
get()
Fetches a single installed gateway including meta data and currency association
public
get(int $gateway_id) : mixed
Parameters
- $gateway_id : int
-
The ID of the gateway to fetch
Return values
mixed —A stdClass object representing the installed gateway, false if no such gateway exists
getAll()
Lists all installed gateways
public
getAll(int $company_id[, string $type = null ][, array<string|int, mixed> $order = ['gateways.name' => 'ASC'] ][, string $currency = null ][, int $client_id = null ][, int $client_group_id = null ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The company ID
- $type : string = null
-
The type of gateways to fetch ("merchant", "nonmerchant") set to null for both
- $order : array<string|int, mixed> = ['gateways.name' => 'ASC']
-
A key/value array where each key is a field and each value is the direction to sort
- $currency : string = null
-
The ISO 4217 currency code
- $client_id : int = null
-
The ID of the client to fetch only the gateways available for this client
- $client_group_id : int = null
-
The ID of the client group to fetch only the gateways available for this client group
Return values
array<string|int, mixed> —An array of stdClass objects representing installed gateways
getAllInstalledNonmerchant()
Fetches all requested installed nonmerchant gateways including meta data and currency association for each. Fetches based on company_id and currency.
public
getAllInstalledNonmerchant(int $company_id[, int $currency = null ][, int $client_id = null ][, int $client_group_id = null ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The ID of the company in use
- $currency : int = null
-
The ISO 4217 currency code to process
- $client_id : int = null
-
The ID of the client to fetch only the gateways available for this client
- $client_group_id : int = null
-
The ID of the client group to fetch only the gateways available for this client group
Return values
array<string|int, mixed> —An array of stdClass objects, each representing an installed gateway
getAvailable()
Lists all available gateways (those that exist on the file system)
public
getAvailable([string $type = null ][, int $company_id = null ]) : array<string|int, mixed>
Parameters
- $type : string = null
-
The type of gateways to look for ("merchant", "nonmerchant"). Set to null for both
- $company_id : int = null
-
The ID of the company to check availability status for
Return values
array<string|int, mixed> —An array of stdClass objects representing available gateways
getByClass()
Fetches a gateway for a given company, or all gateways installed in the system for the given gateway class
public
getByClass(string $class[, int $company_id = null ]) : array<string|int, mixed>
Parameters
- $class : string
-
The class name (in file_case)
- $company_id : int = null
-
The ID of the company to fetch gateways for (optional, default null for all)
Return values
array<string|int, mixed> —An array of stdClass objects, each representing an installed gateway record
getCurrencies()
Fetches all currencies configured to be accepted by the given gateway
public
getCurrencies(int $gateway_id) : array<string|int, mixed>
Parameters
- $gateway_id : int
-
The ID of the gateway to fetch currencies for
Return values
array<string|int, mixed> —An array of stdClass objects representing the currencies accepted for this gateway
getInstalled()
Fetches all gateways installed in the system
public
getInstalled() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of stdClass objects, each representing an installed gateway record
getInstalledMerchant()
Fetches a single installed merchant gateway including meta data and currency association. Fetches based on $company_id and optionally by specifying a specific gateway ID.
public
getInstalledMerchant(int $company_id[, int $currency = null ][, int $gateway_id = null ][, string $gateway_name = null ][, int $client_id = null ][, int $client_group_id = null ]) : mixed
Parameters
- $company_id : int
-
The ID of the company in use
- $currency : int = null
-
The ISO 4217 currency code to process
- $gateway_id : int = null
-
The gateway ID to verify is installed and active for the given currency
- $gateway_name : string = null
-
The installed gateway's file name excluding any extension
- $client_id : int = null
-
The ID of the client to fetch only the gateways available for this client
- $client_group_id : int = null
-
The ID of the client group to fetch only the gateways available for this client group
Return values
mixed —A stdClass object representing the installed gateway, false if no such gateway exists or is not installed
getInstalledNonmerchant()
Fetches the requested installed nonmerchant gateway including meta data and currency association. Fetches based on company_id and gateway name.
public
getInstalledNonmerchant(int $company_id[, string $gateway_name = null ][, int $gateway_id = null ][, int $currency = null ][, int $client_id = null ][, int $client_group_id = null ]) : mixed
Parameters
- $company_id : int
-
The ID of the company in use
- $gateway_name : string = null
-
The installed gateway's file name excluding any extension
- $gateway_id : int = null
-
The gateway ID to verify is installed and active for the given currency
- $currency : int = null
-
The ISO 4217 currency code to process
- $client_id : int = null
-
The ID of the client to fetch only the gateway available for this client
- $client_group_id : int = null
-
The ID of the client group to fetch only the gateway available for this client group
Return values
mixed —A stdClass object representing the installed gateway, false if no such gateway exists or is not installed
isInstalled()
Checks whether the given gateway is installed for the specificed company
public
isInstalled(string $class, string $type[, string $company_id = null ]) : bool
Parameters
- $class : string
-
The gateway class (in file_case)
- $type : string
-
The type of gateway (merchant, nonmerchant)
- $company_id : string = null
-
The ID of the company to fetch for
Return values
bool —True if the gateway is installed, false otherwise
upgrade()
Runs the gateway's upgrade method to upgrade the gateway to match that of the gateway's file version.
public
upgrade(int $gateway_id) : mixed
Sets errors in GatewayManager::errors() if any errors are set by the gateway's upgrade method.
Parameters
- $gateway_id : int
-
The ID of the gateway to upgrade
validateCurrencyNotDefault()
Validates that currencies being removed from a merchant gateway are not set as default
public
validateCurrencyNotDefault(array<string|int, mixed> $currencies, int $gateway_id) : bool
Parameters
- $currencies : array<string|int, mixed>
-
The currencies being set for the gateway
- $gateway_id : int
-
The ID of the gateway being edited
Return values
bool —True if validation passes, false otherwise
verifyCurrency()
Verifies whether or not the given currency is already in use by a merchant gateway for this company
public
verifyCurrency(string $currency, int $company_id[, int $gateway_id = null ]) : bool
since v5.13.0 - Now multiple merchant gateways can use the same currency at the same time
Parameters
- $currency : string
-
The ISO 4217 currency code
- $company_id : int
-
The company ID
- $gateway_id : int = null
-
The gateway ID to exclude from this verification check (optional)
Return values
bool —True if the currency is in use by a gateway, false otherwise
getCurrencyRules()
Fetches the rules for adding/editing currencies for a gateway
private
getCurrencyRules(object $gw[, int $gateway_id = null ]) : array<string|int, mixed>
Parameters
- $gw : object
-
The gateway object
- $gateway_id : int = null
-
The ID of the gateway being edited (optional)
Return values
array<string|int, mixed> —The currency rules
getGatewayInfo()
Fetch information about the given gateway object
private
getGatewayInfo(object $gateway, string $type, int $company_id) : mixed
Parameters
- $gateway : object
-
The gateway object to fetch info on
- $type : string
-
The type of gateway ('merchant', 'nonmerchant')
- $company_id : int
-
The ID of the company to fetch gateway info for
getMeta()
Fetches all meta data associated with the given gateway
private
getMeta(int $gateway_id) : array<string|int, mixed>
Parameters
- $gateway_id : int
-
The ID of the gateway to fetch meta info for
Return values
array<string|int, mixed> —An array of stdClass objects representing meta data
loadGateway()
Instantiates the given gateway and returns its instance
private
loadGateway(string $class, string $type) : An
Parameters
- $class : string
-
The name of the class in file_case to load
- $type : string
-
The type of gateway to load ("merchant" or "nonmerchant")
Return values
An —instance of the gateway specified
setCurrencies()
Sets accepted currencies for the given gateway
private
setCurrencies(int $gateway_id, array<string|int, mixed> $currencies) : mixed
Parameters
- $gateway_id : int
-
The ID of the gateway to set currencies for
- $currencies : array<string|int, mixed>
-
A numerically indexed array of accepted currencies for this gateway
setDefaultCurrencies()
Sets the gateway as default for currencies that don't have a default assigned
private
setDefaultCurrencies(stdClass $gateway, array<string|int, mixed> $currencies) : mixed
Parameters
- $gateway : stdClass
-
The gateway object containing id and company_id
- $currencies : array<string|int, mixed>
-
The currencies supported by the gateway
setGatewayFields()
Sets additional info on the given gateway object
private
setGatewayFields(stdClass $gateway, int $company_id) : stdClass
Parameters
- $gateway : stdClass
-
An object representing the gateway from the database
- $company_id : int
-
The ID of the company to fetch info from
Return values
stdClass —The updated gateway object
setGatewayInfo()
Sets additional info on the given gateway object
private
setGatewayInfo(stdClass $gateway, int $company_id) : stdClass
Parameters
- $gateway : stdClass
-
An object representing the gateway from the database
- $company_id : int
-
The ID of the company to fetch info from
Return values
stdClass —The updated gateway object
setMeta()
Sets meta data for the given gateway, overwriting all existing meta data
private
setMeta(int $gateway_id, array<string|int, mixed> $meta) : mixed
Parameters
- $gateway_id : int
-
The ID of the gateway to store meta info for
- $meta : array<string|int, mixed>
-
A numerically indexed array of meta data containing:
- key The key for this meta field
- value The value for this key
- encrypted Whether or not this field should be encrypted (default 0, not encrypted)
setVersion()
Updates all installed gateways with the version given
private
setVersion(string $class, string $version) : mixed
Parameters
- $class : string
-
The class name of the gateway to update
- $version : string
-
The version number to set for each gateway instance