Skip to main content

Retrieve session content

Overview

Use the getContents method to get info on all the products added to cart by the shopper in the current session.

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.

Response

OrderContents

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)) {
        $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);
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'US';
$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]->Promotion = NULL;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'FirstName';
$Order->BillingDetails->LastName = 'LastName';
$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 = 'customer@email.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'TEST';
$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->HolderName = 'John';
$Order->PaymentDetails->PaymentMethod->CCID = '123';
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;
$jsonRpcRequest = array (
'method' => 'getContents',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);
echo '<BR>';
echo 'The content of the current session:';
echo '<BR>';
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

Custom subscription renewal price

Overview

Charge customers custom prices for the renewal of subscriptions, moving away from the recurring pricing configuration at product level. Use the setCustomRenewalPrice method to set custom renewal prices for subscriptions and control the number of recurring billing cycles the price impact subscribers.

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.

Price

Required (double)

 

Custom cost subscribers incur.

Currency

Required (string)

 

Number of recurring billing cycles for which 2Checkout charges customers the custom price rather, ignoring product–level recurring pricing configurations. (Can be null - Default value 1)

Cycles

Required (int)

 

The price you want to charge customers for the upgrade. The currency used by default is the same as in the previous payment customers made.

ReasonText

Optional (string)

 

Save details at the subscription-level about the custom costs.

Response

Boolean

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

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';
$Price = 50;
$Currency = 'eur';
$Cycles = 2;
$ReasonText = null;
try {
    $CustomPrice = $client->setCustomRenewalPrice($sessionID, $subscriptionReference, $Price, $Currency, $Cycles, $ReasonText);
}
catch (SoapFault $e) {
    echo "CustomPrice: " . $e->getMessage();
    exit;
}
var_dump("CustomPrice", $CustomPrice);

 

Single Sign-On in cart

Overview

Use the getSingleSignOnInCart method.  Avangate attaches a unique token to links, designed to identify the returning shoppers and support the automatic extraction of payment data and billing information from the Avangate system. For example, you can generate single sign on in cart links for existing customers logged into your website based on their external or Avangate customer IDs.

How does this work?

When accessing the shopping cart using tokenized payment links:

  • Avangate prefills automatically customer billing and delivery details associated with their Avangate customer accounts (linked based on their unique customer IDs).
  • Avangate presents shoppers with an optimized payment area featuring the credit / debit cards used to make previous purchases / transactions in the Avangate system. Customers have the option of selecting one of the payment methods depending on available card-on-file data.

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.

IdCustomer

Required (string)

 

Unique customer identifiers. Can be either the ExternalCustomerReference you control or the system-generated AvangateCustomerReference.

CustomerType

Required (string)

 

Possible values:

  • ExternalCustomerReference
  • AvangateCustomerReference

Url

Required (string)

 

The shopping cart URL. Avangate redirects shoppers to this URL.

 

Possible values:

 

Any buy link you generate from the cPanel or using the API. Note: For the time being, payment tokenization does not support Express Payments Checkout or the Avangate mobile shopping cart.

ValidityTime

Optional (int)

 

The time, in seconds, before the single sign-on URL expires. By default, the URL expires after 10 seconds. (optional)

ValidationIp

Optional (string)

 

The IP address of the shopper, necessary for security purposes. Can be an empty string or a valid IP, or null.

Response

Single sign-on URL

String

 

The generated string is the tokenized time-limited single sign-on URL pointing to Avangate shopping cart.

 

Note: Each SSO link cleans any previous cart sessions. Shoppers using multiple SSO links would purchase only a single product at a time.

 

If shoppers add multiple products to cart via SSO buy links and then use a non-SSO link, they’ll purchase all items using the same order.

When you use single sign on in cart for customers without card on files in the Avangate system, the generated tokenized link prefills the billing information but the purchase process requires that shoppers provide payment information, such as a credit or debit card.

Example: https://store.YourCustomDomain.com/order/checkout.php?PRODS=1112233&logintoken=8b74ac97f8277654563c44da6915b054ba0d21be

 

Important! You can use the value of the logintoken to retrieve customer information by SSO token.

 

Request


<?php
$host   = "https://api.avangate.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.avangate.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$now          = 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;
}
$IdCustomer = '352365983';
$CustomerType = 'AvangateCustomerReference';
$Url = 'https://store.avancart.com/order/checkout.php?PRODS=4639321&QTY=1&CART=1&CARD=2';
$ValidityTime = 50;
$ValidationIp = null;
try {
    $ssoLINK = $client->getSingleSignOnInCart($sessionID, $IdCustomer, $CustomerType, $Url, $ValidityTime, $ValidationIp);
}
catch (SoapFault $e) {
    echo "ssoLINK: " . $e->getMessage();
    exit;
}
var_dump("ssoLINK", $ssoLINK);

Unassign order/product additional fields

Overview

Use the unassignAdditionalField method to update additional fields for your account.

Parameters

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.

FieldCode

Required (string)

 

Field identifier. Alpha-numeric chars, underscores and dashes.

ProductCode

Required (string)

 

The unique product code that you control not the system-generated product identifier.

Response

bool(true)

Request

<?php

$host   = "https://api.avangate.com";
$client = new SoapClient($host . "/soap/3.0/?wsdl", array(
    'location' => $host . "/soap/3.0/",
    "stream_context" => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    ))
));


function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}

$merchantCode = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.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
$now          = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')

$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);

try {
    $sessionID = $client->login($merchantCode, $now, $hash);
}

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

$ProductCode = 'AAA4643116';
$FieldCode = 'NewsletterPolicy123457106';
try {
    $UnassignedAdditionalField = $client->unassignAdditionalField($sessionID, $FieldCode, $ProductCode);
}

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

var_dump("UnassignedAdditionalField", $UnassignedAdditionalField);

?>

Checkout catalog products with custom prices using the signature in InLine Cart

Overview

Use the Product object to set the custom price and add it to the InLine Cart by calling the click event handler. In order to use the product custom prices, you first need to generate a signature for the InLine Checkout. The generated signature is then used for checkout.

 

Recommended resources

Use case

  1. Add an HTML link or button on your page, like the one below.
  2. Create a JavaScript click handler to execute the Inline Client desired methods.
  3. In order to set the currency, use the TwoCoInlineCart.cart.setCurrency(currency-code) method.
  4. Use the TwoCoInlineCart.products.add({code, quantity, options, price}) method or the TwoCoInlineCart.products.addMany(products) method to prepare your catalog product(s).
  5. Use the "price" property within the Product object to set the custom price.
  6. You can see below a signature token request payload for this example. A success response contains a JSON with the property “signature“ which needs to be used at the next step to set the signature using the TwoCoInlineCart method.
{
  "merchant": "AVLRNG",
  "currency": "USD",
  "products": [
    {
      "code": "74B8E17CC0",
      "custom-price": {
        "EUR": 8,
        "USD": 10
      }
    }
  ]
}

The above payload will generate the signature ffe213450a70cdf8e45617dde6331a766e184e02b450e1a537e2b52ef0e4d07e.

7. Use the TwoCoInlineCart.cart.setSignature('ffe213450a70cdf8e45617dde6331a766e184e02b450e1a537e2b52ef0e4d07e') method to set the signature. It is important that you employ TwoCoInlineCart.cart.removeAll() just before the TwoCoInlineCart.products.addMany(products) or TwoCoInlineCart.products.add(product) methods to remove previous products as the signature is based on the products' definition.

8. Use the TwoCoInlineCart.cart.checkout() method to display the cart on your page.

Sample Request

HTML

<a href="#" class="btn btn-success" id="buy-button">Buy bundle now!</a>

JavaScript

window.document
  .getElementById("buy-button")
  .addEventListener("click", function() {
    // Sign the
    TwoCoInlineCart.products.removeAll();
    TwoCoInlineCart.products.addMany([
      {
        code: "74B8E17CC0",
        price: {
          EUR: 8,
          USD: 10
        }
      }
    ]);
    TwoCoInlineCart.cart.setCurrency('USD');
    TwoCoInlineCart.cart.setSignature('ffe213450a70cdf8e45617dde6331a766e184e02b450e1a537e2b52ef0e4d07e');
    TwoCoInlineCart.cart.checkout();
  });

Demo

 

Add/Import test subscriptions with credit/debit card data

Overview

Import test subscription and data from your or a third-party system with payment information assigned, and test advanced renewal and upgrade scenarios in the 2Checkout platform. Contact 2Checkout directly for additional details.

Use the addSubscription method to import a test subscription into the 2Checkout system.

Requirements

Test subscriptions can be imported only for eStore orders. Only dummy credit card data can be assigned to subscriptions. Check here the list of credit cards that can be used for import.

Cardholder name is composed as FirstName + " " + LastName.

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.

Test Optional (integer)
  To add test subscriptions, set the Test parameter to 1. Default value is 0, and belongs to regular subscriptions.

CardPayment

Optional (Object)

 

Object containing card details. Check here the list of credit cards that can be used for import.

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'; // first name and last name are used for determining the CardHolder Name
$EndUser->Language = 'en';
$EndUser->LastName = '2Checkout'; // first name and last name are used for determining the CardHolder Name
$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';
$Subscription->Test = 1; // send 1 for test subscription, 0 for regular subscriptions.

$PaymentCard = new stdClass ();
$PaymentCard->CardNumber = '4111111111111111' ;
$PaymentCard->CardType = 'VISA';
$PaymentCard->ExpirationYear = '2018';
$PaymentCard->ExpirationMonth = '12';
$PaymentCard->CCID = '123';
$PaymentCard->HolderNameTime = '15';
$PaymentCard->CardNumberTime = '15';
$PaymentCard->AutoRenewal = true;

$jsonRpcRequest = array (
'method' => 'addSubscription',
'params' => array($sessionID, $Subscription, $PaymentCard),
'id' => $i++,
'jsonrpc' => '2.0');

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

Retrieve specific list of subscriptions

Overview

Extract information on a specific list of subscriptions. Use the getSubscriptions method to retrieve details about a specific list of your account’s subscriptions.

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 (Array of strings)

 

Unique, system-generated subscription identifier.

Aggregate

Required (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.

Response

Subscription

Array of objects

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;
}
$SubscriptionReferences = array('48F5AC7011', '6A8FDC9CD2', '6A8FDC9CD2', '8F749B63E7');
try {
    $ListofSubscriptions = $client->getSubscriptions($sessionID, $SubscriptionReferences);
}
catch (SoapFault $e) {
    echo "ListofSubscriptions: " . $e->getMessage();
    exit;
}
var_dump("ListofSubscriptions", $ListofSubscriptions);

 

Retrieve specific list of subscriptions

Overview

Extract information on a specific list of subscriptions. Use the getSubscriptions method to retrieve details about a specific list of your account’s subscriptions. 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 (Array of strings)

 

Unique, system-generated subscription identifier.

Aggregate

Required (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.

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;
}
$SubscriptionReferences = array('48F5AC7011', '6A8FDC9CD2', '6A8FDC9CD2', '8F749B63E7');
try {
    $ListofSubscriptions = $client->getSubscriptions($sessionID, $SubscriptionReferences);
}
catch (SoapFault $e) {
    echo "ListofSubscriptions: " . $e->getMessage();
    exit;
}
var_dump("ListofSubscriptions", $ListofSubscriptions);

 

Unassign order/product additional fields

Overview

Use the unassignAdditionalField method to update additional fields for your account.

Parameters

sessionID

Required (string)

 

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

FieldCode

Required (string)

 

Field identifier. Alpha-numeric chars, underscores and dashes.

ProductCode

Required (string)

 

The unique product code that you control not the system-generated product identifier.

Response

bool(true)

Request

<?php

$host   = "https://api.2checkout.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
    'location' => $host . "/soap/4.0/",
    "stream_context" => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    ))
));


function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}

$merchantCode = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key          = "SECRET_KEY"; //your account's secret key available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$now          = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')

$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);

try {
    $sessionID = $client->login($merchantCode, $now, $hash);
}

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

$ProductCode = 'AAA4643116';
$FieldCode = 'NewsletterPolicy123457106';
try {
    $UnassignedAdditionalField = $client->unassignAdditionalField($sessionID, $FieldCode, $ProductCode);
}

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

var_dump("UnassignedAdditionalField", $UnassignedAdditionalField);

?>

 

Extend a subscription

Overview

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

Parameters

Parameters Type/Description

sessionID

Required (string)

 

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

subscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

days

Required (int)

 

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

 

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

 

Cannot be NULL.

Response

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';
$days = 5;

$jsonRpcRequest = array (
'method' => 'extendSubscription',
'params' => array($sessionID, $subscriptionReference, $days),
'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