One click (1-click) subscription renewal
Overview
Avangate supports 1-click manual subscription renewals for returning customers who paid for their previous orders with Credit/Debit cards.
In this scenario, you can facilitate subscription renewals for subscribers who opted out of auto-renewal (recurring billing).
How does this work?
- Identify returning customers.
- Generate the manual renewal link.
- Create a tokenized manual subscription renewal link and serve it to the returning customer.
- Customers using the link land on a hosted shopping cart, then chose a credit card they previously used for purchases from your account/store and place the order.
Availability
Please contact Avangate to start using one-click (1-click) subscription renewals.
Requirements
- Make sure that the subscription is eligible:
- Status needs to be Active or Past Due
- Subscriptions cannot be evergreen
- The email address must match that of the initial order. If shoppers change the email they need to re-enter the payment details.
Flow comparison
|
|
Detailed 1-click subscription renewal flow
Identify returning customers
You particularly need either the Avangate customer reference or the external customer reference you control.
Use customer information
|
If customers log into your system and you’ve mapped unique identifiers into the Avangate platform you can easily extract their subscription information.
|
Use subscription information
|
You can also use subscription information to extract customer references, based on a set of filters. Validate the status of the subscription (needs to be Active or Past Due).
|
Create the manual renewal link
Retrieve information regarding subscription renewals based on Avangate Subscription References:
|
Attach the payment token to the manual renewal link
|
Avangate attaches a unique token to links, designed to identify the returning shoppers and support the automatic extraction of payment data and billing information from the Avangate system.
|
Example
<?php
$host = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/3.0/?wsdl", array(
'location' => $host . "/soap/3.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.avangate.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.avangate.com/cpanel/account_settings.php
$now = date('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;
}
var_dump($sessionID);
$SubscriptionSearch = new stdClass();
$SubscriptionSearch->CustomerEmail = null;
$SubscriptionSearch->DeliveredCode = '___TEST___CODE____123';
$SubscriptionSearch->AvangateCustomerReference = '123456789';
$SubscriptionSearch->ExternalCustomerReference = null;
$SubscriptionSearch->Aggregate = false;
$SubscriptionSearch->SubscriptionEnabled = null; //true false null
$SubscriptionSearch->RecurringEnabled = null; // true - autorenewal, false - manual renewal, null = both(default)
$SubscriptionSearch->ProductCodes = null; //array('Product_Code1', 'Product_Code2');
$SubscriptionSearch->CountryCodes = null;//array ('au')
$SubscriptionSearch->PurchasedAfter = null;
$SubscriptionSearch->PurchasedBefore = null;
$SubscriptionSearch->ExpireAfter = null;
$SubscriptionSearch->ExpireBefore = null;
$SubscriptionSearch->RenewedAfter = null;
$SubscriptionSearch->RenewedBefore = null;
$SubscriptionSearch->NotificationAfter = null;
$SubscriptionSearch->NotificationBefore = null;
$SubscriptionSearch->LifetimeSubscription = null;
$SubscriptionSearch->Type = 'regular'; //'trial', 'regular', 'regularfromtrial'
$SubscriptionSearch->TestSubscription = null; // true, false, null = both(default)
$SubscriptionSearch->Page = 1;
$SubscriptionSearch->Limit = 10;
try {
$allsubscriptions = $client->searchSubscriptions($sessionID, $SubscriptionSearch);
}
catch (SoapFault $e) {
echo "allsubscriptions: " . $e->getMessage();
exit;
}
var_dump("allsubscriptions", $allsubscriptions);
$subscriptionReference = $allsubscriptions[0]->SubscriptionReference;
try {
$manualrenewallink = $client->getRenewalDetails($sessionID, $subscriptionReference);
}
catch (SoapFault $e) {
echo "manualrenewallink: " . $e->getMessage();
exit;
}
var_dump("manualrenewallink", $manualrenewallink);
$IdCustomer = $allsubscriptions[0]->AvangateCustomerReference;
$CustomerType = 'AvangateCustomerReference';
$Url = $manualrenewallink->ManualRenewalLink;
$ValidityTime = 10;
$ValidationIp = null;
try {
$ssoLINK = $client->getSingleSignOnInCart($sessionID, $IdCustomer, $CustomerType, $Url, $ValidityTime, $ValidationIp);
}
catch (SoapFault $e) {
echo "ssoLINK: " . $e->getMessage();
exit;
}
var_dump("ssoLINK", $ssoLINK);