Skip to main content

Renew a subscription

Overview

Renew a subscription in the Avangate system on-demand, controlling the number of days, price and currency of the extension. Use the renewSubscription method renew 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.

 

Avangate charges customers using the payment data attached to subscriptions. In the case of credit/debit cards, if customers update their payment information in myAccount or if you update these details on behalf of your subscribers, the Avangate system uses the latest card info provided to charge subscription renewals.

days

Required (int)

 

The number of days the Avangate system extends the lifetime of the subscription.

price

Required (double)

 

The price that Avangate charges the customer for the renewal. This is the Net price.

currency

Required (string)

 

The currency associated to the renewal price - ISO 4217 code.

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';
$days = 4;
$price = 50;
$currency = 'eur';

$jsonRpcRequest = array (
'method' => 'renewSubscription',
'params' => array($sessionID, $subscriptionReference, $days, $price, $currency),
'id' => $i++,
'jsonrpc' => '2.0');

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

Set the pricing option for catalog products

Overview

Use the Product object option property to override the default pricing option defined in your 2Checkout Merchant Control Panel.

Use case

  1. Add an HTML link or button in your page like the one below.
  2. Create a JavaScript click handler to execute the InLine Client desired methods.
  3. Use theTwoCoInlineCart.products.add({code, quantity, options})method to prepare your catalog product.
  4. The options property should contain a list of objects with the name of the field and value.
  5. Use theTwoCoInlineCart.cart.checkout()method to show the cart on your page.

Sample request

HTML

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

JavaScript

window.document.getElementById('buy-button').addEventListener('click', function() {
  TwoCoInlineCart.products.add({
    code: "74B8E17CC0",
    quantity: 3,
    options: [
      {
        name: '11234',
        value: 'new123'
      },
      {
        name: "DEMO_NUMBE_OF_PCS",
        value: "premiumversion"
      },
      {
        name: "DEVICES_5",
        value: "two_devices"
      }
    ]
  });
  TwoCoInlineCart.cart.checkout();
});

Demo

After overriding the default pricing option using the above method, your cart should look like this:

Retrieve SKU code by details

Request

<?php

require ('PATH_TO_AUTH');

$skuDetailsObject = [];
$skuDetailsObject['PricingConfigurationCode'] = 'YOUR_CODE';
$skuDetailsObject['Currency'] = 'USD';
$skuDetailsObject['PurchaseType'] = 'NEW_PRODUCT';
$skuDetailsObject['PriceOptions'] = ['B'];
$skuDetailsObject['Quantity'] = 1;

try {
    $getProductByCode = $client->getSKUCodeByDetails($sessionID, $skuDetailsObject);
} catch (SoapFault $e) {

    echo  $e->getMessage();
}
var_dump($getProductByCode);

Shipping price

Overview

The object below is returned directly or within a successful response from the following API requests:

Retrieve shipping price

Shipping price object

Parameters Type/Description
Shipping prices available

Array of objects

Details below

  Name   String
      Name of the shipping method available for the cart configuration.
  Code   String
      System-generated identified assigned to the shipping method.
  TrackingURL String
      Tracking URL defined at shipping method leve.
  Currency   String
      Currency in which shipping prices are expressed.
  PriceDetails Object
          Details below.
           Net   Object
      Shipping price for a NET price configuration.
    TotalAmount Int
      Total shipping price charged from customers for a cart configuration.
    BasePrice Int
      Shipping method base price amount.
    OverweightAmount Int
      Overweight amount applied to the purchase.
    CountrySurcharge Int
      Surcharge applied based on customer delivery country.
    WeightSurcharge Int
      Surcharged applied based on total order weight.
    OrderSurcharge Int
      Surcharged applied based on total order amount.
           Gross   Object
      Shipping price for a GROSS price configuration.
    TotalAmount Int
      Total shipping price charged from customers for a cart configuration.
    BasePrice Int
      Shipping method base price amount.
    OverweightAmount Int
      Overweight amount applied to the purchase.
    CountrySurcharge Int
      Surcharge applied based on customer delivery country.
    WeightSurcharge Int
      Surcharged applied based on total order weight.
    OrderSurcharge Int
      Surcharged applied based on total order amount.

 

Add products to a promotion

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

// Define first product to add to promotion
$products1 = new stdClass;
$products1->Code = 'YOUR_PRODUCT_CODE';
$products1->PricingConfigurationCode = 'YOUR_PRICING_CONFIGURATION_CODE';
$products1->PricingOptionCodes = ['code1','code2','code3'];

// Define second product to add to promotion
$products2 = new stdClass;
$products2->Code = 'YOUR_PRODUCT_CODE2';
$products2->PricingConfigurationCode = 'YOUR_PRICING_CONFIGURATION_CODE2';

$promotionProducts = [$products1, products2]; // Array of product objects to be added to the promotion

// Retrieve promotion details
$promotionCode = 'YOUR_PROMOTION_CODE'; // code of the promotion that you want to add products to
$response = Client::addPromotionProducts($promotionCode,$promotionProducts);
var_dump($response);

Retrieve an affiliate by code

Overview

Use the getAffiliate method to extract details about an affiliate by code.

Request Parameters

Parameters Required Type/Description
AffiliateCode Required String. Unique code which represents an affiliate.

Request Example

<?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',
        'Cookie: XDEBUG_SESSION=PHPSTORM',
    ));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);


    if ($Debug) {
        var_dump($RequestString);
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        var_dump($ResponseString);
    }

    if (!empty($ResponseString)) {
//        var_dump($ResponseString);
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        var_dump($Response);

        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}


$apiVersion = '6.0';
$host = "http://api.sandbox34.avangate.local/rpc/" . $apiVersion . "/";

$merchantCode = "lucian";
$key = "SECRET_KEY";

$date = gmdate('Y-m-d H:i:s');

$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$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, $hash);
$jsonRpcRequest->id = $i++;

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

$affiliateId = "79396127BA";
// Active:
// 1295 - 964CF2AF42
// 11541 - E4B69882C2
// 12951 - E8A1DB473C
// 12950 - 44857BFE94

// Pending:
// 13639 - F56BCF1E2E

// Rejected
// 65602 - 79396127BA

$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'getAffiliate';
$jsonRpcRequest->params = array($sessionID, $affiliateId);
$jsonRpcRequest->id = $i++;
echo "\nRESPONSE: \n\n";
$getAffiliate = callRPC($jsonRpcRequest, $host, false);

print_r(json_encode($getAffiliate));

Response Parameters

Parameters Description

AffiliateCode

Unique, system-generated identifying code of the affiliate.
Status Merchant Affiliate relationship status.
AffiliateName Name of the affiliate.
Website Website of the affiliate.
CommissionList Affiliate commission list.
                                        ListName Name of the affiliate commission list.
                                        CommissionRate Value of the commission rate (in %).
RequestDate  
Categories Product category  of the affiliate.
NotifyUpdates Boolean. Value can be TRUE or FALSE.
TCSStatus  
AffiliateContact Affiliate contact details.
                                         FirstName Affiliate first name.
                                         LastName Affiliate last name.
                                        Phone Affiliate phone number.
                                        Email Affiliate email.
                                        Country Country of the affiliate.

Response Example

{  
   "AffiliateCode":"TFTF76455ee4YFCFCT6545465",
   "Status":"Active",
   "Affiliate Name":"STIC Soft E-Solutions Private Limited",
   "Website":"https://debasis.2checkout.com",
   "CommissionList":  {  
         "ListName":"CommissionList1",
         "CommissionRate":"25%"
    },
   "RequestDate":"2018-10-05",
   "Categories":["PC security","Mobile security","Tablet security"],
   "TCStatus":"Accepted",
   "AffiliateContact":{  
      "FirstName":"FN",
      "LastName":"LN",
      "Phone":"0040723483987",
      "Email":"FN.LN@2AFFLT.COM",
      "Country":"Spain"
   }
}

 

Update a product group

Overview

Use the updateProductGroup method to update a product group 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.

ProductGroup

Required (object)

 

The product group name is used to identify the product group and cannot be changed in API v2.0. Use API 2.5 and above to change additional characteristics of product groups.

Response

bool(true)

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 = "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;
}


$ProductGroup = new stdClass();
$ProductGroup->Name = 'New Product Group from API';
$ProductGroup->Code = 'DBA13A4268';
$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 = false;


try {
    $UpdatedProductGroup = $client->updateProductGroup($sessionID, $ProductGroup);
}

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

var_dump("UpdatedProductGroup", $UpdatedProductGroup);


?>

Control recurring billing

Overview

Use this feature to control recurring billing (the automatic renewal system) for a specific subscription,  limiting the number of future payments, and preventing automated and manual renewals. Stopping automatic recurring billing does not cancel the subscription unless you also check the Cancel subscription when automatic billing ends option. Otherwise, customers have the option of using their subscription beyond the current billing cycle, provided that they purchase renewals manually. 

By using this feature you can:

  • Stop automatic recurring billing for a subscription either immediately or at a certain time in the future/after a number of billing cycles.
  • Cancel manual renewal emails for the subscription for which automatic recurring billing was stopped after a specific number of billing cycles and prevent the customers from renewing the subscription both manually and automatically after the last payment is made.

Availability

You can stop automatic billing for:

  • Active subscriptions
  • Expired subscriptions
  • Past due subscriptions
  • Subscriptions generated for products purchased with a payment method that supports recurring billing, such as credit and debit cards, PayPal and Direct Debit

Auto-renewal (automatic billing) is not available for:

  1. Lifetime subscriptions
  2. Expired subscriptions with the expiration deadline in the past (before the moment when you attempt to re-enable recurring billing).

Stop automatic recurring billing

To stop automatic recurring billing (auto-renewal):

  1. Go to Subscriptions management.
  2. Search for the subscription and edit its settings.
  3. Click Stop automatic billing.
  4. Enter the number of billing cycles to cancel the subscription after.
  5. Enable the Cancel subscription when automatic billing ends option.
  6. Click Apply.
  7. Once disabled, you can switch it back on, provided that payment data is available.

Options

Stop automatic billing:

  1. Now - This setting comes into effect at the end of the subscription's current billing cycle. If you also want to disable the subscription when it expires, check the Cancel subscription when automatic billing ends option. 2Checkout disables the automatic renewal system immediately after you click Apply and transitions the subscription to manual renewal payments. 2Checkout will no longer charge the customer automatically for the next billing cycle (when the automatic renewal of the subscription was scheduled). This option enables you to Send a notification email to the customer providing subscription level information about the automated recurring billing settings. When the Now option is selected, customers receive manual renewal emails according to the subscription renewal configuration and can use the links provided in the messages to purchase renewals. In addition, during the ordering process, customers will also have the option of re-enabling the automatic renewal system.
  2. After a specified number of billing cycles.  If you also want to disable the subscription when it expires, check the Cancel subscription when automatic billing ends option. The 2Checkout system stops automatic recurring billing after a specific number of billing cycles. Stopping automated recurring billing for subscriptions after a number of billing cycles cancels any manual renewal emails set to be sent to customers associated with the subscriptions according to the global or per-product renewal configurations. When recurring billing/the renewal system is disabled for a subscription, the 2Checkout system will no longer attempt to send the manual renewal messages to the customer using it. For subscriptions with the automatic recurring billing disabled after a number of billing cycles, the manual renewal link won't be visible to customers when they log into their myAccount platform.

FAQ

  1. Can I re-enable automated recurring billing?
    • You can re-enable automatic recurring billing and have subscriptions renewed automatically as well as customers charged per the recurring billing configuration of the products for which subscriptions were generated only in scenarios in which sufficient payment data is available in the 2Checkout system.  While re-enabling automatic recurring billing is possible for credit and debit cards, the option is missing for subscriptions paid using PayPal and Direct Debit, for which this functionality was disabled.
  2. Can I re-enable automatic billing for imported subscriptions?
    • Only for subscriptions that were imported into the 2Checkout system along with credit card information attached.
  3. Can I re-enable automatic billing for canceled subscriptions?
    • To re-enable automatic billing for canceled subscriptions, you need to first reactivate them. In addition, the subscriptions must have credit card information submitted in the 2Checkout system.
  4. Is this functionality supported for trial subscriptions?
    • Yes. You can disable and re-enable automatic recurring billing for trial subscriptions via the Control Panel or through the 2Checkout API. Customers can do the same when logged into their myAccount. The requirements mentioned above still have to be met. On top of the requirements enumerated above, the payment terminal must support auto-renewal, but the reference of the transaction made for the previous order is not required.
    • When the status of automatic billing is disabled, it means that the 2Checkout system has sufficient data for this functionality to be re-enabled to start charging the customer on the upcoming billing cycles.
    • When the status of automatic billing is N/A (not available), it means that the 2Checkout system does not have sufficient data for this functionality to be re-enabled to start charging the customer on the upcoming billing cycles. In this case, customers can renew their subscription manually and choose to reactivate automatic recurring billing (the renewal system) before placing their order.
    • Customers will be able to disable and re-enable the auto-renewal system of subscriptions on-demand, by logging into their myAccount.
    • Suggestion: In the eventuality in which you canceled automated recurring billing for a subscription after a number of billing cycles, but the new setting has yet to come into effect, you can increase the number of billing cycles and prolong the disabling of the automated recurring billing until after a maximum of 100 billing cycles, for example. Recurring billing will only stop when the number of billing cycles defined passes.
  5. Can customers continue to use any ongoing subscriptions they purchased?
    • Yes, but only through the duration of the current billing cycle or a number of billing cycles, as it was set when stopping recurring billing. Otherwise, disabling the renewal system has no impact on the subscription usage, it only keeps the 2Checkout system from automatically billing the customer, and the customer from renewing the subscription. Changes to automatic billing will only impact customers:
      • starting with the next automatic billing cycle/when the next payment is due - the option Now is selected;
      • after a number of billing cycles/payments according to the setting you configure.
  6. Can the subscription be manually renewed by the customer?
    • Only in scenarios in which you disabled automatic billing using the option Now. If you stop automatic billing after a number of billing cycles, customers will not be able to manually renew subscriptions for which the auto-renewal system/automated recurring billing was disabled.
    • Please bear in mind that when stopping automatic recurring billing after a number of billing cycles you also stop manual renewal subscriptions from being sent to customers, as such, the 2Checkout system will no longer offer the manual renewal link.
    • In addition, the manual renewal link is no longer available in myAccount for subscriptions with automatic recurring billing disabled.

Subscription

Overview

Retrieve information and manage subscriptions for your account. Subscriptions can be retrieved starting with 5 minutes after their orders are generated in the 2Checkout system.

Object parameters

Parameters Type/Description

SubscriptionReference

String

 

Unique, system-generated subscription identifier.

StartDate

String

 

Subscription start date(YYYY-MM-DD) - StartDate is mandatory when importing subscription data. If you changed the time zone for the Avangate API by editing system settings under Account settings, then the StartDate you provide must be in accordance with your custom configuration.

ExpirationDate

String

 

Subscription expiration date(YYYY-MM-DD) - ExpirationDate is mandatory when importing subscription data. If you changed the time zone for the Avangate API by editing system settings under Account settings, then the ExpirationDate you provide must be in accordance with your custom configuration.

RecurringEnabled

Boolean

 

Possible values:

TRUE – recurring billing/automatic subscription renewals enabled

FALSE– recurring billing/automatic subscription renewals disabled

SubscriptionEnabled

Boolean

Possible values:

TRUE –subscription enabled

FALSE–subscription disabled

Product

Required (object)

 

The product for which Avangate generated the subscription. Details below.

 

ProductCode

String

 

 

Unique product identifier that you control.

 

ProductId

Int

 

 

Unique, system-generated product identifier.

 

ProductName

String

 

 

Product name.

 

ProductQuantity

Int

 

 

Ordered number of units.

 

ProductVersion

String

 

 

Product version.

 

PriceOptionCodes

Array

 

 

The product options codes the customer selected when acquiring the subscription. Pricing options codes are case sensitive.

EndUser

Object

 

The end user of the subscription. Details below.

 

Person

Object

 

 

FirstName

String

 

 

 

End user's first name

 

 

LastName

String

 

 

 

End user's last name

 

 

CountryCode

String

 

 

 

End user country code [ISO3166-1 Alpha 2].

 

 

State

String

 

 

 

End user state.

 

 

City

String

 

 

 

End user city.

 

 

Address1

String

 

 

 

End user first address line.

 

 

Address2

String

 

 

 

End user second address line.

 

 

Zip

String

 

 

 

End user zip code.

 

 

Email

String

 

 

 

End user email address.

 

 

Phone

String

 

 

 

End user phone number.

 

 

Company

String

 

 

 

Company name.

 

Fax

String

 

 

End user fax.

 

Language

String

 

 

Language [ISO639-2] the Avangate system uses for communications.

SKU

String

 

Stock keeping unit you defined.

DeliveryInfo

Object

 

The object contains information about the delivery/fulfillment made to the customer.

 

Description

String

 

 

Delivery description.

 

Codes

Array of objects

 

 

Code

String

 

 

 

Activation key/license code of the first order from this subscription. Use getSubscriptionHistory method if you want to retrieve the activation keys/license codes for all orders belonging to a subscription.

 

 

Description

String

 

 

 

Code description for dynamic lists from your key generator. 

 

 

ExtraInfo

Object

 

 

 

Info set by your key generator for dynamic lists only.

 

 

 

CodeExtraInfo

Object

 

 

 

Type

String

 

 

 

Label

String

 

 

 

Value

String

 

 

File

Array of objects

 

 

 

Content

String

 

 

 

 

Content of the file (base64 encoded).

 

 

 

ContentLength

Int

 

 

 

 

File size.

 

 

 

Filename

String

 

 

 

 

The name of the delivered file.

 

 

 

FileType

String

 

 

 

 

The type of the delivered file.

ReceiveNotifications

Boolean

 

1 – Subscribe: Avangate sends subscription notifications to the end user.

0 – Unsubscribe – Avangate does not send subscription notifications to the end user.

Lifetime

Boolean

 

Possible values:

  • True – the subscription is evergreen

False – the subscription has a recurring billing cycle less than or equal to three years.

PartnerCode

String

 

  • Empty: for ecommerce orders

Partner Code

AvangateCustomerReference

Int

 

Unique, system-generated customer identifier.

ExternalCustomerReference

String

 

Customer identifier that you control.

TestSubscription

Boolean

 

True for test subscriptions, false otherwise.

IsTrial

Boolean

 

True for trial subscriptions, false otherwise.

MerchantCode String
  Unique, system-generated ID in the Avangate system.

 

Retrieve a subscription

Overview

Extract information on a single subscription. Use the getSubscription method to retrieve details about 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

Subscription

Object

Request


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

function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$now          = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);
try {
    $sessionID = $client->login($merchantCode, $now, $hash);
}
catch (SoapFault $e) {
    echo "Authentication: " . $e->getMessage();
    exit;
}
$subscriptionReference = 'F27CFE06ED';
try {
    $subscriptionInfo = $client->getSubscription($sessionID, $subscriptionReference);
}
catch (SoapFault $e) {
    echo "subscriptionInfo: " . $e->getMessage();
    exit;
}
var_dump("subscriptionInfo", $subscriptionInfo);

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo