Skip to main content

Retrieve product info by code

Overview

Use getProductByCode to extract product information using the unique, product code that you control.  

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.

ProductCode

String

 

The product code that you control.

Response

Product

Object

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)) {
//        var_dump($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 = "YOURCODE12345";//your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "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 the login method for authentication
 
$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);
 
$ProductCode = "subscr1";
 
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getProductByCode',
'params' => array($sessionID, $ProductCode)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
 
?>

Retrieve assigned additional fields

Overview

Use the getAssignedAdditionalFields method to extract information about the additional fields assigned to a specific product.

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.

productCode

Required (string)

 

The editable code that you control at product-level, not the unique, system-generated product ID.

Response

Parameters Type/Description

AdditionalField

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$productCode = 'YOUR_PRODUCT_CODE';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getAssignedAdditionalFields',
'params' => array($sessionID, $productCode)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host));


Add/Import subscriptions without payment data

Overview

This article covers subscription import without credit/debit card information. Use the addSubscription method to import a subscription into the 2Checkout system.

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.

Subscription import

Required (Object)

 

Object designed to provide 2Checkout with all the information to create a subscription.

Response

Parameters Type/Description

SubscriptionReference

String

 

Unique, system-generated subscription identifier.

Request

<?php

require ('PATH_TO_AUTH');

$Product = new stdClass ();
$Product->ProductCode = 'my_subscription_1';
$Product->ProductId = 4639321;
$Product->ProductName = '2Checkout Subscription Imported';
$Product->ProductVersion = 1.0;
$Product->ProductQuantity = 3;
$Product->PriceOptionCodes = array();
$EndUser = new stdClass ();
$EndUser->Address1 = 'Address line 1';
$EndUser->Address2 = 'Address line 2';
$EndUser->City = 'LA';
$EndUser->Company = 'Company Name';
$EndUser->CountryCode = "US";
$EndUser->Email = 'customerAPI@2Checkout.com';
$EndUser->FirstName = 'Customer';
$EndUser->Language = 'en';
$EndUser->LastName = '2Checkout';
$EndUser->Phone = '1234567890';
$EndUser->State = 'California';
$EndUser->Fax = NULL;
$EndUser->Zip = '90210';
$Subscription = new stdClass();
$Subscription->ExternalSubscriptionReference = '12345678912ImportedSubscription';
$Subscription->SubscriptionCode= NULL;
$Subscription->StartDate = '2013-01-01';
$Subscription->ExpirationDate = '2017-12-30';
$Subscription->Product = $Product;
$Subscription->EndUser = $EndUser;
$Subscription->ExternalCustomerReference = '12354678ExtCustRef';


try {
    $importedSubscriptionNoPayData = $client->addSubscription($sessionID, $Subscription);
}
catch (SoapFault $e) {
    echo "importedSubscriptionNoPayData: " . $e->getMessage();
    exit;
}
var_dump("importedSubscriptionNoPayData", $importedSubscriptionNoPayData);

Subscription authorization of recurring charges

Overview

Use multiple renewal authorization (retry logic), along with additional customer retention tools from 2Checkout, to recover expired subscriptions for which the renewal process has failed. 2Checkout supports expanding the number of renewal authorization attempts for expired subscriptions beyond the default tries described above. The 2Checkout system enables the customization of post-expiration subscription renewal authorization attempts, fine-tuning them to increase your renewal rates.

Authorization retry intervals can be set in:

  • Hours - At least 20 hours after subscriptions expire. The minimum interval between two (2) consecutive authorization retries is 20 hours.
  • Days - Any number of days can be set, but 2Checkout makes retries only in the grace period of subscriptions.

Availability

All 2Checkout accounts. 

Multiple authorization attempts work for:

  • Subscription auto-renewals (including imported subscriptions)
  • Trial conversions

Requirements

This feature works only for subscriptions that have expired but are still in their grace period (status: Past Due). 2Checkout makes multiple renewal authorization attempts for expired subscriptions only if you set a grace period.

    Authorization scenarios

    Depending on the renewal interval set for subscriptions, the 2Checkout system will charge customers in accordance with the following two scenarios:

    1. Subscription billing cycle smaller or equal to six (6) months. The 2Checkout system attempts to charge customers according to their time zone at a maximum of three (3) hours prior to the expiration of the current subscription.
    2. Subscription billing cycle is larger than six (6) months. 2Checkout makes the first attempt to charge shoppers two (2) days prior to the expiration date. The system makes a subsequent attempt one day before the subscription expires.

      Workflow

      Let's assume that you're selling monthly subscription and that you set a 5-day global grace period for all subscriptions, and that 2Checkout has configured three additional renewal authorization attempts, 20 hours but also in the first and third day after the expiration deadline.

      Subscription A, purchased by Customer A on April 15, is set to renew on May 15.

      On May 15 the 2Checkout system attempts to automatically charge for the renewal per the auto-renewal configuration. The transaction fails due to a lack of funds.

      Subscription A is transitions to the manual renewal system, and 2Checkout contacts Customer A providing information on the failed transaction as well as the guidance necessary for the subscription to be renewed through a manual payment.

      20 hours after the subscription expired, a new authorization request is made. This is followed, by another automatic renewal authorization attempt the next day after Subscription A expired.

      The same happens on the third day, provided that the customer has not renewed the transaction manually by then. If Customer A's card now holds sufficient funds, the account is automatically charged and the subscription renewed.

        Payment methods for recurring billing

        The 2Checkout platform supports recurring billing for the following payment methods:

        • Credit/debit cards (Visa, Visa Electron, MasterCard, Maestro, American Express, JCB, Carte Bancaire, Dankort, Discover and local cards from Brazil and Turkey)
        • PayPal
        • DirectDebit 
        • iDeal
        • Sofort banking
        • eCheck/ACH
        • Neteller
        • Skrill

        Grace period

        The grace period provides an interval of time during which shoppers can purchase a subscription renewal, following the expiration deadline.

        Configuring a grace period for subscriptions does not influence the recurring billing process. After the grace period, if any, runs out for expired subscriptions, customers have to purchase a new subscription. 2Checkout calculates expiration deadlines (GMT+02:00) from the subscription generation date, taking into consideration the billing cycle you configured.

        FAQ

        Can multiple renewal authorization attempts be discontinued for a subscription?

        Yes, this happens automatically:

        • If customers renew their subscriptions through a manual payment - although the discontinuation is only valid for that specific billing cycle, and the multiple renewal authorization settings will continue to come into effect as subscriptions expire.
        • Or if the subscription expires.

        Remove sources

        Overview

        Use the deletePromotionSources method to define new sources for an existing promotion.

        Parameters

        Parameter Type/Description

        sessionID

        Required (string)

         

        Output of the Login method.

        promotionCode

        Required (string)

         

        The code corresponding to the promotion that you want to remove sources from.

        promotionSources

        Required (string array)

         

        Array of strings defining the promotion sources to be removed.

        Response

        Parameter Type/Description

        Status

        Boolean

         

        True or false

        Request

        <?php
        
        require ('PATH_TO_AUTH');
        
        // Promotion code corresponding to the promotion you want to remove sources from
        $promotionCode = '';
        
        // Sources array with the source values 
        $sources = ['source1', 'source2'];
        
        $jsonRpcRequest = array (
        'jsonrpc' => '2.0',
        'id' => $i++,
        'method' => 'deletePromotionSources',
        'params' => array($sessionID, $promotionCode, $sources)
        );
        var_dump (callRPC($jsonRpcRequest, $host));
        

        Retrieve a price option group

        Overview

        Use the getPriceOptionGroup method to extract information about a specific price option group that you configured.

        Parameters

        Parameters Type/Description

        ProductGroup

        Object

        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.

        GroupCode

        Required (string)

         

        The code that the Avangate system generated or that you set for the product pricing options group.

        Response

        PriceOptionGroup

        Array of objects

        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)) {
        //        var_dump($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 = "YOURCODE12345";//your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
        $key = "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 the login method for authentication
         
        $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);
         
        $GroupCode = 'USERS';
         
        $jsonRpcRequest = array (
        'jsonrpc' => '2.0',
        'id' => $i++,
        'method' => 'getPriceOptionGroup',
        'params' => array($sessionID, $GroupCode)
        );
         
        var_dump (callRPC((Object)$jsonRpcRequest, $host));

        Retrieve subscriptions

        Overview

        Extract information on your account’s subscriptions.

        Use the searchSubscriptions method to retrieve details about your account’s subscriptions, based on a set of filters. Subscriptions can be retrieved starting with 5 minutes after their orders are generated in the 2Checkout system.

        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.

        SearchBy

        Optional (Object)

         

        Unique, system-generated subscription identifier.

         

        SubscriptionSearchOptions parameters

        Type/Description

        CustomerEmail

        Optional (string)

         

        Customer email address. Can be NULL.

        Note: The CustomerEmail parameter must be paired always with another reference pointing to the correct customer, such as the AvangateCustomerReference parameter or the ExternalCustomerReference parameter. Otherwise, the search call will return partial hits on the customer email address.

        ExactMatchEmail Optional (Boolean)
         

        Force search by email to perform exact match; recommended to keep this option set to true in order to avoid matching similar email addresses from multiple customers.

        DeliveredCode

        Optional (string)

         

        Activation key/code. Can be NULL.

        AvangateCustomerReference

        Optional (int)

         

        System-generated customer reference. Can be NULL.

        ExternalCustomerReference

        Optional (string)

         

        External customer reference that you control. Can be NULL.

        Aggregate

        Optional (boolean)

         

        true - search will work across all your aggregated Avangate accounts.

        false - default value. You limit the search to the account whose details you used for authentication.

        Can be NULL.

        SubscriptionEnabled

        Optional (boolean)

         

        true for enabled subscriptions.

        false for disabled subscriptions.

        Can be NULL.

        RecurringEnabled

        Optional (StringArray)

         

        true – Avangate charges customers using recurring billing for subscriptions.

        false – customers need to make manual payments to renew their subscriptions.

        Can be NULL.

        ProductCodes

        Optional (StringArray)

         

        Product identifier that you control. Can be NULL.

        CountryCodes

        Optional (string)

         

        Country code (ISO 3166 two-letter code). Can be NULL.

        PurchasedAfter

        Optional (string)

         

        YYYY-MM-DD. Subscription search interval start. You can search for subscriptions purchased between the dates you set using PurchasedAfter and PurchasedBefore. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        PurchasedBefore

        Optional (string)

         

        YYYY-MM-DD. Subscription search interval end. You can search for subscriptions purchased between the dates you set using PurchasedAfter and PurchasedBefore. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        ExpireAfter

        Optional (string)

         

        YYYY-MM-DD. Search subscriptions set to expire after a specific date. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        ExpireBefore

        Optional (string)

         

        YYYY-MM-DD. Search subscriptions set to expire before a specific date. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        RenewedAfter

        Optional (string)

         

        YYYY-MM-DD. Search subscriptions renewed after a specific date. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        RenewedBefore

        Optional (string)

         

        YYYY-MM-DD. Search subscriptions renewed before a specific date. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        NotificationAfter

        Optional (string)

         

        YYYY-MM-DD. Search subscriptions for which the Avangate system sent out notifications after a specific date. Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        NotificationBefore

        Optional (string)

         

        YYYY-MM-DD. Search subscriptions for which the Avangate system sent out notifications before a specific date Note: The default Avangate API time zone is GMT+02:00. Can be NULL.

        Type

        Optional (string)

         

        trial - trial subscriptions.

        regular - all generated subscriptions that are not trials.

        regularfromtrial - subscriptions generated from a trial conversion.

        Can be NULL.

        TestSubscription

        Optional (boolean)

         

        true

        false, depending on whether you want to include test subscriptions in the search or not. Can be NULL.

        LifetimeSubscription

        Optional (boolean)

         

        true – evergreen subscriptions.

        false - subscriptions with a limited recurring billing cycle, typically no larger than 36 months.

        Can be NULL.

        Page

        Optional (int)

         

        A specific page of search results. Default value is 1.

        Can be NULL.

        Limit

        Optional (int)

         

        Number of results (subscriptions) displayed per page. Default value is 10.

        Can be NULL.

        Response

        Subscription

        Array of objects

        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);
        $SubscriptionSearch = new stdClass();
        $SubscriptionSearch->CustomerEmail  = 'example@email.com';
        $SubscriptionSearch->DeliveredCode = null;
        $SubscriptionSearch->AvangateCustomerReference = null;
        $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->LifetimeSubscription = null;
        $SubscriptionSearch->Type = 'regular'; //'trial', 'regular', 'regularfromtrial'
        $SubscriptionSearch->TestSubscription = null; // true, false, null = both(default) $SubscriptionSearch->Page = 1;$SubscriptionSearch->Limit = 25;
        $SubscriptionSearch->Page = 1;
        $SubscriptionSearch->Limit = 10;
        
        $jsonRpcRequest = array (
        'method' => 'searchSubscriptions',
        'params' => array($sessionID, $SubscriptionSearch),
        'id' => $i++,
        'jsonrpc' => '2.0');
        
        var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
        
        

        Retrieve product groups

        Overview

        Use the getProductGroups method to extract information about the product groups you created for your account.

        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.

         

        Response

        ProductGroup

        Array of objects

        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)) {
        //        var_dump($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 = "YOURCODE12345";//your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
        $key = "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 the login method for authentication
         
        $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);
         
        $jsonRpcRequest = array (
        'jsonrpc' => '2.0',
        'id' => $i++,
        'method' => 'getProductGroups',
        'params' => array($sessionID)
        );
        var_dump (callRPC((Object)$jsonRpcRequest, $host));
         
         
        ?>
        

        Disable a subscription

        Overview

        Use the cancelSubscription method to disable an active subscription. Avangate disabled the subscription immediately and no longer performs any recurring billing actions.

        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

        Boolean

        true or false depending on whether the call resulted in success 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);
        $subscriptionReference = '351D8F557E';
        
        $jsonRpcRequest = array (
        'method' => 'cancelSubscription',
        'params' => array($sessionID, $subscriptionReference),
        'id' => $i++,
        'jsonrpc' => '2.0');
        
        var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
        
        

        Retrieve a subscription

        Overview

        Extract information on a single subscription. Use the getSubscription method to retrieve details about a subscription. 

        Subscriptions can be retrieved starting with 5 minutes after their orders are generated in the 2Checkout system.

        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.

        SubscriptionReference

        Required (string)

         

        Unique, system-generated subscription identifier.

        Response

        Subscription

        Object

        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;
        }
        $subscriptionReference = 'F27CFE06ED';
        try {
            $subscriptionInfo = $client->getSubscription($sessionID, $subscriptionReference);
        }
        catch (SoapFault $e) {
            echo "subscriptionInfo: " . $e->getMessage();
            exit;
        }
        var_dump("subscriptionInfo", $subscriptionInfo);
        
        

         

        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