Single Sign On by customer reference
Overview
Use the getSingleSignOnByCustomer method to create Single Sign-On links into 2Checkout myAccount based on customer references (IDs). Use either the 2Checkout Customer Reference or the External Customer Reference to identify specific customers.
Parameters
Parameters |
Type/Description |
---|---|
sessionID |
Required (string) |
|
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. |
IdCustomer |
Required (string) |
|
Unique customer identifiers. Can be either the ExternalCustomerReference you control or the system-generated 2CheckoutCustomerReference. |
CustomerType |
Required (string) |
|
Possible values:
|
Page |
Optional (string) |
|
The specific myAccount page where you redirect the customer. Possible values: my_subscription - redirect shoppers to the subscription's page of myAccount based on the SubscriptionReference you provide. my_products - redirects shoppers to the myAccount page designed to list all products purchased from 2Checkout. https://store.YourCustomDomain.com/m...t/my_products/? user_data - redirects shoppers to the Personal Information page in myAccount https://store.YourCustomDomain.com/m...unt/user_data/? order_lookup - redirects shoppers to the Order Lookup area of myAccount: https://store.YourCustomDomain.com/m.../order_lookup/ faq - redirects shoppers to the Support page of myAccount https://secure. YourCustomDomain.com/support/ payment_methods – redirect shoppers to the Payment Methods area of myAccount: https://store.YourCustomDomain.com/m...yment_methods/ Do not include PAGE in the URL to redirect shoppers to myAccount homepage https://store.YourCustomDomain.com/myaccount/?
|
Request |
Optional (string) |
|
Needed for 'my_subscription' Request[]=code=123D40F123 redirects customers to the page for the subscription with the 123D40F123 SubscriptionReference value.
|
ValidityTime |
Optional (int) |
|
The time, in seconds, before the single sign-on URL expires. By default, the URL expires after 10 seconds. (optional) |
ValidationIp |
Optional (string) |
|
The IP address of the shopper, necessary for security purposes. Can be an empty string or a valid IP, or null. |
LanguageCode | Optional (string) |
ISO 639-1 two-letter code. |
Response
Parameter | Type/Description |
---|---|
Single sign-on URL |
String |
The string generated is the complete single sign-on URL pointing to 2Checkout myAccount, containing the unique URL. Shoppers using it log into their 2Checkout myAccount automatically. |
Request
<?php
$host = "https://api.2checkout.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
'location' => $host . "/soap/4.0/",
"stream_context" => stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
))
));
function hmac($key, $data)
{
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*", md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: 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 cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$now = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash = hmac($key, $string);
try {
$sessionID = $client->login($merchantCode, $now, $hash);
}
catch (SoapFault $e) {
echo "Authentication: " . $e->getMessage();
exit;
}
$IdCustomer = '352365983';
$CustomerType = '2CheckoutCustomerReference';
$Page = 'my_license';
$Request = null;
$ValidityTime = 50;
$ValidationIp = null;
try {
$ssoLINK = $client->getSingleSignOnByCustomer($sessionID, $IdCustomer, $CustomerType, $Page, $Request, $ValidityTime, $ValidationIp);
}
catch (SoapFault $e) {
echo "ssoLINK: " . $e->getMessage();
exit;
}
var_dump("ssoLINK", $ssoLINK);