Skip to main content

Retrieve upgrade options for a subscription

Overview

Use the getProductUpgradeOptions method to retrieve the possible upgrade options 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.

Response

Upgrade options

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

Retrieve assigned additional fields

Overview

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

Parameters

Parameters Type/Description

sessionID

Required (string)

 

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

productCode

Required (string)

 

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

Request

<?php

require ('PATH_TO_AUTH');

$productCode = 'YOUR_PRODUCT_CODE';

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

?>

Response

Parameters Type/Description

AdditionalField

Array of objects

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

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/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;
}
$SubscriptionReferenceTest = '48F5AC7011';
$days = 7;
try {
    $extendedSubscription = $client->extendSubscription($sessionID, $SubscriptionReferenceTest, $days);
}
catch (SoapFault $e) {
    echo "extendedSubscription: " . $e->getMessage();
    exit;
}
var_dump("extendedSubscription", $extendedSubscription);

 

SSO by subscription reference

Overview

Use the getSingleSignOn method to redirect and login shoppers automatically from your user portal into their 2Checkout myAccount based on subscription information. This method connects third-party user hubs with the 2Checkout myAccount, and allows your shoppers to seamlessly sign in to manage their information and perform tasks such as updating/changing credit card details.

Parameters

Parameter 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.

email

Optional (string)

 

End-user email address belonging to the customers associated with the subscription.

validityTime

Optional (int)

 

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

accessPage

Optional (string)

 

The specific myAccount page you want the user to be redirected to. Possible values: view_order, my_license, change_card, my_products, payment_methods, user_data, order_lookup, faq - default: index page
In the payment_methods list is the new text for the available page or page type parameter.

view_order - based on the SubscriptionReference, redirects shoppers to the myAccount page for the initial order that served to purchase the subscription. The 2Checkout system will match the subscription to the order automatically, displaying its associated myAccount view_order page.

my_license - redirect shoppers to the subscription's page of myAccount based on the SubscriptionReference you provide.

change_card - redirects shoppers to the subscription page of myAccount and opens up the change credit card pop-up window designed to update the payment details associated with a subscription.

my_products - redirects shoppers to the myAccount page designed to list all products purchased from 2Checkout.

https://store.YourCustomDomain.com/m...t/my_products/?

user_data - redirects shoppers to the Personal Information page in myAccount

https://store.YourCustomDomain.com/m...unt/user_data/?

order_lookup - redirects shoppers to the Order Lookup page of myAccount.

https://store.YourCustomDomain.com/m.../order_lookup/?

faq - redirects shoppers to the Support page of myAccount

https://store.YourCustomDomain.com/support/

default: index page - redirects shoppers to myAccount homepage

https://store.YourCustomDomain.com/myaccount/?

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

Parameter Type/Description

Single sign-on URL

String

 

The string generated is the complete single sign-on URL pointing to 2Checkout myAccount, containing the unique URL. Shoppers using it log into their 2Checkout myAccount automatically.

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';
$email = 'EMAIL@EXAMPLE.COM';
$validityTime = 50;
$accessPage = 'my_license';
$validationIp = null;

$jsonRpcRequest = array (
'method' => 'getSingleSignOn',
'params' => array($sessionID, $subscriptionReference, $email, $validityTime, $accessPage, $validationIp),
'id' => $i++,
'jsonrpc' => '2.0');

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

Retrieve account balance

Overview

Use getPendingPayout to retrieve a detailed estimation of the amount that 2Checkout owes you, based on the sales from your current payout period.

The amounts returned by this API method are approximations, and may not represent the final amount that 2Checkout will pay you at the end of the billing period.

Parameters

Parameters Type/Description
inputParameters

Object (Optional)

Details below

  Currency String (Optional)
   

Use this parameter to show the balance only for a single order currency. Example: 'USD'.

If not sent, or sent as NULL, 2Checkout sends the balance for all order currencies.

  TotalCurrency String (Optional)
   

Use this parameter to show the total account balance in the preferred currency. Example: 'EUR'.

If not sent, or sent as NULL, 2Checkout sends the total balance in the default account currency.

Request

<?php

require('PATH_TO_AUTH');

$inputParameters = new StdClass();
$inputParameters->Currency = "USD";
$inputParameters->TotalCurrency = "EUR";

try {
    $pendingPayout = $client->getPendingPayout($sessionID, $inputParameters);
}
catch (SoapFault $e) {
    echo "pendingPayout: " . $e->getMessage();
    exit;
}
var_dump("pendingPayout", $pendingPayout);

Response

Pending Payout Object

Parameters   Type/Description
Currencies

Array of objects

Details below

  CurrencyObject

Object

Details below

    Currency

String

      Order currency.
    OrdersTotal

Object

Total order amounts, divided per order source.

                        estore Float
      eStore order amounts from the current payout cycle.
                       affiliates Float
      Amounts from your affiliates' orders, during the current payout cycle.
                       partner Float
      Amounts from your partner sales, during the current payout cycle.
                        total Float
      Total sales amount made in the order currency from this object, during the current payout cycle.
  RetainedToDisputesBalance Float
      Amounts retained to your dispute balance reports, in the object order currency.
  ReleasedFromDisputesBalance Float
      Amounts released from your dispute balance reports, in the object order currency.
  RetainedToRollingReserveBalance Float
      Amounts retained to your rolling reserve, in the object order currency.
  ReleasedFromRollingReserveBalance Float
      Amounts retained to your rolling reserve, in the object order currency
  ChargebackFees Float
      Chargeback fees retained in the object order currency.
  ProcessingFees Float
      Processing fees retained by 2Checkout in the object order currency.
  AffiliatesCommission Float
      Affiliate commissions paid by 2Checkout in the object order currency.
  TaxCollected Float
      Tax collected by 2Checkout in the object order currency.
  EstimatedTotalRevenue Float
      The estimated total revenue for the object order currency.
Total    

Object

Total account balance amount

  Currency  

String

      Currency in which the total account balance is expressed. If not sent during the API call, 2Checkout uses the account default currency.
  OrdersTotal

 

Object

Total order amounts, divided per order source.

    estore Float
      Amounts from total eStore orders during the currency payout cycle.
                      affiliates Float
      Amounts from total affiliates orders during the currency payout cycle.
                      partner Float
      Amounts from total partner orders during the currency payout cycle.
                      total Float
      Total sales amount during the currency payout cycle.
  RetainedToDisputesBalance Float
      Total amounts retained to your dispute balance during the current payout cycle.
  RetainedFromDisputesBalance Float
      Total amounts released from your dispute balance during the current payout cycle.
  RetainedToRollingReserveBalance Float
      Total amounts retained to your rolling reserve during the current payout cycle.
  RetainedFromRollingReserveBalance Float
      Total amounts released from your rolling reserve during the current payout cycle.
  ChargebackFees Float
      Total chargeback fees retained from your account during the currency payout cycle.
  ProcessingFees Float
      Total processing fees retained by 2Checkout during the current payout cycle.
  AffiliatesCommission Float
      Total affiliates commissions paid by 2Checkout during the current payout cycle.
  TaxCollected Float
      Total tax amount collected by 2Checkout during the current payout cycle.
  EstimatedTotalRevenue Float
      Total estimated revenue for the current payout cycle.

 

Place an order with installments

Overview 

Use the placeOrder method to create an order and collect the payment.

Supported payment methods 

Credit/Debit cards: Visa and MasterCard local Brazilian cards.

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.

Requirements

  1. Payment methods: Visa, MasterCard or AMEX
  2. Country: Brazil
  3. Currency BRL
  4. Specified number of installments under the PaymentMethod object. (Minimum installment threshold is 5 BRL.)
    • Phone number
    • Fiscal code (CPF/CNPJ)
  5. Mandatory billing information must include:

  6. Transaction: non-recurring
  7. Installments are available only for:
    • Brazilian customers
    • Local Visa, MasterCard and AMEX cards
    • Non-recurring transactions

 


<?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.1/';
 
$merchantCode = "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 = "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(date('Y-m-d H:i:s')) . date('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, date('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;
 
$sessionID = callRPC($jsonRpcRequest, $host);
 
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'brl';
$Order->Country = 'BR';
$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 = 'BR';
$Order->BillingDetails->State = 'DF';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '70403-900';
$Order->BillingDetails->Email = 'customer@email.com';
$Order->BillingDetails->Phone = "556133127400";
$Order->BillingDetails->FiscalCode = "056.027.963-98";
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'brl';
$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' => 'getInstallments',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);
echo '<BR>';
echo 'The content of the current session:';
echo '<BR>';
$installments = callRPC((Object)$jsonRpcRequest, $host, true);
var_dump ($installments);
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'brl';
$Order->Country = 'BR';
$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 = 'BR';
$Order->BillingDetails->State = 'DF';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '70403-900';
$Order->BillingDetails->Email = 'customer@email.com';
$Order->BillingDetails->Phone = "556133127400";
$Order->BillingDetails->FiscalCode = "056.027.963-98";
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'brl';
$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->InstallmentsNumber = 2;
$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' => 'placeOrder',
'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));


Update price options

Overview

Use the updatePriceOptionGroup method to update/edit an existing price options group you configured for your account. Price options intervals cannot overlap. 

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.

PriceOptionsGroup

Required (object)

 

Use this object to update/edit a new price option group for your account.

You cannot update the Code and Required parameters of the price options group.

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$SearchOptions = new stdClass ();
$SearchOptions->Name = 'New Users from API';

$SearchOptions->Types = array('INTERVAL', 'RADIO'); //RADIO, CHECKBOX, INTERVAL, COMBO, INTERVAL

$SearchOptions->Limit = 10;
$SearchOptions->Page = 1;

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

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

$updatedPriceOptions = $existentPriceOptions[0];

$existentPriceOptions[0]->Translations[0]->Name = 'New Users from API3';
$existentPriceOptions[0]->Translations[0]->Language = 'EN';

$updatedPriceOptions = $existentPriceOptions[0];
echo "$updatedPriceOptions->Name";

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

?>

Retrieve a customer’s subscriptions

Overview

Use the getCustomerSubscriptions method to retrieve details about the subscriptions belonging to a specific customer.

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

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;
}
$CustomerReference = 260015052;
try {
    $ListofSubscriptions = $client->getCustomerSubscriptions($sessionID, $CustomerReference);
}
catch (SoapFault $e) {
    echo "ListofSubscriptions: " . $e->getMessage();
    exit;
}
var_dump("ListofSubscriptions", $ListofSubscriptions);

 

Retrieve a promotion

Overview

Use the getPromotion method to extract information on a promotion you set up 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.

PromotionCode

Required (string)

 

System-generated identifier 2Checkout associated with promotion campaigns.

Response

Parameters Type/Description
Promotion Object 

 

Request

<?php

require ('PATH_TO_AUTH');

$PromotionCode = 'YOUR_COUPON_CODE';

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

?>

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;

try {
    $extendedSubscription = $client->extendSubscription($sessionID, $subscriptionReferenceTest, $days);
}
catch (SoapFault $e) {
    echo "extendedSubscription: " . $e->getMessage();
    exit;
}
var_dump("extendedSubscription", $extendedSubscription);

 

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