Skip to main content

Extend a subscription

Overview

Extend the lifetime of a subscription in the Avangate system on-demand. Use the extendSubscription method to set a new expiration deadline for a subscription.

Parameters

Parameters

Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

SubscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

Days

Required (int)

 

Avangate prolongs the lifetime of a subscription using the number of days you send, adding the interval on top of the expiration date.

 

Hint: Use a negative number to reduce the lifetime of a subscription.

 

Cannot be NULL.

Response

Boolean

true or false depending on whether the changes were successful or not.

Request


<?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);
 
var_dump($sessionID);
$SubscriptionReferenceTest = '48F5AC7011';
$days = 5;

$jsonRpcRequest = array (
'method' => 'extendSubscription',
'params' => array($sessionID, $SubscriptionReferenceTest, $days),
'id' => $i++,
'jsonrpc' => '2.0');

var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

Create product group

Overview

Use the addProductGroup method to create product groups for your account:

  • Send null for product group Code. 2Checkout ignores any values you send for Code and generates identifiers itself. 
  • Use unique product group names. 
  • 2Checkout throws an exception if you send a blank product group.
  • If you send only the name of the product group 2Checkout creates the new product group entity. 

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.

ProductGroup

Required (object)

 

Use this object to create product groups. Send null for the Code. 2Checkout generates unique product group code identifiers. 

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$ProductGroup = new stdClass();
$ProductGroup->Name = 'New Product Group from API';
$ProductGroup->Code = null;//Send null for the Code. 2Checkout generates unique product group code identifiers.
$ProductGroup->TemplateName = 'Default Template';//'001 - Two Column Billing'; //the name of the cart template you want to associate with the product group
$ProductGroup->Description = 'This is a generic description';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addProductGroup',
'params' => array($sessionID, $ProductGroup)
);

var_dump (callRPC($jsonRpcRequest, $host));

?>

Update a subscription plan/product

Overview

Use the updateProduct method to update the configuration of a subscription plan/product you already configured for your account.

Parameters

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.

Product

Required (object)

 

Use this object to configure your subscription plans/products.

 

You can update/edit all parameters, except the following:

  • 2CheckoutID
  • ProductType

 

When updating a subscription plan/product, you also update its PricingConfigurations. However, you cannot modify:

  • The pricing configuration CODE.
  • The PricingSchema from DYNAMIC to FLAT or vice versa.
  • The intervals of an existing pricing configuration (MinQuantity and MaxQuantity). 

Response

bool(true)

Request

<?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 = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key          = "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;
}

$ProductCode = 'NewSubscriptionPlan_Code_12345';

try {
    $ProdbyCode = $client->getProductByCode($sessionID, $ProductCode);
}

catch (SoapFault $e) {
    echo "ProductInfo: " . $e->getMessage();
    exit;
}

var_dump("ProductInfo", $ProdbyCode);

$ProdbyCode->ProductName = 'NewSubscriptionPlan_Name_2.0';

try {
    $NewSubscriptionPlan = $client->updateProduct($sessionID, $ProdbyCode);
}

catch (SoapFault $e) {
    echo "UpdatedProductInfo: " . $e->getMessage();
    exit;
}

var_dump("UpdatedProductInfo", $NewSubscriptionPlan);

?>

 

Renew a subscription

Overview

Renew a subscription in the Avangate system on-demand, controlling the number of days, price and currency of the extension. Use the renewSubscription method to renew a subscription.

Parameters

Parameters

Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

SubscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

 

Avangate charges customers using the payment data attached to subscriptions. In the case of credit/debit cards, if customers update their payment information in myAccount or if you update these details on behalf of your subscribers, the Avangate system uses the latest card info provided to charge subscription renewals.

Days

Required (int)

 

The number of days the Avangate system extends the lifetime of the subscription.

Price

Required (double)

 

The price that Avangate charges the customer for the renewal. This is the Net price.

Currency

Required (string)

 

The currency associated to the renewal price - ISO 4217 code.

Response

Boolean

true or false depending on whether or not the operation succeeded.

Request


<?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);
 
var_dump($sessionID);
$subscriptionReference = '30E47F8699';
$Days = 4;
$Price = 50;
$Currency = 'eur';

$jsonRpcRequest = array (
'method' => 'renewSubscription',
'params' => array($sessionID, $subscriptionReference, $Days, $Price, $Currency),
'id' => $i++,
'jsonrpc' => '2.0');

var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

Update a subscription plan/product

Overview

Use the SOAP API 4 updateProduct method to update the configuration of a subscription plan/product you already configured for your account.

Parameters

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.

Product

Required (object)

 

Use this object to configure your subscription plans/products.

 

You can update/edit all parameters, except the following:

  • 2CheckoutID
  • ProductType

 

When updating a subscription plan/product, you also update its PricingConfigurations. However, you cannot modify:

  • The pricing configuration CODE.
  • The PricingSchema from DYNAMIC to FLAT or vice versa.
  • The intervals of an existing pricing configuration (MinQuantity and MaxQuantity). 

Response

bool(true)

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 = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key          = "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;
}

$ProductCode = 'NewSubscriptionPlan_Code_12345';

try {
    $ProdbyCode = $client->getProductByCode($sessionID, $ProductCode);
}

catch (SoapFault $e) {
    echo "ProductInfo: " . $e->getMessage();
    exit;
}

var_dump("ProductInfo", $ProdbyCode);

$ProdbyCode->ProductName = 'NewSubscriptionPlan_Name_2.0';

try {
    $NewSubscriptionPlan = $client->updateProduct($sessionID, $ProdbyCode);
}

catch (SoapFault $e) {
    echo "UpdatedProductInfo: " . $e->getMessage();
    exit;
}

var_dump("UpdatedProductInfo", $NewSubscriptionPlan);

?>

 

Granting user rights to the Subscriptions section

Overview

The Subscriptions section is available to all 2Checkout accounts. However, access is governed by user rights.

Follow the steps below to grant access to this section for users of your account.

How to grant user rights to the Subscriptions section

  1. Go to Account settings.
  2. Click on the Manage button in the User Management section. 

Subscriptions.png

3. Click on Users, scroll down to the user whose role you want to change and click on Edit.

subscriptions2.png

4. On the next page, go to Roles and select the role you want to assign to the account to grant it access.

subscriptions 3.png

5. Click Save.

How to configure auto-renewal enrollment campaigns

Overview

2Checkout offers an easy way to increase your revenue by giving your shoppers the option to enroll into auto-renewal campaigns in their myAccount.

Important: 2Checkout triggers auto-renewal campaigns only for products/subscriptions that have been paid with online payment methods. 

You can find the retention tools in the Marketing tools menu.

Here you can configure auto-renewal enrollment campaigns for your shoppers and offer them discounts for enrolling.

Setting up auto-renewal campaigns

  1. Click Add new campaign
  2. Fill in the details of the campaign: name, running interval and discount percentage. You can also set the discount to apply to all the following billing cycles or define a custom number of billing cycles to apply it to.
  3. Choose whether or not to apply this campaign to subscriptions with custom price by checking or un-checking the Apply for subscriptions that are using product catalog pricing only option.
  4. Select the products that you want the campaign to be applied to from the Available products list and add them to the Selected products list.
  5. Click Save campaign when you're done.

The campaign is now created and displayed as Ready. Click Start campaign to start it.

You can see the status of your campaign in the Retention tools page. An auto-renewal enrollment campaign can have the following statuses:

  1. Scheduled = a campaign that didn't reach Running status yet. You can edit or stop it from running in the future.
  2. Ready = a campaign that you have not started or one that you've stopped before its end date. You can edit it.
  3. Running = a campaign that is currently running. You can stop it or view its settings. You can add products to a running campaign.
  4. Finished = a campaign that passed its end date. You can view its settings but you cannot edit it.

If the campaign is Scheduled, you can click Edit if you want to modify its settings.

Important: You can only edit Ready campaigns and Scheduled ones. You cannot edit Running campaigns.

How to search for auto-renewal campaigns

Use the Auto-renewal enrollment search filters to find specific campaigns that you have previously set. You can search campaigns by:

  • Name
  • Status
  • Starting date
  • Product applied to

Important: Searching campaigns by the starting date returns all the campaigns that had started in the specified time interval.

Click Search when you're done configuring the filters.

You'll see the search results in the table at the bottom of the page along with possible actions that you can take on the campaigns. You can only edit Ready campaigns and Scheduled ones. You cannot edit Running campaigns. You can view the details of Running and Finished campaigns.

How to run auto-renewal campaign reports

You can find the Auto-renewal campaigns reports in the Main reports section of the Reports center menu.

  1. Open the Reports center menu and click Main reports
  2. Click the Enrollment statistics category to access the reports page.
  3. Use the filters in the Report settings section to define the campaigns that you want to include in the report. Click Build report when you're done.

The report shows the top 10 auto-renewal enrollment campaigns. The rest of the campaigns are aggregated in the Other entry. The data included in the report comes from campaigns that ran in the selected interval.

You can also export the full report as CSV by clicking Export as CSV. The exported report contains details about all of your campaigns.

How do shoppers enroll in auto-renewal campaigns?

Your shoppers can enroll in the auto-renewal campaigns by visiting 2Checkout myAccount and clicking the enrollment link.

Enable recurring billing

Overview

Use the enableRecurringBilling method to switch on the automatic renewal system for a subscription that's manually renewable. 

Parameters

Parameters Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

subscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

Response

Parameters Type/Description

Boolean

true or false depending on whether the changes were successful or not.

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';

$jsonRpcRequest = array (
'method' => 'enableRecurringBilling',
'params' => array($sessionID, $subscriptionReference),
'id' => $i++,
'jsonrpc' => '2.0');

var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

Retrieve SKU details

Overview

Use the getSkuDetails method to retrieve SKU details based on its ID.

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.
skuCode Required (string)
  Unique identifier of the SKU.

Response


{
"PricingConfigurationCode":"{PricingConfigurationCode}",
"ProductCode":"{ProductCode}",
"Currency":"{Currency}",
"PriceOptions":[{PriceOption1},{PriceOption2}],
"PurchaseType":"{PurchaseType}",
"FromQuantity":"{FromQuantity}",
"ToQuantity":"{ToQuantity}"
}

Request

<?php
require ('PATH_TO_AUTH');

$sku = 'YOUR_SKU_CODE';

try {
    $getSkuDetails = $client->getSkuDetails($sessionID, $sku);
} catch (SoapFault $e) {
    echo  $e->getMessage();
}
var_dump($getSkuDetails);

 

Retrieve an order

Overview

Use the getOrder method to retrieve details on a specific order using its unique, system-generated reference.

Parameters

Parameters

Type/Description

sessionID

Required (string)

 

Session identifier, the output of the Login method. Include sessionID into all your requests. A2Checkout throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

orderReference

Required (string)

 

Order reference number of an older order, which is already approved/paid.

Response

Order information

Object

Request


<?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.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;
}
$orderReference = '43403739';
try {
    $fullOrderDetails = $client->getOrder    ($sessionID, $orderReference);
}
catch (SoapFault $e) {
    echo "fullOrderDetails: " . $e->getMessage();
    exit;
}
var_dump("fullOrderDetails", $fullOrderDetails);
?>

 

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