Skip to main content

Subscription renewal notifications

Overview

Use the setRenewalNotificationStatus method to subscribe or unsubscribe shoppers from subscription renewal notifications.

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.

status

Required (boolean)

 

true – enable subscription renewal notifications.

false – disable subscription renewal notifications.

Response

Parameters Type/Description

Boolean

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

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';
$status = false;

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

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

Add order/product additional fields

Overview

Use the addAdditionalField method to create new additional fields 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.

AdditionalField

Object

 

Additional field object.

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++;

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

$AdditionalField                             = new stdClass();
$AdditionalField->Label                      = 'Do you agree with the new newsletter policy 2015?';
$AdditionalField->Type                       = 'LISTBOX';
$AdditionalField->Code                       = 'NewsletterPolicy1234576';
$AdditionalField->ApplyTo                    = 'ORDER';
$AdditionalField->Values                     = array();
$AdditionalField->Values[0]                  = 'YES';
$AdditionalField->Values[1]                  = 'NO';
$AdditionalField->ValidationRule             = null;
$AdditionalField->Translations               = array();
$AdditionalField->Translations[0]            = new stdClass();
$AdditionalField->Translations[0]->Label     = "Êtes-vous d'accord avec la politique de la newsletter?";
$AdditionalField->Translations[0]->Values    = array();
$AdditionalField->Translations[0]->Values[0] = 'Oui';
$AdditionalField->Translations[0]->Values[1] = 'Non';
$AdditionalField->Translations[0]->Language  = 'fr';
$AdditionalField->Translations[1]            = new stdClass();
$AdditionalField->Translations[1]->Label     = 'Haben Sie mit dem Newsletter Politik zu?';
$AdditionalField->Translations[1]->Values    = array();
$AdditionalField->Translations[1]->Values[0] = 'Ja';
$AdditionalField->Translations[1]->Values[1] = 'Nein';
$AdditionalField->Translations[1]->Language  = 'de';

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

?>

Retrieve subscription plan/product info

Overview

Use the searchProducts method to extract information about the subscription plan/products you configured 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.

SearchOptions

Object

Name

Optional (string)

 

Product name.

Can be NULL.

Types

Optional (StringArray)

 

Array of the values representing the type of products. Possible values:

  • REGULAR

  • BUNDLE

Leave empty to have all product types returned to the search.

Can be NULL. If NULL, Avangate returns both regular and bundle products.

Enabled

Optional (boolean)

 

True or false.

Can be NULL.

GroupName

Optional (string)

 

The name of the group that the product is associated with.

Can be NULL.

Limit

Optional (integer)

 

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

Can be NULL.

Page

Optional (integer)

 

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

Can be NULL.

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

$SearchOptions = new stdClass();
$SearchOptions->Name = 'Avangate Subscription'; //Product name
$SearchOptions->Types = array ('REGULAR', 'BUNDLE'); //product type (standalone), regular or bundle
$SearchOptions->Enabled = True;
//$SearchOptions->GroupName = '';
$SearchOptions->Limit = '10';
$SearchOptions->Page = '10';

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'searchProducts',
'params' => array($sessionID, $SearchOptions)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
?>

Assign a subscription to another customer

Overview

Use the setSubscriptionCustomer method. Avangate moves subscription under the customer for which you provide the Avangate customer reference or the External customer reference during the subscription update process.

json_diagram.png

Requirements

To move a subscription from a source customer to a target customer:

  • Use Avangate customer references or External customer references belonging to the target customer. Avangate re-assigns the subscription to the target customer. 
  • Customer references must be valid and associated to the target customer entity under which you move the subscription.
  • If you provide both the Avangate customer reference and External customer reference they need to belong to the same target customer 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.

AvangateCustomerReference

Required (int)

 

System-generated customer reference. Required unless you prefer to use ExternalCustomerReference.

ExternalCustomerReference

Optional (string)

 

External customer reference that you control. Optional when you use AvangateCustomerReference. If you include it, it needs to belong to the same customer as the AvangateCustomerReference.

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);
$subscriptionReference = '30E47F8699';
$customerReference = 260015052;

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

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

Use iDEAL

Overview

Place an order with catalog products defined in your Control Panel and collect the payment using iDEAL.

Requirements

One shoppers from Netherlands can purchase using iDEAL. The billing country and the order country code has to be NL.

Supported currencies

  • EUR

Workflow

  1. Use the getIdealIssuerBanks method for retrieving information on the 2Checkout 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 2Checkout.
  5. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING.
  6. 2Checkout 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.2checkout.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. 2Checkout 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

    Parameter Type/Description

    Order information

    Object

      Object containing order information.

    Request

    <?php
    
    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->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
    $Order->BillingDetails = new stdClass();
    $Order->BillingDetails->FirstName = 'Test Cosmin API';
    $Order->BillingDetails->LastName = 'Cosmin API';
    $Order->BillingDetails->CountryCode = 'NL';
    $Order->BillingDetails->State = 'California';
    $Order->BillingDetails->City = 'LA';
    $Order->BillingDetails->Address1 = 'Address example';
    $Order->BillingDetails->Address2 = NULL;
    $Order->BillingDetails->Zip = '90210';
    $Order->BillingDetails->Email = 'cosmin.deftu@2checkout.com';
    $Order->BillingDetails->Phone = NULL;
    $Order->BillingDetails->Company = NULL;
    $Order->DeliveryDetails = 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 = 'http://yourreturnurl.com';
    $Order->PaymentDetails->PaymentMethod->CancelURL= 'http://yourcancelurl.com';
    $Order->PaymentDetails->PaymentMethod->BankCode='RABONL2U+RAB'; // value retrieved based on the bank selected by the customer, from the array obtained after calling method getIdealIssuerBanks.
    
    
    $jsonRpcRequest = array (
    'method' => 'placeOrder',
    'params' => array($sessionID, $Order),
    'id' => $i++,
    'jsonrpc' => '2.0'
    );
    
    $output = callRPC($jsonRpcRequest, $host);
    
    $idealredirect = $output->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$output->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;
    
    header('Location:' . $idealredirect);
    
    

    Place order with custom subscription settings

    Overview

    Use the placeOrder method to create an order using custom subscription settings via JSON-RPC API 6.0.

    Request parameters

    Parameters Type Required/Optional Description
    sessionID String Required 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.
    Order Object Required

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

    Response

    Parameters Type Description
    Order information Object Object that includes all data necessary for an order, including billing, product/subscription plan, and payment details.

    Request sample

    <?php
    $Order = new \stdClass();
    $Order->Currency = 'usd';
    $Order->Country = 'US';
    $Order->Language = 'en';
    $Order->CustomerIP = '91.220.121.21';
    $Order->ExternalReference = NULL;
    $Order->Source = NULL;
    $Order->Affiliate = new stdClass();
    $Order->Affiliate->AffiliateCode = 'Partner123'
    $Order->Affiliate->AffiliateSource = 'MobilePlatform'
    $Order->CustomerReference = NULL;
    
    // Don't forget about B2B flag
    $Order->ExtraInformation = new \stdClass();
    $Order->ExtraInformation->B2B = true;
    
    
    $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->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
    
    // Subscription custom settings
    $Order->Items[0]->SubscriptionCustomSettings = new \stdClass();
    $Order->Items[0]->SubscriptionCustomSettings->ContractLength = "123";
    $Order->Items[0]->SubscriptionCustomSettings->CycleAmountType = "NET";
    $Order->Items[0]->SubscriptionCustomSettings->CycleUnit = "DAY";
    $Order->Items[0]->SubscriptionCustomSettings->CycleAmount = "123";
    $Order->Items[0]->SubscriptionCustomSettings->CycleLength = "123";
    $Order->Items[0]->SubscriptionCustomSettings->MerchantDealAutoRenewal = true;
    $Order->Items[0]->SubscriptionCustomSettings->ClientDealAutoRenewal = true;
    
    
    $Order->BillingDetails = new \stdClass();
    $Order->BillingDetails->FirstName = 'First';
    $Order->BillingDetails->LastName = 'Last';
    $Order->BillingDetails->CountryCode = 'us';
    $Order->BillingDetails->State = 'California';
    $Order->BillingDetails->City = 'LA';
    $Order->BillingDetails->Address1 = 'Address example';
    $Order->BillingDetails->Address2 = NULL;
    $Order->BillingDetails->Zip = '90210';
    $Order->BillingDetails->Email = 'email@address.com';
    $Order->BillingDetails->Phone = NULL;
    $Order->BillingDetails->Company = NULL;
    $Order->DeliveryDetails = NULL;
    
    $Order->PaymentDetails = new \stdClass ();
    $Order->PaymentDetails->Type = 'CC';
    $Order->PaymentDetails->Currency = 'usd';
    $Order->PaymentDetails->PaymentMethod = new \stdClass ();
    $Order->PaymentDetails->CustomerIP = '10.10.10.10';
    $Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
    $Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111";
    $Order->PaymentDetails->PaymentMethod->CardType = 'visa';
    $Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019';
    $Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12';
    $Order->PaymentDetails->PaymentMethod->CCID = '123';
    $Order->PaymentDetails->PaymentMethod->HolderName = 'John';
    $Order->PaymentDetails->PaymentMethod->CardNumberTime = 83.21; // can be null - high value in seconds is a red flag for fraud attempts.
    $Order->PaymentDetails->PaymentMethod->HolderNameTime = 13.35; // can be null - high value in seconds is a red flag for fraud attempts.
    $Order->PaymentDetails->PaymentMethod->Vendor3DSReturnURL = "http://www.success.ro";
    $Order->PaymentDetails->PaymentMethod->Vendor3DSCancelURL = "http://www.error.ro";
    
    $jsonRpcRequest = array (
        'method' => 'placeOrder',
        'params' => array($sessionID, $Order),
        'id' => $i++,
        'jsonrpc' => '2.0'
    );
    
    var_dump(callRPC((Object)$jsonRpcRequest, $host, true));
    
    

    Add additional fields

    Overview

    Use the addAdditionalField method to create new additional fields for your account.

    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.

    AdditionalField

    Object

     

    Additional field object.

    Response

    bool(true)

    Request

    <?php
    
    require ('PATH_TO_AUTH');
    
    $AdditionalField                             = new stdClass();
    $AdditionalField->Label                      = 'Do you agree with the new newsletter policy 2015?';
    $AdditionalField->Type                       = 'LISTBOX';
    $AdditionalField->Code                       = 'NewsletterPolicy1234576';
    $AdditionalField->ApplyTo                    = 'ORDER';
    $AdditionalField->Values                     = array();
    $AdditionalField->Values[0]                  = 'YES';
    $AdditionalField->Values[1]                  = 'NO';
    $AdditionalField->ValidationRule             = null;
    $AdditionalField->Translations               = array();
    $AdditionalField->Translations[0]            = new stdClass();
    $AdditionalField->Translations[0]->Label     = "Êtes-vous d'accord avec la politique de la newsletter?";
    $AdditionalField->Translations[0]->Values    = array();
    $AdditionalField->Translations[0]->Values[0] = 'Oui';
    $AdditionalField->Translations[0]->Values[1] = 'Non';
    $AdditionalField->Translations[0]->Language  = 'fr';
    $AdditionalField->Translations[1]            = new stdClass();
    $AdditionalField->Translations[1]->Label     = 'Haben Sie mit dem Newsletter Politik zu?';
    $AdditionalField->Translations[1]->Values    = array();
    $AdditionalField->Translations[1]->Values[0] = 'Ja';
    $AdditionalField->Translations[1]->Values[1] = 'Nein';
    $AdditionalField->Translations[1]->Language  = 'de';
    
    $jsonRpcRequest = array(
        'jsonrpc' => '2.0',
        'id' => $i++,
        'method' => 'addAdditionalField',
        'params' => array(
            $sessionID,
            $AdditionalField
        )
    );
    var_dump(callRPC((Object) $jsonRpcRequest, $host));
    
    ?>
    

     

    Retrieve a product’s campaigns

    Overview

    Use the getProductCrossSellCampaigns method to extract information on all cross-sells campaigns triggered by the same primary 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 code of the primary product triggering cross-sell campaign that you can define for each of your offerings.

    Response

    Parameters Type/Description

    CrossSellCampaign

    Object

    Request

    <?php
    
    require ('PATH_TO_AUTH');
    
    $ProductCode = 'subscr1';
    
    try {
        $ProductCrossSellCampaigns = $client->getProductCrossSellCampaigns($sessionID, $ProductCode);
    }
    
    catch (SoapFault $e) {
        echo "ProductCrossSellCampaigns: " . $e->getMessage();
        exit;
    }
    
    var_dump("ProductCrossSellCampaigns", $ProductCrossSellCampaigns);
    

     

    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. 2Checkout 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));
    

    Assign a subscription to another customer

    Overview

    Use the setSubscriptionCustomer method. 2Checkout moves subscription under the customer for which you provide the 2Checkout customer reference or the External customer reference during the subscription update process.

    json_diagram.png

    Requirements

    To move a subscription from a source customer to a target customer:

    • Use 2Checkout customer references or External customer references belonging to the target customer. 2Checkout re-assigns the subscription to the target customer. 
    • Customer references must be valid and associated to the target customer entity under which you move the subscription.
    • If you provide both the 2Checkout customer reference and External customer reference they need to belong to the same target customer 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.

    2CheckoutCustomerReference

    Required (int)

     

    System-generated customer reference. Required unless you prefer to use ExternalCustomerReference.

    ExternalCustomerReference

    Optional (string)

     

    External customer reference that you control. Optional when you use 2CheckoutCustomerReference. If you include it, it needs to belong to the same customer as the 2CheckoutCustomerReference.

    Response

    Boolean

    true or false depending on whether the changes were successful 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 = '30E47F8699';
    $customerReference = 220531648;
    try {
        $newCustomerInfo = $client->setSubscriptionCustomer($sessionID, $subscriptionReference, $customerReference);
    }
    catch (SoapFault $e) {
        echo "newCustomerInfo: " . $e->getMessage();
        exit;
    }
    var_dump("newCustomerInfo", $newCustomerInfo);
    
    

     

    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