Skip to main content

Set pricing option for dynamic products

Overview

Use the Product object option property in order to define pricing options for dynamic products.

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. Set the dynamic mode for cart by callingTwoCoInlineCart.setup.setMode('DYNAMIC').
  4. Set your currency using theTwoCoInlineCart.cart.setCurrency('USD')method.
  5. Use theTwoCoInlineCart.products.add({name, quantity, price, options})method to prepare your dynamic products.
  6. The options property should contain a list of objects with the name of the field, it's value and surcharge.
  7. 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": "2COLRNC",
    "dynamic": "1",
    "currency": "USD",
    "products": [
        {
            "name": "A test dynamic product",
            "quantity": 1,
            "price": 20,
            "options": [
                {
                    "name": "color",
                    "value": "red",
                    "surcharge": 10
                },
                {
                    "name": "shape",
                    "value": "squared",
                    "surcharge": 20
                }
            ]
        }
    ]
}

The above payload will generate the signature 50a651873d3d8926f6bb62397f34b1ec7dd3373fc885b28466db8f4022060138.

8. Use the TwoCoInlineCart.cart.setSignature('50a651873d3d8926f6bb62397f34b1ec7dd3373fc885b28466db8f4022060138') 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.

9. 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.setup.setMode('DYNAMIC');
  TwoCoInlineCart.cart.setCurrency('USD');
  
  TwoCoInlineCart.products.add({
    name: 'A test dynamic product',
    quantity: 1,
    price: 20,
    options: [
      {
        name     : 'color',
        value    : 'red',
        surcharge: 10
      },
      {
        name     : 'shape',
        value    : 'squared',
        surcharge: 20
      }
    ],
  });
  
  TwoCoInlineCart.cart.setSignature('50a651873d3d8926f6bb62397f34b1ec7dd3373fc885b28466db8f4022060138');
  TwoCoInlineCart.cart.checkout();
});

Demo

After setting the pricing options for dynamic products using the above method, your cart should look like this:

 

Search subscriptions

Overview

Extract information on your account’s subscriptions. Use the searchSubscriptions method to retrieve details about your account’s subscriptions, based on a set of filters. 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.

searchBy

Optional (Object)

 

Unique, system-generated subscription identifier.

Additional search filters

SubscriptionSearchOptions Parameters Type/Description

CustomerEmail

Optional (string)

 

Customer email address. Can be NULL.

Note:  The CustomerEmail parameter must be paired always with another reference pointing to the correct customer, such as the 2CheckoutCustomerReference parameter or the ExternalCustomerReference parameter. Otherwise, the search call will return partial hits on the customer email address.

ExactMatchEmail Optional (Boolean)
 

Force search by email to perform exact match; recommended to keep this option set to true in order to avoid matching similar email addresses from multiple customers.

DeliveredCode

Optional (string)

 

Activation key/code. Can be NULL.

2CheckoutCustomerReference

Optional (int)

 

System-generated customer reference. Can be NULL.

ExternalCustomerReference

Optional (string)

 

External customer reference that you control. Can be NULL.

Aggregate

Optional (boolean)

 

true - search will work across all your aggregated 2Checkout accounts.

false - default value. You limit the search to the account whose details you used for authentication.

Can be NULL.

SubscriptionEnabled

Optional (boolean)

 

true for enabled subscriptions.

false for disabled subscriptions.

Can be NULL.

RecurringEnabled

Optional (StringArray)

 

true – 2Checkout charges customers using recurring billing for subscriptions.

false – customers need to make manual payments to renew their subscriptions.

Can be NULL.

ProductCodes

Optional (StringArray)

 

Product identifier that you control. Can be NULL.

CountryCodes

Optional (string)

 

Country code (ISO 3166 two-letter code). Can be NULL.

PartnerCode Optional (string)
  Can be NULL.

PurchasedAfter

Optional (string)

 

YYYY-MM-DD. Subscription search interval start. You can search for subscriptions purchased between the dates you set using PurchasedAfter and PurchasedBefore. Note: The default 2Checkout API time zone is GMT+02:00. Can be NULL.

PurchasedBefore

Optional (string)

 

YYYY-MM-DD. Subscription search interval end. You can search for subscriptions purchased between the dates you set using PurchasedAfter and PurchasedBefore. Note: The default 2Checkout API time zone is GMT+02:00. Can be NULL.

ExpireAfter

Optional (string)

 

YYYY-MM-DD. Search subscriptions set to expire after a specific date. Note: The default 2Checkout API time zone is GMT+02:00. Can be NULL.

ExpireBefore

Optional (string)

 

YYYY-MM-DD. Search subscriptions set to expire before a specific date. Note: The default 2Checkout API time zone is GMT+02:00. Can be NULL.

ModifiedAfter Optional (string)
  YYYY-MM-DD HH-MM-SS. Search subscriptions modified after a specific date.
ModifiedBefore Optional (string)
  YYYY-MM-DD HH-MM-SS. Search subscriptions modified before a specific date.

RenewedAfter

Optional (string)

 

YYYY-MM-DD. Search subscriptions renewed after a specific date. Note: The default 2Checkout API time zone is GMT+02:00. Can be NULL.

RenewedBefore

Optional (string)

 

YYYY-MM-DD. Search subscriptions renewed before a specific date. Note: The default 2Checkout API time zone is GMT+02:00. Can be NULL.

NotificationAfter

Optional (string)

 

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

NotificationBefore

Optional (string)

 

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

NextBillingDateAfter Optional (string)
  YYYY-MM-DD. Search subscriptions with the next billing date after the specified date
NextBillingDateBefore Optional (string)
  YYYY-MM-DD. Search subscriptions with the next billing date before the specified date

Type

Optional (string)

 

trial - trial subscriptions.

regular - all generated subscriptions that are not trials.

regularfromtrial - subscriptions generated from a trial conversion.

Can be NULL.

TestSubscription

Optional (boolean)

 

true

false, depending on whether you want to include test subscriptions in the search or not. Can be NULL.

LifetimeSubscription

Optional (boolean)

 

true – evergreen subscriptions.

false - subscriptions with a limited recurring billing cycle, typically no larger than 36 months.

Can be NULL.

Page

Optional (int)

 

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

Can be NULL.

Limit

Optional (int)

 

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

Can be NULL.

Response

Parameters Type/Description

Subscription

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$SubscriptionSearch = new stdClass();
$SubscriptionSearch->CustomerEmail  = 'example@email.com';
$SubscriptionSearch->DeliveredCode = null;
$SubscriptionSearch->AvangateCustomerReference = null;
$SubscriptionSearch->ExternalCustomerReference = null;
$SubscriptionSearch->Aggregate = false;
$SubscriptionSearch->SubscriptionEnabled = null; //true false null
$SubscriptionSearch->RecurringEnabled = null; // true - autorenewal, false - manual renewal, null = both(default)
$SubscriptionSearch->ProductCodes = null; //array('Product_Code1', 'Product_Code2');
$SubscriptionSearch->CountryCodes = null;//array ('au')
$SubscriptionSearch->PurchasedAfter = null;
$SubscriptionSearch->PurchasedBefore = null;
$SubscriptionSearch->ExpireAfter = null;
$SubscriptionSearch->ExpireBefore = null;
$SubscriptionSearch->LifetimeSubscription = null;
$SubscriptionSearch->Type = 'regular'; //'trial', 'regular', 'regularfromtrial'
$SubscriptionSearch->TestSubscription = null; // true, false, null = both(default) $SubscriptionSearch->Page = 1;$SubscriptionSearch->Limit = 25;
$SubscriptionSearch->Page = 1;
$SubscriptionSearch->Limit = 10;

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

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

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

Optional (int)

 

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

Price

Optional (double)

 

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

Currency

Optional (string)

 

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

Response

Boolean

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

Retrieve options

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

Parameters Type/Description

Subscription upgrade

Array of objects

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';

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

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

Mark leads as used and stop follow-ups

Overview

Use the markLeads method to mark a lead as used and/or stop follow-ups.

Request Parameters

Parameters Required Type/Description
LeadCode Required String. Unique system-generated identifier.
Used Required

Boolean. With possible values:

TRUE - 

FALSE - 

StopFollowups Required

Boolean. With possible values:

TRUE - 

FALSE - 

Request Example

<?php

require ('PATH_TO_AUTH');

$markLead = [
    'LeadCode' => '60E6C4B574',
    'StopFollowups' => false,
    'Used' => true
];

try {
    $leadData = $client->markLeads($sessionID, [$markLead]);
} catch (SoapFault $e) {
    echo "markLeads: " . $e->getMessage();
    exit;
}

var_dump("markLeads", $leadData);

Response Example

class stdClass#18 (2) {
  public $Response =>
  string(37) "1 leads have been marked successfully"
  public $Errors =>
  array(0) {
  }
}

Create EES token

Overview

Use the createEESToken method to be able to place orders with credit cards with installments and 2Pay.js.

Request Parameters

Parameter Name Type Required/Optional Description
       
       
       

Request Example

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.avangate.local/soap/6.0';
    public const ACTION = 'createToken';
    public const ADDITIONAL_OPTIONS = null;
    //array or JSON
    public const PAYLOAD = <<<JSON
{
    "Name": "Mike Doe",
    "CreditCard": "4111111111111111",
    "Cvv": "123",
    "ExpirationDate": "12\/21"
}
JSON;
}

class Client
{
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?object {
        if (is_array($payload)) {
            $payload = json_encode($payload);
        }
        if (!empty($payload)) {
            // SoapClient works with objects(StdClass)
            $payload = json_decode($payload);
        }
        $soapClient = $this->getClient($url);
        $sessionId = $this->getSession($soapClient);
        $args = array_filter([$sessionId, $payload]);

        return $soapClient->$action(...$args);
    }

    public function getClient(string $url): SoapClient
    {
        return new SoapClient(
            $url.'?wsdl',
            [
                'location' => $url,
                'cache_wsdl' => WSDL_CACHE_NONE,
            ]
        );
    }

    public function getSession(SoapClient $client)
    {
        $date = gmdate('Y-m-d H:i:s');
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $string = strlen($merchantCode).$merchantCode.strlen($date).$date;
        $hash = hash_hmac('md5', $string, $key);
        $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');

        return $client->login($merchantCode, $date, $hash);
    }
}

$client = new Client();
$result = $client->call();
var_dump($result);

Response

     
     
     

 

Upgrade price

Overview

Retrieve the upgrade price for a subscription.

Attributes

Parameters

Type/Description

BillingPrice

Double

 

The price Avangate charges the customer, without taxes.

BillingGrossPrice

Double

 

The price Avangate charges the customer, including taxes.

BillingCurrency

String

 

The currency ISO code used for the payment - ISO 4217.

Quantity

Int

 

The mandatory quantity for the upgrade (you cannot make partial upgrades)

DisplayPrice

Double

 

Display price.

DisplayGrossPrice

Double

 

Display price before deductions.

DisplayCurrency

String

 

Display currency. ISO 4217 code.

Discount Float
  Applied discounts
DiscountedBillingPrice Float
  Net billing price available for  the upgrade process with applied discounts
DiscountedBillingGrossPrice Float
  Gross billing price available for  the upgrade process with applied discounts
DisplayDiscount Float
  Discount displayed for the upgrade process
DiscountedDisplayPrice Float
  Net display price available for the upgrade process with applied discounts
DiscountedDisplayGrossPrice Float
  Gross display price available for the upgrade process with applied discounts

Assign to product group

Overview

Use the assignProductGroup method to assign a product to a product group. Following the assignation, the 2Checkout system uses the shopping cart template associated with the product group as the default cart design when shoppers purchase a subscription plan/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 product you wish assigned to the group.

groupCode Required (string)
  Unique, system-generated identifier assigned to product groups. 

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

$productCode = "YOUR_PRODUCT_CODE";
$groupCode = "YOUR_PRODUCT_GROUP_CODE";

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'assignProductGroup',
'params' => array($sessionID, $productCode,$groupCode)
);

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

?>

 

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:

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