Retrieve available countries
Last updated: 20-Apr-2021
Rate this article:
Overview
Use the getAvailableCountries method to get the list of available countries for the current merchant. If the language parameter is provided, all the returned countries will be translated into that language.
Request Parameters
Parameter Name | Type | Required/Optional | Description |
---|---|---|---|
sessionId | String | Required | Session identifier, the output of the Login method. Include sessionId into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionId expires in 10 minutes. |
language | String | Optional | The ISO language code (two-letter code). If the language parameter is empty, the default language will be English. |
Request Example
class Configuration
{
public const MERCHANT_CODE = '';
public const MERCHANT_KEY = '';
public const URL = 'http://api.2checkout.com/soap/6.0';
public const ACTION = 'getAvailableCountries';
public const ADDITIONAL_OPTIONS = null;
public const PAYLOAD = "nl";
}
class Client
{
public function call(
string $url = Configuration::URL,
$payload = Configuration::PAYLOAD,
string $action = Configuration::ACTION
) {
if (is_array($payload)) {
$payload = json_encode($payload);
}
$soapClient = $this->getClient($url);
$sessionId = $this->getSession($soapClient);
$args = array_filter([$sessionId, $payload]);
return $soapClient->$action(...$args);
}
public function getClient(string $url): SoapClient
{
return new SoapClient(
$url.'?wsdl',
[
'location' => $url,
'cache_wsdl' => WSDL_CACHE_NONE,
]
);
}
public function getSession(SoapClient $client)
{
$date = gmdate('Y-m-d H:i:s');
$merchantCode = Configuration::MERCHANT_CODE;
$key = Configuration::MERCHANT_KEY;
$string = strlen($merchantCode).$merchantCode.strlen($date).$date;
$hash = hash_hmac('md5', $string, $key);
$client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
return $client->login($merchantCode, $date, $hash);
}
}
try {
$client = new Client();
var_dump($client->call());
} catch (Exception $ex) {
var_dump($ex);
}
Response
Parameter Name | Type | Description |
---|---|---|
countries | Array | An array of country objects, mode of country code, and translated country name. |
Response Example
[
{
“Code”: “AE”,
“Label”: “Verenigde Arabische Emiraten”
},
{
“Code”: “AF”,
“Label”: “Afghanistan”
}
]
Rate this article: