TestConnection
Purpose
Tests the gateway availability with the specified plug-in configuration.
Mandatory
No.
Input Parameters
An associative array that contains the following values:
Param name | Description | Type |
---|---|---|
config
|
The plug-in configuration values saved in the Billing database. | array |
environment
|
The Billing environment information ( |
Environment |
The example of input parameters is shown below as a JSON object:
{
"config": {
"auth_code": "421",
"format": "json",
"gateway_url": "https://plugin-gateway-url.com",
"test_mode": "1" },
"environment": {
"lang": "en",
"system_host": "bss.int.zone" }
}
Response
The associative array that contains the following keys:
Param name | Description | Type |
---|---|---|
STATUS
|
The status of the method execution. Valid values are:
|
string |
TEXT
|
(Optional) The array that contains the following parameters:
|
array |
Example
The TestConnection
implementation below tries to connect to the gateway_url
URL provided during the plug-in configuration. If there is no error (HTTP range < 400) calling HTTP GET
on that URL, it returns STATUS = APPROVED
to the Billing, which means that the configuration is correctly set. If it fails (for example, provided auth_code
is not correct, so the gateway would probably return HTTP 403 Unauthorized Error
in this case), it returns STATUS = DECLINED
and an error message is returned in the TEXT
field.
function Example_TestConnection($params){
$config = $params['config'];
if (!$config['test_mode']) {
$auth = $config['auth_code'];
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_URL, $config['gateway_url']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (isset($auth)) {
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Auth: '.$auth));
}
try {
curl_exec($curl);
} catch (Exception $e) {
return array(
STATUS => STATUS_DECLINED,
TEXT => array(
'vendor_message' => $e->getMessage()
)
);
}
return array(STATUS => STATUS_APPROVED);
}
If test connection to the payment gateway succeeds, Billing displays the "Test connection succeeded." message: