Skip to main content

Retrieve subscription deal information

Overview

Use the GetDealInfo method to retrieve information about the existing deal on a given subscription as well as what the subscription will look like with the new proposed deal being applied to it.

Request parameters

Parameter name

Type

Required/Optional

Description

Currency

String

Required

The desired output currency.

Language

String Required

The desired output language.

Items

Array

Required

Each item corresponds to a subscription.

Items.DealDate

Datetime

Required

The date when the deal is set to come into effect. Format: YYYY-MM-DD HH:MM:SS.

Items.SubscriptionReference

String

Required

The subscription code.

Items.ProductCode

String

Required

The product code.

Items.Quantity

String

Required

The product quantity.

Items.DealPriceScenario

String

Required

The upgrade scenario to be applied. Must be one of: using_last_order_price, using_last_product_price, price_total, product_price_difference.

Items.DealSubscriptionScenario

String

Required

The scenarion for price calculation. Must be on of: start_new_deal_contract_now, start_new_deal_contract_after_current_cycle.

Items.PriceOptions

Array

Optional

The array of price options.

Items.PriceOptions.Code

String

Required

The price option group code if the group is of interval type or the price option code otherwise.

Items.PriceOptions.Options

Array

Optional

The array of options that belong to this option group.

Items.PriceOptions.Options.Value

String

Required

If the group is of type “scale”, this is a value from the allowed interval, otherwise, this is the option code as defined in Merchant Control Panel under “Unique Code”.

Items.Price

Object

Required

The product price.

Items.Price.Amount

Float

Required

The actual numeric amount.

Items.Price.Type

String

Required

Describes if the price type is catalog or custom. Can be only CUSTOM.

Items.Price.AmountType

String

Required

Describes if the price is NET or GROSS. Can be one of NET, GROSS.

Items.SubscriptionCustomSettings.CycleLength

Int

Required

The length of a single billing cycle.

Items.SubscriptionCustomSettings.CycleUnit

String

Required

The unit of a single billing cycle. Can be one of MONTH, DAY. 

To perform a getDeal call towards a One Time Fee subscription, this value must be -1.

Items.SubscriptionCustomSettings.CycleAmount

Float

Required

The price of a single billing cycle.

Items.SubscriptionCustomSettings.CycleAmountType

String

Required

Describes the price type. Can be one of NET, GROSS.

Items.SubscriptionCustomSettings.ContractLength

Int

Required

The number of billing cycles contained in a single contract. To perform a getDeal call towards a One Time Fee or a Lifetime subscription, this value must be NULL.

BillingDetails

Object

Required

The billing details.

BillingDetails.FirstName

String

Required

The first name.

BillingDetails.LastName

String

Required

The last name.

BillingDetails.CountryCode

String

Required

The country code. Must be one of the seller's associated country codes.

BillingDetails.State

String

Optional

Required only if the business model requires it.

BillingDetails.City

String

Required

The city name.

BillingDetails.Address1

String

Required

The address.

BillingDetails.Zip

String

Required

The zip code.

BillingDetails.Email

String

Required

The email address.

BillingDetails.Phone

String

Required

The phone number.

BillingDetails.Company

String

Required

The company's legal name.

BillingDetails.FiscalCode

String

Required

The fiscal code.

DeliveryDetails

Object

Required

The delivery details.

DeliveryDetails.FirstName

String

Required

The first name.

DeliveryDetails.LastName

String

Required

The last name.

DeliveryDetails.CountryCode

String

Required

The country code. Must be one of the seller's associated country codes.

DeliveryDetails.State

String

Optional

Required only if the business model requires it.

DeliveryDetails.City

String

Required

The city name.

DeliveryDetails.Address1

String

Required

The address.

DeliveryDetails.Zip

String

Required

The zip code.

DeliveryDetails.Email

String

Required

The email address.

DeliveryDetails.Phone

String

Required

The phone number.

DeliveryDetails.Company

String

Required

The company's legal name.

Request sample

<?php
declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/soap/6.0';
    public const ACTION = 'getDealInfo';
    //array or JSON
    public const PAYLOAD = <<<JSON
 {
  "Currency": "us",
  "Country": "us",
  "Language": "ro",
  "CustomerIp": "91.220.121.21",
  "Source": "salesforce_cpq",
  "Items": [
    {
      "DealDate": "2021-09-20 23:59:59",
      "SubscriptionReference": "MY2DD1E8P0",
      "ProductCode": "CD297BBCE9",
      "Quantity": 10,
      "DealPriceScenario": "using_last_order_price",
      "DealSubscriptionScenario": "prolong",
      "Price": {
        "Amount": 10,
        "Type": "CUSTOM",
        "AmountType": "NET"
      },
      "SubscriptionCustomSettings": {
        "CycleLength": 1,
        "CycleUnit": "MONTHS",
        "CycleAmount": 10,
        "CycleAmountType": "NET",
        "ContractLength": 12
      }
    }
  ],
  "BillingDetails": {
    "FirstName": "Oscar",
    "LastName": "McMillan",
    "CountryCode": "ro",
    "State": "Ilsios",
    "City": "RE",
    "Address1": "4519 Kovar Road",
    "Zip": "645",
    "Email": "o.mcmillan@integrawealth.net",
    "Phone": "6172938133",
    "Company": "Integra Wealth",
    "FiscalCode": "2816464"
  },
  "DeliveryDetails": {
    "FirstName": "Maria",
    "LastName": "Frederick",
    "CountryCode": "ro",
    "State": "New York",
    "City": "Buffalo",
    "Address1": "2033 Nuzum Court",
    "Zip": "14216",
    "Email": "m.frederick@integrawealth.net",
    "Phone": "7165708136",
    "Company": "Integra Wealth"
  }
}
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);
    }
}

try {
    $client = new Client();
    var_dump($client->call());
} catch (Exception $ex) {
    var_dump($ex);
}

Response 

Parameter name

Type

Description

Currency

String

The currency code of all the returned price values.

DealDueNowPriceNet

Float

The NET amount that needs to be paid.

DealDueNowPriceGross

Float

The GROSS amount that needs to be paid.

DealTaxAmount

Float

The tax amount (DealDueNowPriceGross - DealDueNowPriceNet).

Items

Array

The array of response items, one for each subscription.

Items.SubscriptionReference

String

The subscription code.

Items.DealPriceScenario

String

The provided DealPriceScenario.

Items.DealSubscriptionScenario

String

The provided DealSubscriptionScenario.

Items.DealDate

Datetime

The provided DealDate. Format: YYYY-MM-DD HH:MM:SS.

Items.DealDueNowPriceNet

Float

The NET amount to be paid now.

Items.DealDueNowPriceGross

Float

The GROSS amount to be paid now.

Items.DealTaxAmount

Float

The tax amount.

Items.DealTaxPercent

Int

The percent that the tax amount is covering from the GROSS price.

Items.CurrentInfo

Object

The current subscription information.

Items.CurrentInfo.ProductCode

String

The product code.

Items.CurrentInfo.ProductName

String

The product name.

Items.CurrentInfo.ProductDescription

String

The product description.

Items.CurrentInfo.BillingPriceNet

Float

The NET price of a billing cycle.

Items.CurrentInfo.BillingPriceGross

Float

The GROSS price of a billing cycle.

Items.CurrentInfo.NoOfBillingCycles

Int

The number of billing cycles.

Items.CurrentInfo.CurrentBillingCycle

Int

The current billing cycle number.

Items.CurrentInfo.PayedBillingCycles

Int

The number of paid billing cycles.

Items.CurrentInfo.RemainingBillingCycles

Int

The number of remaining billing cycles.

Items.CurrentInfo.CurrentBillingCycleEndDate

Datetime

The end date of the current billing cycle. Format: YYYY-MM-DD HH:MM:SS.

Items.CurrentInfo.TaxAmount

Float

The tax amount.

Items.CurrentInfo.TaxPercent

Float

The percent that the tax amount is covering from the GROSS price.

Items.CurrentInfo.BillingCyclesFrequency

String

The frequency of a billing cycle for the current subscription as it is now.

Items.CurrentInfo.BillingCycleFrequencyUnit

String

The unit of a billing cycle for the current subscription as it is now.

Can be one of MONTHS, DAYS.

Items.CurrentInfo.ContractLength

Int

The contract length for the current subscription as it is now.

Items.CurrentInfo.ContractLengthUnit

Int

The unit of the contract length for the current subscription as it is now. Can be one of MONTH, DAY.

Items.CurrentInfo.ProductOptions

Array

The array of existing product options.

Items.CurrentInfo.ProductOptions.Code

String

The option group code as defined in the Merchant Control Panel under “Unique Code”.

Items.CurrentInfo.ProductOptions.Value

String

The price option value if the group is of type interval or the price option code as defined in the Merchant Control Panel under “Unique Code” otherwise.

Items.NewDealInfo

Object

The new deal information.

Items.NewDealInfo.ProductCode

String

The product code.

Items.NewDealInfo.ProductName

String

The product name.

Items.NewDealInfo.ProductDescription

String

The product description.

Items.NewDealInfo.BillingPriceNet

Float

The NET price of a billing cycle.

Items.NewDealInfo.BillingPriceGross

Float

The GROSS price of a billing cycle.

Items.NewDealInfo.NoOfBillingCycles

Int

The number of billing cycles.

Items.NewDealInfo.CurrentBillingCycle

Int

The current billing cycle number.

Items.NewDealInfo.PayedBillingCycles

Int

The number of paid billing cycles.

Items.NewDealInfo.RemainingBillingCycles

Int

The number of remaining billing cycles.

Items.NewDealInfo.CurrentBillingCycleEndDate

Datetime

The end date of the current billing cycle. Format: YYYY-MM-DD HH:MM:SS.

Items.NewDealInfo.TaxAmount

Float

The tax amount.

Items.NewDealInfo.TaxPercent

Float

The percent that the tax amount is covering from the GROSS price.

Items.NewDealInfoBillingCyclesFrequency

Int

The frequency of a billing cycle for this subscription following an eventual deal change with the provided Items.SubscriptionCustomSettings. In case of a One Time Fee subscription, this value will be -1.

Items.NewDealInfo.BillingCycleFrequencyUnit

String

The unit of a billing cycle for this subscription following an eventual deal change with the provided Items.SubscriptionCustomSettings. Can be one of MONTH, DAY.

Items.NewDealInfo.ContractLength

Int

The contract length for this subscription following an eventual deal change with the provided Items.SubscriptionCustomSettings. In case of a One Time Fee or Lifetime subscription, this value will be NULL.

Items.NewDealInfo.ContractLengthUnit

String

The unit of the contract length for this subscription following an eventual deal change with the provided Items.SubscriptionCustomSettings. Ca be one of MONTH, DAY.

Items.NewDealInfo.ProductOptions

Array

The array of existing product options.

Items.NewDealInfo.ProductOptions.Code

String

The option group code as it's defined in the Merchant Control Panel under “Unique Code”.

Items.NewDealInfo.ProductOptions.Value

String

The price option value if the group is of type interval or the price option code as defined in the Merchant Control Panel under “Unique Code” otherwise.

Items.TotalsDealInfo

Object

General statistics regarding the subscription.

Items.TotalsDealInfo.DealsNumber

Int

The total number of deals made so far.

Items.TotalsDealInfo.ContractsNumber

Int

The total number of contracts made so far.

Items.TotalsDealInfo.PaidBillingCycles

Int

The number of paid billing cycles.

Items.TotalsDealInfo.ElapsedBillingCycles

Int

The number of elapsed billing cycles.

Error handling

Situation

Error Code

Error Message

Mandatory parameter(s) not provided

MALFORMED_PARAMETER

Currency not provided, Items.SubscriptionReference not provided, Items.Price.Type not provided, ...

DealDate not provided in required format

MALFORMED_PARAMETER

Invalid format provided for Items.DealDate. Format must be Y-m-d H:i:s. Provided: 2021-0920 23:59:59.

DealDate is in the past

MALFORMED_PARAMETER

Deal date 2020-09-20 23:59:59 is in the past.

Subscription not found or not associated with seller

VALIDATION_SUBSCRIPTION_MISSING

Subscription 6D4F1S81EEB not found.

Subscription not active

VALIDATION_SUBSCRIPTION_INACTIVE

Subscription 6D4F181EEB not active.

Product not found or not associated with seller

VALIDATION_PRODUCT_MISSING

Product with code 6A4C23036C not found.

Product not active

VALIDATION_PRODUCT_INACTIVE

Product with code 6A4C23036C not active.

The subscription is not B2B due to no custom renewal settings being found on subscription

VALIDATION_SUBSCRIPTION_NOT_B2B

No custom renewal settings found for subscription 6D4F1S81EEB. This subscription may not be a B2B subscription.

Provided price option groups are not valid price options for provided product

VALIDATION_PRICE_OPTION_MISSING

Some of the provided price options not found!

Provided subscription upgrade scenario not among supported values

VALIDATION_DEAL_SUBSCRIPTION_SCENARIO

Invalid upgrade subscription scenario provided: 'WRONG_SCENARIO'. Must be one of start_new_deal_contract_now, start_new_deal_contract_after_current_cycle.

Provided subscription price scenario not among supported values

VALIDATION_DEAL_PRICE_SCENARIO

Invalid price scenario provided: 'WRONG_SCENARIO'. Must be one of: using_last_order_price, using_last_product_price, price_total, product_price_difference.

Provided subscription price scenario not among supported values

VALIDATION_FISCAL_CODE

<fiscal code validation error>

Invalid billing email provided

VALIDATION_BILLING_DETAILS

Invalid billing email provided.

Provided billing country not among seller supported countries.

VALIDATION_BILLING_DETAILS

Provided billing country not among seller supported countries.

Business model tax calculation type requires that BillingDetails.State be provided.

VALIDATION_BILLING_DETAILS

Business model tax calculation type requires that BillingDetails.State be provided.

Invalid delivery email provided

VALIDATION_DELIVERY_DETAILS

Invalid delivery email provided.

Provided delivery country not among seller supported countries.

VALIDATION_DELIVERY_DETAILS

Provided delivery country not among seller supported countries.

Business model tax calculation type requires that DeliveryDetails.State be provided.

VALIDATION_DELIVERY_DETAILS

Business model tax calculation type requires that DeliveryDetails.State be provided.

Country '{$deliveryCountryCode}' provided in two different business model distributions.

VALIDATION_BUSINESS_MODEL

Country provided in two different business model distributions.

Invalid price type detected for the next renewal price

INTERNAL_ERROR

Internal error

Unexpected error

INTERNAL_ERROR

Internal error

 

Pricing configuration

Overview

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

Retrieve a pricing configuration by name            Retrieve a pricing configuration by code               Retrieve pricing configurations

Pricing configuration object

Parameters Type/Description

Name

String

 

Pricing configuration name.

Code

String

 

System-generated identifier. Read-only.

Default

Boolean

 

True for the default pricing configuration

BillingCountries

Array of strings

 

ISO codes of the countries assigned to the pricing configuration.

Empty unless a pricing configuration has specific countries assigned.

PricingSchema

String

 

DYNAMIC – With a base price

FLAT – Without a base price

PriceType

String

 

Possible values:

• NET

• GROSS

DefaultCurrency

String

 

The ISO code of the default currency for the pricing configuration.

Prices

Object

 

Details below.

 

Regular

Array of objects

 

 

Details below.

 

 

Amount

Int

 

 

 

The price of the product. Use -1 to delete it.

 

 

Currency

String

 

 

 

ISO code of the currency for the product price.

 

 

MinQuantity

Int

 

 

 

The minimum quantity of volume discounts. Default is 1.

 

 

MaxQuantity

Int

 

 

 

The maximum quantity of volume discounts. Default is 99999.

 

 

OptionCodes

Array of objects

 

 

 

Details below.

 

 

 

Code

String

 

 

 

 

System generated pricing options group code (you can also configure it) that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

 

 

 

Options

StringArray

 

 

 

 

The pricing options group option code you configured that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

 

Renewal

Array of objects

 

 

Details below.

 

 

Amount

Int

 

 

 

The price of the product. Use -1 to delete it.

 

 

Currency

String

 

 

 

ISO code of the currency for the product price.

 

 

MinQuantity

Int

 

 

 

The minimum quantity of volume discounts. Default is 1.

 

 

MaxQuantity

Int

 

 

 

The maximum quantity of volume discounts. Default is 99999.

 

 

OptionCodes

Array of objects

 

 

 

Details below.

PriceOptions

Array of objects

 

Details below.

 

Code

String

 

 

System generated pricing options group code (you can also configure it) that the 2Checkout system uses to calculate product prices for pricing configurations without a base price.

 

Required

Boolean

 

 

true – you set the price options group as required during the purchase process.

false - you did not set the price options group as required during the purchase process.

 

Retrieve assigned price option groups

Overview

Use the getAssignedPriceOptionGroups method to extract information about the price option groups you assigned to one of your products.

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 editable code that you control at product-level, not the unique, system-generated product ID.

Response

Parameters Type/Description

PriceOptionGroup

Array of objects

Request

<?php

require ('PATH_TO_AUTH');
 
$ProductCode = 'YOUR_PRODUCT_CODE';
 
try {
    $AssignedPriceOptionGroups = $client->getAssignedPriceOptionGroups($sessionID, $ProductCode);
}

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

var_dump("AssignedPriceOptionGroups", $AssignedPriceOptionGroups);

?>

Upgrade a subscription

Overview

Retrieve information about the upgrade options for a specific subscription.

Parameters

Array of upgrade options

ProductInfo

Object

               

Details below.

 

ProductId

Int

 

 

Unique, system-generated product identifier belonging to the upgrade product.

 

ProductCode

String

 

 

Unique product identifier that you control belonging to the upgrade product.

 

ProductName

String

 

 

Product name

 

ProductVersion

String

 

 

The product version number that you control.

 

ProductEnabled

Boolean

 

 

Possible values:

0 – You disabled this product.

1 – You enabled this product.

 

ProductType

String

 

 

REGULAR or BUNDLE

 

Currency

String

 

 

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

 

DefaultCurrency

String

 

 

The product's default currency which is set in the Control Panel. The currency ISO code to be used for the payment - ISO 4217.

 

Price

Double

 

 

Product price. Can be null for flat pricing schemes. You need to call getPrice with Quantity, Currency and Price Options parameters to get a valid price.

 

GiftOption

String

 

 

True or false depending on whether the product can be gifted or not.

 

IdGroup

Int

 

 

Product Group ID number.

 

GroupName

String

 

 

The name of the Product Group.

 

ShortDescription

String

 

 

The product's short description.

 

ProductImage

String

 

 

URLs to the product images uploaded into the 2Checkout platform.

 

Languages

Array of strings

 

 

Array of ISO language codes for the product - ISO 639-1.

 

PriceIntervals

Array of objects

 

 

Pricing intervals.

 

PriceType

String

 

 

NET or GROSS

 

PriceSchema

String

 

 

FLAT or DYNAMIC

Quantity

Int

 

Number of units available for the upgrade order.

PriceOptions

Array of objects

 

Details below.

 

Id

String

 

 

Pricing options ID.

 

Name

String

 

 

Pricing options group name.

 

Description

String

 

 

The description of the Pricing options group

 

Required

Boolean

 

 

True or False depending on whether you set the Pricing options group asrequired or not.

 

Type

String

 

 

Pricing options group type:

  • COMBO
  • CHECKBOX
  • RADIO

INTERVAL

 

Options

Array of objects

 

 

Details below.

 

 

Name

String

 

 

 

The name of the option inside the Pricing options group

 

 

Value

String

 

 

 

The code of the option inside the Pricing options group

 

 

Default

Boolean

 

 

 

True or false.

 

 

Description

String

 

 

 

The description of the option inside the Pricing options group.

 

 

MinValue

Int

 

 

 

Start value of a scale interval.

 

 

MaxValue

Int

 

 

 

End value of a scale interval.

 

Create promotion

Overview

Use the addPromotion method via JSON-RPC API 4.0 to create a new promotion.

Parameters

Parameters

Type/Description

sessionID

Required (String)

 

Output of the Login method.

Promotion

Object

 

Name

Optional(String)

 

 

Promotion name

 

Description

Optional(String)

 

 

Promotion description

 

StartDate

Optional(String)

 

 

Starting date. The date when you set the promotion to start. Is NULL for promotions that start immediately after they're created.

Format: Y-m-d

 

EndDate

Optional(String)

 

 

Ending date. The date when you set the promotion to end. Is NULL for promotions that you want active indefinitely.

Format: Y-m-d

 

MaximumOrdersNumber

Optional(Int)

 

 

Avangate stops offering the discount when the promotion reaches the maximum number of orders. Can be NULL if you want the promotion to apply to an unlimited number of orders.

 

MaximumQuantity

Optional(Int)

 

 

Discount only applies to a specific number of products, smaller than the maximum quantity you defined. Can be NULL if you want the promotion to apply to an unlimited number of units. Any extra quantity added to the cart will be sold at full price.

 

InstantDiscount

Optional(Boolean)

 

 

Selecting the instant discount option will auto-apply the discount for ALL the selected products for all shoppers, without the need to enter the discount coupon.

Coupon

Optional(Object)

 

Type

Optional(String)

 

 

  • SINGLE = one coupon code shared by all shoppers
  • MULTIPLE = array of unique coupon codes, each designed for individual use

 

Code/Codes

Optional(String/Array)

 

 

Varies according to type. Send:

  • Code = 'single_code'; when Type = 'SINGLE';
  • Codes = ['code1', 'code2']; when Type = 'MULTIPLE';

Enabled

Optional(Boolean)

 

TRUE

FALSE

ChannelType

Optional(String)

 

Possible values:

  • ECOMMERCE
  • CHANNEL_MANAGER
  • ALL

Type

Optional(String)

 

REGULAR

Discount

Optional(Object)

 

Type

Optional(String)

 

 

Discount type:

  • PERCENT, use in combination with Value
  • FIXED, use in combination with Values and DefaultCurrency

 

Value / Values

Optional (Int / Array of objects)

 

 

  • Value = Int, determines the discount percentage from 0 to 100
  • Values = Array of Value objects

 

 

Value

Optional(Object)

 

 

 

Currency

Optional (String)

 

 

 

 

ISO currency code

 

 

 

Amount

Optional (Int)

 

 

 

 

Discount amount in corresponding currency.

 

DefaultCurrency

Optional(String)

 

 

ISO code

Products

Optional(Object)

 

Code

Optional(Int)

 

 

Unique product code that you control.

 

PricingConfigurationCode

Optional(String)

 

 

Unique system generated pricing configuration code.

 

PricingOptionCodes

Array of strings

 

 

Array of pricing option codes controlled by you.

PriceThreshold

Object

 

Limits discount use only when total order value (taxes included) exceeds the threshold you configure.

 

Amount

Decimal

 

 

The minimum threshold you defined for the default currency.

 

Currency

String

 

 

Currency code available for the default currency of custom threshold settings.

Translations

Optional(Array of objects)

 

PromotionTranslation

Optional(Object)

 

 

Name

Optional(String)

 

 

 

Localized name corresponding to translated language.

Name: Le product

Language: FR

 

 

Language

Optional(String)

 

 

 

 

Sources

StringArray

 

Array of strings defining the sale source through the SRC parameter.

PublishToAffiliatesNetwork

Optional(Int)

 

 

ApplyRecurring

Optional(String)

 

  • NONE
  • ALL
  • CUSTOM

RecurringChargesNumber

Optional(Int)

 

Offer discounts for a number of recurring billing charges beyond the initial purchase.

Response

Parameters Type/Description
Promotion Object

Request

<?php

function callRPC($Request, $host, $Debug = true) {
    $curl = curl_init($host);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSLVERSION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
    if ($Debug) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }
    if (!empty($ResponseString)) {
        var_dump($ResponseString);
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}

$host = 'https://api.avangate.com/rpc/3.1/';

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

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

$promotionObject = new stdClass;
$promotionObject->Name = 'YOUR_PROMOTION_TITLE';
$promotionObject->Description = 'YOUR_PROMOTION_DESCRIPTION';
$promotionObject->StartDate = date('Y-m-d', strtotime('1 month ago'));
$promotionObject->EndDate = date('Y-m-d', strtotime('+1 month'));
$promotionObject->Type = 'REGULAR';
$promotionObject->Enabled = 1;
$promotionObject->MaximumOrdersNumber = 0;
$promotionObject->MaximumQuantity = 0;
$promotionObject->InstantDiscount = false;
$promotionObject->ChannelType = 'ECOMMERCE';
$promotionObject->ApplyRecurring = 'NONE';
$promotionObject->RecurringChargesNumber = 3;
$promotionObject->PublishToAffiliatesNetwork = 0;
$promotionObject->InstantDiscount = 0;

$couponObject = new stdClass;
$couponObject->Type = 'SINGLE';
$couponObject->Code = 'single_code';
$promotionObject->Coupon = $couponObject;

$discountObj = new stdClass;
$discountObj->Type = 'PERCENT';
$discountObj->Value = 30;
$promotionObject->Discount = $discountObj;
$promotionObject->Products = [$productsObj1, $productsObj2, $productsObj3];
$promotionObject->Translations = [$translation1, $translation2];

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

$result = callRPC((object)$jsonRpcRequest, $host);
var_dump($result);

Use Credit cards

Overview

Use the placeOrder method to create an order using products defined in your Control Panel and collect the payment using credit card based payment methods.

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

For credit card orders placed using API 5.0, you need to pass through additional parameters that support the 3D Secure flow. 3D Secure works by redirecting customers to pages provided by their banks, where they need to enter additional security tokens or password to trigger the completion of the charge. By using 3D Secure, you get additional protection from liability for fraudulent card payments, with customers having to go through an extra layer of authentication. Send the following parameters in the placeOrder call:

Parameters Description
Vendor3DSReturnURL Required (string)
  URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.
Vendor3DSCancelURL Required (string)
  URL address to which customers are redirected if the 3DS details were not validated or the order could not be authorized.

Response

Parameters Type/Description

Order information

Object

  Object containing order information.

Request

<?php

require ('PATH_TO_AUTH');

$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->Affiliate = new stdClass();
$Order->Affiliate->AffiliateCode = 'Partner123'
$Order->Affiliate->AffiliateSource = 'MobilePlatform'
$Order->CustomerReference = NULL;

$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1;
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false;
$Order->Items[0]->AdditionalFields = NULL;
$Order->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.

$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'First';
$Order->BillingDetails->LastName = 'Last';
$Order->BillingDetails->CountryCode = 'us';
$Order->BillingDetails->State = 'California';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '90210';
$Order->BillingDetails->Email = 'email@address.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;

$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111";
$Order->PaymentDetails->PaymentMethod->CardType = 'visa';
$Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019';
$Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12';
$Order->PaymentDetails->PaymentMethod->CCID = '123';
$Order->PaymentDetails->PaymentMethod->HolderName = 'John';
$Order->PaymentDetails->PaymentMethod->CardNumberTime = 83.21; // can be null - high value in seconds is a red flag for fraud attempts.
$Order->PaymentDetails->PaymentMethod->HolderNameTime = 13.35; // can be null - high value in seconds is a red flag for fraud attempts.
$Order->PaymentDetails->PaymentMethod->Vendor3DSReturnURL = "http://www.success.ro";
$Order->PaymentDetails->PaymentMethod->Vendor3DSCancelURL = "http://www.error.ro"; 

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

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

Upgrade a subscription

Overview

Retrieve information about the upgrade options for a specific subscription.

Parameters

Array of upgrade options

ProductInfo

Object

               

Details below.

 

ProductId

Int

 

 

Unique, system-generated product identifier belonging to the upgrade product.

 

ProductCode

String

 

 

Unique product identifier that you control belonging to the upgrade product.

 

ProductName

String

 

 

Product name

 

ProductVersion

String

 

 

The product version number that you control.

 

ProductEnabled

Boolean

 

 

Possible values:

0 – You disabled this product.

1 – You enabled this product.

 

ProductType

String

 

 

REGULAR or BUNDLE

 

Currency

String

 

 

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

 

DefaultCurrency

String

 

 

The product's default currency which is set in the Control Panel. The currency ISO code to be used for the payment - ISO 4217.

 

Price

Double

 

 

Product price. Can be null for flat pricing schemes. You need to call getPrice with Quantity, Currency and Price Options parameters to get a valid price.

 

GiftOption

String

 

 

True or false depending on whether the product can be gifted or not.

 

IdGroup

Int

 

 

Product Group ID number.

 

GroupName

String

 

 

The name of the Product Group.

 

ShortDescription

String

 

 

The product's short description.

 

ProductImage

String

 

 

URLs to the product images uploaded into the 2Checkout platform.

 

Languages

Array of strings

 

 

Array of ISO language codes for the product - ISO 639-1.

 

PriceIntervals

Array of objects

 

 

Pricing intervals.

 

PriceType

String

 

 

NET or GROSS

 

PriceSchema

String

 

 

FLAT or DYNAMIC

Quantity

Int

 

Number of units available for the upgrade order.

PriceOptions

Array of objects

 

Details below.

 

Id

String

 

 

Pricing options ID.

 

Name

String

 

 

Pricing options group name.

 

Description

String

 

 

The description of the Pricing options group

 

Required

Boolean

 

 

True or False depending on whether you set the Pricing options group asrequired or not.

 

Type

String

 

 

Pricing options group type:

  • COMBO
  • CHECKBOX
  • RADIO

INTERVAL

 

Options

Array of objects

 

 

Details below.

 

 

Name

String

 

 

 

The name of the option inside the Pricing options group

 

 

Value

String

 

 

 

The code of the option inside the Pricing options group

 

 

Default

Boolean

 

 

 

True or false.

 

 

Description

String

 

 

 

The description of the option inside the Pricing options group.

 

 

MinValue

Int

 

 

 

Start value of a scale interval.

 

 

MaxValue

Int

 

 

 

End value of a scale interval.

 

3D Secure Flow

Overview

With the roll-out of Strong Customer Authentication regulation in Europe, the use of 3D Secure Authentication becomes mandatory for all payments made with Credit Cards. In order to integrate the 2Checkout API, 3DS 2.0 support needs to be implemented for both direct API orders made with credit card details as well as with 2pay tokens.

More information on the 3DS and PSD2 information can be found on our blog.

Availability

Available for all 2Checkout accounts.

3DS Secure Flow

Additional parameters are required in order to support the 3D Secure flow and this works by redirecting customers to pages provided by their banks, where they need to enter additional security tokens or passwords to trigger the completion of the charge. By using 3D Secure, you get additional protection from liability for fraudulent card payments, with shoppers having to go through an extra layer of authentication.

Diagram #1 3ds flow.png

These are the required steps for the 3DS flow:

1. The shopper fills in the payment details and places an order.

2. The merchant processes the order.

The merchant receives the shopper's data from the checkout page and triggers an order to 2Checkout with their information, including credit card data: cardholder name, credit card number, expiration date, and CVV are the mandatory fields.

Additionally, the merchant needs to provide two mandatory parameters in the PaymentMethod object: 

  • Vendor3DSReturnURL: the URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.
  • Vendor3DSCancelURL: the URL address to which customers are redirected if the 3DS details were not validated or the order could not be authorized.

3. 2Checkout processes the order from the merchant. The 2Checkout API will respond to the placeOrder API call with the order information or an error message.

4. The merchant processes the 2Checkout response.

Since 3DS is not always mandatory, how do we know when we are not on the 3DS flow?

If the order in the response is in Status AUTHRECEIVED or COMPLETE and PaymentDetails node looks like this, then the order does not require 3DS authorization.

{
  "Type": "CC",
  "Currency": "usd",
  "PaymentMethod": {
    "FirstDigits": "4111",
    "LastDigits": "1111",
    "CardType": "visa",
    "RecurringEnabled": false,
    "Vendor3DSReturnURL": null,
    "Vendor3DSCancelURL": null,
    "InstallmentsNumber": null
  },
  "CustomerIP": "10.11.12.1"
}

For 2pay tokens, the request is similar, as the credit card details are replaced by the encrypted token.

After this response, the shopper is redirected to the Finish page.

If the order in the response is in Status PENDING and the PaymentDetails node contains the Authorize3DS node, it'll look like this:

{
  "Type": "CC",
  "Currency": "usd",
  "PaymentMethod": {
    "Authorize3DS": {
      "Href": "http://api.sandbox63.avangate.local/6.0/scripts/credit_card/authorize",
      "Method": "GET",
      "Params": {
        "avng8apitoken": "50dcb997be8b70bd"
      }
    },
    "Vendor3DSReturnURL": "http://shopping.cart.local/checkout/external/return/cc",
    "Vendor3DSCancelURL": "http://shopping.cart.local/checkout/external/cancel/cc",
    "FirstDigits": "4111",
    "LastDigits": "1111",
    "CardType": "Visa",
    "RecurringEnabled": false
  },
  "CustomerIP": "10.11.12.1"

5. The merchant redirects the shopper to the 3DS page.

The actual authorization is not done yet, but it will be completed after redirecting the shopper to the Authorize3DS URL where they enter the 3DS code. 

Example of URL (composed from Authorize3DS['href'] and Authorize3DS['Params']):

http://api.sandbox63.avangate.local/6.0/scripts/credit_card/authorize?avng8apitoken=50dcb997be8b70bd

6. The shopper authenticates the payment.

The shopper reaches the bank's 3D Secure page, where they must complete the authentication flow by use of a one-time password (OTP) sent to their mobile phones by the issuing bank, or by use of a personal PIN.

7. The issuing bank processes the authentication request.

Based on the status of the authentication flow, the shopper is redirected back to the merchant's site, to the URL for either the success (Vendor3DSReturnURL) or the failed flow (Vendor3DSCancelURL). 

8. The merchant handles the 3DS flow result.

The shopper is redirected to the appropriate page, where the merchant needs to handle that specific case.

Integration test cases

Using the test credit cards available here, follow the next steps:

  1. Build a request in order to place a new order, with all the relevant information. Make sure that when the order is sent in the API, the response contains an order object (order was placed successfully).
  2. Handle the 3DS flows, both when 3DS is mandatory (and the shopper needs to be redirected to authorize the transaction), as well as where this is not needed (order is created with status AUTHRECEIVED or COMPLETE).
  3. If you have any additional webhook integrations, make sure that the webhooks are correctly configured and that the notifications are received and processed successfully. 

Order session contents

Overview

Retrieve the current cart session content, and learn insights about your customers' actions in cart.

You can obtain the VAT or sales TAX based on current cart items, prefill the customer information based on the subscription reference, or get the price applied in the cart by using the API method from below.

 

How to use the signature with the Inline Checkout

Overview

Some of the Inline Checkout parameters require a signature to prevent any interference in the ordering process. Optional parameters also require a signature if they are included in the Inline Checkout. You can read here which parameters require a signature.

Demo Sample

In order to attach the signature of signed parameters to the TwoCoInlineCart library, use the setSignature() method.

TwoCoInlineCart.setup.setMerchant('MERCHANT_CODE');
...
TwoCoInlineCart.cart.setSignature('<signature>');
...
TwoCoInlineCart.cart.checkout();

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