Skip to main content

One click (1-click) subscription upgrade

One click (1-click) subscription upgrade

Last updated: 13-Oct-2021
Rate this article:

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).

  • Customer email
  • Delivered codes/activation keys
  • Avangate customer reference
  • External customer reference
  • Subscription status
  • Recurring billing status
  • Product code
  • Customer country
  • Purchased date
  • Expiration/Renewal deadline
  • Subscription type

 

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

getSingleSignOnInCart

 

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;
}
 
$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;
try {
    $allsubscriptions = $client->searchSubscriptions($sessionID, $SubscriptionSearch);
}
catch (SoapFault $e) {
    echo "allsubscriptions: " . $e->getMessage();
    exit;
}
$subscriptionReference = $allsubscriptions[0]->SubscriptionReference;
//retrieve all the upgrade options for a subscription
try {
    $optionsforUpgrade = $client->getProductUpgradeOptions($sessionID, $subscriptionReference);
}
catch (SoapFault $e) {
    echo "optionsforUpgrade: " . $e->getMessage();
    exit;
}
//retrieve information about the costs a customer incurs when upgrading a specific subscription
$productCode = $optionsforUpgrade[1]->ProductInfo->ProductCode;
$Currency = 'usd';
$Options = 'emailsupport'.';'.'oneuser1';
try {
    $upgradeOptions = $client->getProductUpgradeOptionsPrice($sessionID, $subscriptionReference, $productCode, $Currency, $Options);
}
catch (SoapFault $e) {
    echo "upgradeOptions: " . $e->getMessage();
    exit;
}
var_dump("upgradeOptions", $upgradeOptions);
try {
    $upgradadebleProduct = $client->getProductByCode($sessionID, $productCode);
}
catch (SoapFault $e) {
    echo "upgradadebleProduct: " . $e->getMessage();
    exit;
}
$upgradadebleProductID = $upgradadebleProduct->AvangateId;
$Options = 'emailsupport'.','.'oneuser1';//Replace the ; separator with , for use with query strings
 
//$upgradelink = "https://secure.avangate.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=".$upgradadebleProductID."&UPGRADEOPT=".$Options; //make sure to use your custom domain or secure.avangate.com otherwise
$IdCustomer = $allsubscriptions[0]->AvangateCustomerReference;
$CustomerType = 'AvangateCustomerReference';
$Url = $upgradelink;
$ValidityTime = 10;
$ValidationIp = null;
try {
    $upgradeSSOURL = $client->getSingleSignOnInCart($sessionID, $IdCustomer, $CustomerType, $Url, $ValidityTime, $ValidationIp);
}
catch (SoapFault $e) {
    echo "ssoLINK: " . $e->getMessage();
    exit;
}
header("Location: $upgradeSSOURL");


Rate this article:

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo