TestConnection
Purpose
Use this function to test plugin connection to the third-party service that provides exchange rates.
Mandatory
Yes
Input Parameters
An associative array that contains the plugin configuration data.
Parameter name | Description | Type |
---|---|---|
config
|
An associative array that contains configuration parameter data. | array[ParameterData] |
ParameterData
Parameter name | Available values | Description | Type |
---|---|---|---|
<name> |
<value>
|
Parameter value. |
|
Response
An associative array that contains the following keys:
Parameter name |
Description |
Type |
---|---|---|
STATUS
|
Status of method execution. Valid values for the TestConnection method are:
|
string
|
TEXT
|
(optional) Additional text description of the operation. | string
|
Example
Input data (request)
Copy
{
"config": {
"username": "example_user",
"password": "example_password" }
}
const TEST_CONNECTION_URL = 'https://some.exchange.rates.provider.com/api/status';
function Example_ValidateConfig($params)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_URL, TEST_CONNECTION_URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('username: '.$params['config']['username']));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('password: '.$params['config']['password']));
try {
curl_exec($curl);
} catch (Exception $e) {
return array(
STATUS => STATUS_DECLINED,
TEXT => array(
'vendor_message' => $e->getMessage()
)
);
}
return array(STATUS => STATUS_APPROVED);
}
const TEST_CONNECTION_URL = 'https://some.exchange.rates.provider.com/api/status';
function Example_ValidateConfig($params)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_URL, TEST_CONNECTION_URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('username: '.$params['config']['username']));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('password: '.$params['config']['password']));
try {
curl_exec($curl);
} catch (Exception $e) {
return array(
STATUS => STATUS_DECLINED,
TEXT => array(
'vendor_message' => $e->getMessage()
)
);
}
return array(STATUS => STATUS_APPROVED);
}