One click (1-click) subscription upgrade
Overview
Avangate supports 1-click manual subscription upgrades for returning customers who paid for their previous orders with Credit/Debit cards.
In this scenario, you can facilitate subscription upgrades for subscribers by enabling them to use card on file information to pay for the upgrade.
How does this work?
- Identify returning customers.
- Identify valid upgrade options and costs.
- Create a tokenized manual subscription upgrade link and serve it to the returning customer.
- Customers using the link land a hosted shopping cart, chose one of their credit cards they previously used for purchases from your account/store and place the order.
What do shoppers see in the cart?
Availability
Please contact Avangate to start using one click (1-click) subscription upgrades.
Requirements
- Configure the upgrade product / subscription plan in your Control Panel.
- Email address must match that from the initial order. If shoppers change the email they need to re-enter the payment details.
Flow comparison
|
|
Detailed 1-click subscription upgrade flow
Identify returning customers
You particularly need either the Avangate customer reference or the external customer reference you control.
Use customer information
getCustomerSubscriptions
|
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
searchSubscriptions
|
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).
|
Validate upgrade options and costs
getProductUpgradeOptions
getProductUpgradeOptionsPrice |
Retrieve the possible upgrade options for a subscription.
Retrieve information about the costs a customer incurs when upgrading a specific subscription |
Create the manual upgrade link
To build custom upgrade links you need the following two elements:
1. The main upgrade path:
https://secure.avangate.com/order/upgrade.php? or https://YourStore.com/order/upgrade.php? if you use a custom domain with Avangate
2. The unique subscription identifier from the Avangate system: LICENSE=1234567.
The simplest upgrade link you can build is
https://secure.avangate.com/order/upgrade.php?LICENSE=1234567
Attach the payment token to the manual Upgrade 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
function callRPC($Request, $hostUrl, $Debug = true) {
$curl = curl_init($hostUrl);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSLVERSION, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$RequestString = json_encode($Request);
curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
if ($Debug) {
$RequestString;
}
$ResponseString = curl_exec($curl);
if ($Debug) {
$ResponseString;
}
if (!empty($ResponseString)) {
$Response = json_decode($ResponseString);
if (isset($Response->result)) {
return $Response->result;
}
if (!is_null($Response->error)) {
var_dump($Request->method, $Response->error);
}
} else {
return null;
}
}
$host = 'https://api.avangate.com/rpc/3.0/';
$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
$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);
$i = 1; // counter for API calls
// call login
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;
$sessionID = callRPC($jsonRpcRequest, $host);
$SubscriptionSearch = new stdClass();
$SubscriptionSearch->CustomerEmail = null;
$SubscriptionSearch->DeliveredCode = '___TEST___CODE____123';
$SubscriptionSearch->AvangateCustomerReference = '449686020';
$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;
$jsonRpcRequest = array (
'method' => 'searchSubscriptions',
'params' => array($sessionID, $SubscriptionSearch),
'id' => $i++,
'jsonrpc' => '2.0');
$allsubscriptions = callRPC((Object)$jsonRpcRequest, $host, true);
$subscriptionReference = $allsubscriptions[0]->SubscriptionReference;
//retrieve all the upgrade options for a subscription
$jsonRpcRequest = array (
'method' => 'getProductUpgradeOptions',
'params' => array($sessionID, $subscriptionReference),
'id' => $i++,
'jsonrpc' => '2.0');
$optionsforUpgrade = callRPC((Object)$jsonRpcRequest, $host, true);
//retrieve information about the costs a customer incurs when upgrading a specific subscription
$productCode = $optionsforUpgrade[1]->ProductInfo->ProductCode;
$Currency = 'usd';
$Options = 'emailsupport'.';'.'oneuser1';
$jsonRpcRequest = array (
'method' => 'getProductUpgradeOptionsPrice',
'params' => array($sessionID, $subscriptionReference, $productCode, $Currency, $Options),
'id' => $i++,
'jsonrpc' => '2.0');
callRPC((Object)$jsonRpcRequest, $host, true);
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getProductByCode',
'params' => array($sessionID, $productCode)
);
$upgrtadebleProduct = callRPC((Object)$jsonRpcRequest, $host, true);
$upgrtadebleProductID = $upgrtadebleProduct->AvangateId;
$Options = 'emailsupport'.','.'oneuser1';//Replace the ; separator with , for use with query strings
//$upgradelink = "https://store.avancart.com/order/upgrade.php?LICENSE=".$subscriptionReference; //This is the simplest upgrade link you can build and use to generate a tokenized upgrade checkout URL
$upgradelink = "https://store.avancart.com/order/upgrade.php?LICENSE=".$subscriptionReference."&UPGRADEPROD=".$upgrtadebleProductID."&UPGRADEOPT=".$Options;
$IdCustomer = $allsubscriptions[0]->AvangateCustomerReference;
$CustomerType = 'AvangateCustomerReference';
$Url = $upgradelink;
$ValidityTime = 10;
$ValidationIp = null;
$jsonRpcRequest = array (
'method' => 'getSingleSignOnInCart',
'params' => array($sessionID, $IdCustomer, $CustomerType, $Url, $ValidityTime, $ValidationIp),
'id' => $i++,
'jsonrpc' => '2.0');
$upgradeSSOURL = callRPC((Object)$jsonRpcRequest, $host, true);
header("Location: $upgradeSSOURL");