Authentication
Last updated
Was this helpful?
Was this helpful?
<?php
$host = "https://api.avangate.com/channel-manager";
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the Control Panel: https://secure.2checkout.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the Control Panel: https://secure.2checkout.com/cpanel/account_settings.php
$algo = "sha256";
$now = date('Y-m-d H:i:s'); //date_default_timezone_set('UTC')
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash = hash_hmac($algo, $string, $key);
try {
$client = new SoapClient($host . "/2.1/soap/?wsdl", [\
'location' => $host . "/2.1/soap/",\
"stream_context" => stream_context_create([\
'ssl' => [\
'verify_peer' => false,\
'verify_peer_name' => false\
]\
])\
]);
$sessionID = $client->login($merchantCode, $now, $hash, $algo);
echo("Token: {$sessionID}" . PHP_EOL);
} catch (SoapFault $e) {
echo("Error: {$e->getMessage()}" . PHP_EOL);
}
?>