Skip to main content

Create a product group

Overview

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

  • Send null for product group Code. Avangate ignores any values you send for Code and generates identifiers itself. 
  • Use unique product group names. 
  • Send true or null for the Enabled property.
  • Avangate throws an exception if you send a blank product group.
  • If you send only the name of the product group Avangate 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. Avangate throws an exception if the values are incorrect.  The sessionID expires in 10 minutes.

Name

Required (string)

 

The name of the product group.  

Response

bool(true)

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);
 
$ProductGroup = new stdClass();
$ProductGroup->Name = 'New Product Group from API';
$ProductGroup->Code = null;//Send null for the Code. Avangate 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';
$ProductGroup->Enabled = true;
 
 
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addProductGroup',
'params' => array($sessionID, $ProductGroup)
);
 
var_dump (callRPC($jsonRpcRequest, $host));
 
 ?>

Interactive Voice Response system

Overview

The Interactive Voice Response system is geared towards helping your customers better manage their subscriptions.

Through the Interactive Voice Response system subscribers can:

  1. Check the auto-renewal and recurring billing status of their subscriptions. To do this, they need to provide the last four digits of the card number used during the acquisition process.
  2. Request that 2Checkout re-deliver the license codes to the end-user. 2Checkout sends the license codes to the email address associated with the subscription.

Benefits

Through the Interactive Voice Response system, you empower your customers to take more control of their subscriptions through easy to use self-service capabilities that they can access directly from their mobile phone, significantly shortening the time needed to resolve requests such as the ones mentioned above.

Retrieve price option groups

Overview

Use the searchPriceOptionGroups to extract information on the price option groups you configured. 

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.

PriceOptionGroupSearch

Optional (object)

 

Details below.

 

PriceOptionGroupSearch

Object

Name

Optional (string)

 

The name of the pricing options groups configured in the Avangate system.

Can be NULL.

Types

Optional (array)

 

Possible values:

· RADIO

· CHECKBOX

· INTERVAL

· COMBO

Can be NULL.

Limit

Optional (int)

 

Number of results displayed per page. Default maximum value is 10.

Can be NULL.

Page

Optional (int)

 

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

Can be NULL.

 

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 cross-sell campaigns

Overview

Use the searchCrossSellCampaigns method to extract information about the cross-sell campaigns you configured.

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.

Request

<?php

require ('PATH_TO_AUTH');

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'searchCrossSellCampaigns';
$jsonRpcRequest->params = array($sessionID);
$jsonRpcRequest->id = $i++;

var_dump(" \n Cross-sell campaigns: \n", callRPC($jsonRpcRequest, $host));
?>

Response

Parameters Type/Description

CrossSellCampaign

Object

Create percentage discount

Overview

Use setPromotionDiscount via SOAP API 4.0 to set a percentage-based promotion discount.

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 set the discount for.

promotionDiscount

Required(Object)

 

Type

Required (String)

 

 

Discount type:

  • PERCENT, use in combination with Value
  • FIXED, use in combination with Values and DefaultCurrency

 

Value / Values

Required (Int / Array of objects)

 

 

  • Value = Int, determines the discount percentage from 0 to 100
  • Values = Array of Value objects

 

 

Value

Required (Object)

 

 

 

Currency

Required (String)

 

 

 

 

Discount currency ISO code (ISO 4217).

 

 

 

Amount

Required (Int)

 

 

 

 

Discount amount in corresponding currency.

 

DefaultCurrency

Required (String)

 

 

Default discount currency ISO code (ISO 4217).

Response

Parameter Type/Description
promotionDiscount Object

Request

<?php 

class Client
{
    protected static $merchantCode;
    protected static $loginDate;
    protected static $hash;
    protected static $baseUrl;
    protected static $callCount = 0;
    protected static $sessionId = '';

    protected static $client;

    public static function setCredentials($code, $key)
    {
        static::$merchantCode = $code;
        static::$loginDate = gmdate('Y-m-d H:i:s');
        static::$hash = hash_hmac('md5', strlen($code) . $code . strlen(static::$loginDate) . static::$loginDate, $key);
        static::$sessionId = static::login();
    }

    public static function setBaseUrl($url)
    {
        static::$baseUrl = $url;
    }

    public static function login()
    {
        $client = static::getClient();
        return $client->login(static::$merchantCode, static::$loginDate, static::$hash);
    }

    public static function __callStatic($name, $arguments = array())
    {
        $client = static::getClient();

        array_unshift($arguments, static::$sessionId);
        $response = call_user_func_array(array($client, $name), $arguments);

        return $response;
    }

    protected static function getClient()
    {
        $opts = array(
            'http'=> ['user_agent' => 'PHPSoapClient'],
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false,
            ],
        );

        if (null === static::$client) {
            static::$client = new \SoapClient(static::$baseUrl . '?wsdl', [
                'location' => static::$baseUrl,
                'cache_wsdl' => WSDL_CACHE_NONE,
                'stream_context' => stream_context_create($opts),
            ]);
        }

        return static::$client;
    }
}

Client::setBaseUrl('https://api.avangate.com/soap/3.1/');
Client::setCredentials('YOUR_MERCHANT_CODE', 'YOUR_SECRET_KEY');
Client::login();

// create discount object
$discountObj = new stdClass;
$discountObj->Type = 'PERCENT';
$discountObj->Value = 30;

$promotionCode = 'YOUR_PROMO_CODE'; // code of the promotion that you want to update
$response = Client::setPromotionDiscount($promotionCode,$discountObj); // Set the promotion discount to the existing promotion
var_dump($response);

 

How to configure churn prevention campaigns

Overview

Configure churn prevention campaigns for your shoppers and offer them discounts for keeping their subscription auto-renewals active. 2Checkout offers an easy way to configure churn prevention campaigns so that you can:

  • Solidify your recurring revenue by offering discounts to customers who want to cancel recurring billing, incentivizing them to keep auto-renewal enabled for their subscriptions.
  • Engage and collect feedback from your customers to optimize your products, marketing campaigns, and business operations.

Set up a new churn prevention campaign

  1. In your Merchant Control Panel, navigate to Dashboard → Marketing tools → Retention tools →  Churn prevention and click on Add campaign.

    add a churn prevention campaign_1.png

  2. Fill in the details of the campaign: name and running interval. You can also choose whether or not to apply this campaign to subscriptions with custom price by checking or unchecking the Apply for subscriptions that are using product catalog pricing only option.

     

    add a churn prevention campaign_2.png

  3. Select the campaign settings that will be displayed to the shopper:

    • Create a message to display to your shoppers when they try to stop the subscription auto-renewal for products that you've selected in the campaign. The default message is mandatory but can be customized from the Edit campaign message section, as shown below. You can customize the default message for each shopper language to make it as personalized as you wish.

    add a churn prevention campaign_default message.png

    add a churn prevention campaign_default message_1.png

    • You can also request shoppers to give you a cancelation reason (optional).

    add a churn prevention campaign_request cancelation reason.png

    • Allow your shoppers to pause a subscription when they try to stop auto-renewal for products that you've selected in the campaign.

    add a churn prevention campaign_allow pause.png

    • Provide a discount incentive (this step is optional, but recommended) for your customers to keep auto-renewal enabled for their subscriptions and customize the discount message that you want shoppers to see during their cancelation attempts. This message is only displayed if you have set a campaign discount.

    add a churn prevention campaign_add discount.png

    add a churn prevention campaign_customize discount message.png

  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. You can add products to a campaign after it starts running.

    add a churn prevention campaign_add products.png

  5. Click on the Save campaign button at the bottom of the page.
  6. The campaign is now created and displayed as Ready. Click Start campaign to start it.

    add a churn prevention campaign_start campaign.png

    You can see the status of your campaign in the Retention tools → Churn prevention page. A churn prevention campaign can have the following statuses:

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

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

You can only edit  Ready and  Scheduled campaigns. You cannot edit campaigns that reached the  Running status.

What shoppers see in their 2Checkout myAccount platform

Once you've started the campaign, your shoppers are notified in myAccount whenever they try to stop the subscription auto-renewal for the products that you've selected in the campaign.

  1. The first pop-up displays either the default message (in the screenshot below) or the message that you customized before.

  2. The next pop-up asks for the cancelation reason (if you've checked the Request cancelation reason box) while setting up the campaign. Cancelation reasons are listed in the image below and they cannot be customized. After selecting the cancelation reason shoppers can provide additional comments/feedback in the Comment text box. 

    cancelation reason

  3. The next pop-up asks the shopper to select the date until they want to pause the subscription and the reason for pausing the subscription. Note that a subscription cannot be paused for a period longer than 3 years.

    image.png

  4. The last pop-up shows the discount that you offered your shoppers for keeping the auto-renewal. You can customize this message by changing the discount message while configuring the campaign.

How to search for existing churn prevention campaigns

Use the churn prevention search filters to find specific campaigns that you have previously set. You can search for 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 edit Ready and Scheduled campaigns, and view details of Finished campaigns.

How to run churn prevention campaign reports

You can find the Cancelation statistics reports in the Main reports section of the Reports center menu.

  1. Open the Reports center menu and click Main reports.
  2. Click the Churn prevention report, under Marketing reports to access the reports page. 
    churn prevention report.JPG
  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 churn prevention campaigns, filtered by the Orders value column, in descending order. The rest of the campaigns are aggregated under the Others 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.

Additionally, you can download a CSV report of the feedback collected from your customers during the cancelation prevention campaigns in the selected time interval by clicking Download feedback.

Retrieve subscriptions

Overview

Extract information on your account’s subscriptions. Subscriptions can be retrieved starting with 5 minutes after their orders are generated in the 2Checkout system.

Use the searchSubscriptions method to retrieve details about your account’s subscriptions, based on a set of filters. 

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.

SearchBy

Optional (Object)

  Contains any combination of the available additional search filters.

 

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 2CheckoutCustomerReference 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.

2CheckoutCustomerReference

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 2Checkout 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 – 2Checkout 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 2Checkout 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 2Checkout 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 2Checkout 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 2Checkout 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 2Checkout 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 2Checkout API time zone is GMT+02:00. Can be NULL.

NotificationAfter

Optional (string)

 

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

NotificationBefore

Optional (string)

 

YYYY-MM-DD. Search subscriptions for which the 2Checkout system sent out notifications before a specific date Note: The default 2Checkout 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
$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;
}
$SubscriptionSearch = new stdClass();
$SubscriptionSearch->CustomerEmail  = 'customer@email.com';
$SubscriptionSearch->DeliveredCode = null;
$SubscriptionSearch->2CheckoutCustomerReference = 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;
try {
    $accountSubscriptions = $client->searchSubscriptions($sessionID, $SubscriptionSearch);
}
catch (SoapFault $e) {
    echo "accountSubscriptions: " . $e->getMessage();
    exit;
}
var_dump("accountSubscriptions", $accountSubscriptions);

 

Place an order with iDEAL

Overview

Use the placeOrder method to create orders and collect payments from iDEAL.

Requirements

Only shoppers in the Netherlands can select iDEAL as a payment option and choose their bank. You're required to include the following text when using Avangate API and to make it visible for your customers in the ordering interface.

Order processed by Avangate, authorized reseller and merchant of the products and services offered within this store. 

Supported currencies

  • EUR

Workflow

  1. Use the getIdealIssuerBanks method for retrieving information on the Avangate list of banks that support iDEAL payments. More details about this method here.
  2. Shoppers select iDEAL as payment option in the interface you provide them, and select their bank from the list.
  3. Create the order object. Use IDEAL as the type of the PaymentDetails object, and include ReturnURL and CancelURL. The BankCode parameter should be added based on the bank selected by the customer, from the array obtained after calling method getIdealIssuerBanks.
  4. Use the placeOrder method to send the data to Avangate.
  5. Once you place the order, Avangate logs it into the system. At this point in time, the status of the order is PENDING.
  6. Avangate returns an Order object as the output of the placeOrder method. 
  7. Use the PaymentMethod object to create a redirect URL for the shoppers, concatenating the values of the Href and avng8apitoken parameters. Here's an example of the redirect URL:
    https://api.avangate.com/4.0/scripts/ideal/authorize/?avng8apitoken=f56373d92ed6b153
    
  8. Customers are directed to the iDEAL payment page, where they have to confirm their payment details before finishing the ordering process.
  9. Shoppers are redirected to the RedirectURL from the Order information object. In case the payment fails, shoppers are redirected to the CancelURL. 

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.

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

To place an order with iDEAL, use IDEAL as the type of the PaymentDetails object and provide the following parameters as part of the PaymentMethod object:

  • ReturnURL - URL to which customers are redirected after a successful payment.
  • CancelURL - URL to which customers are redirected after a failed payment attempt.
  • BankCode - information retrieved based on the bank selected by the customer, from the array obtained after calling getIdealIssuerBanks method.

See code sample for more details. 

    Response

    Order information

    Object

    Request

    
    <?php
    
    // authentication script: https://knowledgecenter.avangate.com/Integration/JSON-RPC_API/API_4.0/00Authentication
    
    require ('PATH_TO_AUTH');
    
    $Order = new stdClass();
    $Order->RefNo = NULL;
    $Order->Currency = 'eur';
    $Order->Country = 'nl';
    $Order->Language = 'en';
    $Order->CustomerIP = '91.220.121.21';
    $Order->ExternalReference = NULL;
    $Order->Source = NULL;
    $Order->AffiliateId = NULL;
    $Order->CustomerReference = NULL;
    $Order->Items = array();
    $Order->Items[0] = new stdClass();
    $Order->Items[0]->Code = 'my_subscription_1';
    $Order->Items[0]->Quantity = 1;
    $Order->Items[0]->PriceOptions = NULL;
    $Order->Items[0]->SKU = NULL;
    $Order->Items[0]->Price = NULL;
    $Order->Items[0]->CrossSell = NULL;
    $Order->Items[0]->Trial = false;
    $Order->Items[0]->AdditionalFields = NULL;
    $Order->BillingDetails = new stdClass();
    $Order->BillingDetails->FirstName = 'FirstName';
    $Order->BillingDetails->LastName = 'LastName';
    $Order->BillingDetails->CountryCode = 'NL';
    $Order->BillingDetails->State = 'State Example';
    $Order->BillingDetails->City = 'City Example';
    $Order->BillingDetails->Address1 = 'Address example';
    $Order->BillingDetails->Address2 = NULL;
    $Order->BillingDetails->Zip = '12345';
    $Order->BillingDetails->Email = 'email@address.com';
    $Order->BillingDetails->Phone = NULL;
    $Order->BillingDetails->Company = NULL;
    $Order->PaymentDetails = new stdClass ();
    $Order->PaymentDetails->Type = 'IDEAL';
    $Order->PaymentDetails->Currency = 'eur';
    $Order->PaymentDetails->PaymentMethod = new stdClass ();
    $Order->PaymentDetails->CustomerIP = '91.220.121.21';
    $Order->PaymentDetails->PaymentMethod->ReturnURL = 'YOUR_RETURN_URL';
    $Order->PaymentDetails->PaymentMethod->CancelURL= 'YOUR_CANCEL_URL';
    $Order->PaymentDetails->PaymentMethod->BankCode='BANK_CODE'; // value retrieved based on the bank selected by the customer, from the array obtained after calling method getIdealIssuerBanks.
    
    $jsonRpcRequest = new stdClass();
    $jsonRpcRequest->jsonrpc = '2.0';
    $jsonRpcRequest->method = 'placeOrder';
    $jsonRpcRequest->params = array($sessionID, $Order);
    $jsonRpcRequest->id = $i++;
     
    $output = callRPC($jsonRpcRequest, $host);
    
    $idealredirect = $output->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$output->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;
    
    header('Location:' . $idealredirect);
    

    Disable a subscription

    Overview

    Use the cancelSubscription method to disable an active subscription. 2Checkout 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. 2Checkout 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
    $host   = "https://api.2checkout.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;
    }
    $subscriptionReference = 'F27CFE06ED';
    try {
        $disableSubscription = $client->cancelSubscription($sessionID, $subscriptionReference);
    }
    catch (SoapFault $e) {
        echo "disableSubscription: " . $e->getMessage();
        exit;
    }
    var_dump("disableSubscription", $disableSubscription);
    
    

     

    Enable a subscription

    Overview

    Use the enableSubscription method to enable 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.

    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 = '0742B179DD';
    
    $jsonRpcRequest = array (
    'method' => 'enableSubscription',
    'params' => array($sessionID, $SubscriptionReferenceTest),
    'id' => $i++,
    'jsonrpc' => '2.0');
    
    var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
    

    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