Skip to main content

Order session content object

Overview

Use this object to retrieve session content and to guide shoppers through advanced payment flows, such as those of PayPal, PayPal Express, Wire, Check, etc. 

Attributes

Order session  contents

Type/Description

Errors

Optional (StringArray)

 

Payment gateway processing errors.

Items

Array of objects

    Details below. 

 

ProductDetails

Object

      Details below. 

 

 

Name

Optional (string)

 

 

 

Product name.

 

 

ExtraInfo

Optional (string)

 

 

 

The text entered in the Additional information field when generating Buy links, or via the INFO[PRODUCT_ID] parameter used in Buy links.

 

 

RenewalStatus

Optional (boolean)

 

 

 

  • true for orders renewing subscriptions.
  • false for all other orders: new purchases, upgrades.

 

 

Subscriptions

Object

        Details below. 

 

 

 

SubscriptionReference

Optional (string)

 

 

 

 

Unique, system-generated subscription identifier.

 

 

 

PurchaseDate

Optional (string)

 

 

 

 

The date time stamp when shoppers acquired their subscriptions corresponding to the moment when the Avangate system marks the purchase as finished. Format (YYYY-MM-DD HH:mm:ss). Default GMT+02:00.

 

e.g. 2015-08-11 15:18:52

 

 

 

SubscriptionStartDate

Optional (string)

 

 

 

 

 

Example: 2015-09-29 17:57:59

 

 

 

ExpirationDate

Optional (string)

 

 

 

 

The date time stamp of upcoming renewal/expiration for subscriptions not taking into account grace period settings.

 

Format (YYYY-MM-DD HH:mm:ss). Default GMT+02:00.

 

e.g. 2015-09-11 15:18:52

 

 

 

Lifetime

Optional (boolean)

 

 

 

 

  • true – For non-recurring, evergreen subscriptions.
  • false – For recurring subscriptions with a specific billing cycle from 7 days to 36 months.

 

 

 

Trial

Optional (boolean)

 

 

 

 

  • true – For trial subscriptions.
  • false – For non-trial, recurring subscriptions with a specific billing cycle from 7 days to 36 months.

 

 

 

Enabled

Optional (boolean)

 

 

 

 

  • true – For active and past due subscriptions.
  • false – For expired and cancelled subscriptions.

 

 

 

RecurringEnabled

Optional (boolean)

 

 

 

 

 

                    

PriceOptions

Optional (Array of strings)

 

 

Product price options.

 

Price

Object

 

 

This object returns the price per unit at order line level.

 

In the case of trials, the object returns the costs for the trial to full subscription conversion.

 

 

UnitNetPrice

Optional (double)

 

 

 

The value per product unit, excluding sales tax/VAT expressed in the payment currency.

 

 

UnitGrossPrice

Optional (double)

 

 

 

Total value per product unit, including sales tax/VAT expressed in the payment currency. UnitGrossPrice does not reflect any discounts.

 

 

UnitVAT

Optional (double)

 

 

 

Sales tax/VAT per product unit expressed in the payment currency.

 

 

UnitDiscount

Optional (double)

 

 

 

Value of the discount per product unit expressed in the payment currency.

 

 

UnitNetDiscountedPrice

Optional (double)

 

 

 

The value per product unit, expressed in the payment currency, excluding sales tax/VAT, from which Avangate deducts the unit discount.

 

 

UnitGrossDiscountedPrice

Optional (double)

 

 

 

Total costs shoppers incur per product unit, expressed in the payment currency. This value includes sales tax/VAT, Avangate and affiliate commissions, but Avangate deducts the value of any discounts.

 

 

UnitAffiliateCommission

Optional (double)

 

 

 

Value of the affiliate commission per product unit calculated expressed in the payment currency.

 

Avangate deducts discounts from the costs incurred by shoppers before calculating affiliate commissions.

 

Avangate does not take into account shipping costs when calculating affiliate commissions.

 

NULL when Avangate does not apply an affiliate commission.

 

 

Currency

Optional (string)

 

 

 

The currency ISO code for the payment - ISO 4217. Example: usd.

 

 

NetPrice

Optional (double)

 

 

 

The value per order line, excluding sales tax/VAT expressed in the payment currency.

 

 

GrossPrice

Optional (double)

 

 

 

Total value per order line, including sales tax/VAT expressed in the payment currency. UnitGrossPrice does not reflect any discounts.

 

 

NetDiscountedPrice

Optional (double)

 

 

 

The NetPrice value per order line, excluding sales tax/VAT, from which Avangate deducts discounts. NetDiscountedPrice is expressed in the payment currency.

 

 

GrossDiscountedPrice

Optional (double)

 

 

 

Total costs shoppers incur per order line, expressed in the payment currency. This value includes sales tax/VAT, Avangate and affiliate commissions, but Avangate deducts the value of any discounts.

 

Example:

  • UnitNetPrice: 99
  • UnitGrossPrice: 120.39
  • UnitVAT: 21.39
  • UnitDiscount: 9.9
  • UnitNetDiscountedPrice: 89.1
  • UnitGrossDiscountedPrice: 110.49
  • UnitAffiliateCommission: 22.28
  • Currency: "usd"
  • NetPrice: 198
  • GrossPrice: 240.77
  • NetDiscountedPrice: 178.2
  • GrossDiscountedPrice: 220.97
  • Discount: 19.8
  • VAT: 42.77
  • AffiliateCommission: 44.56

 

 

Discount

Optional (double)

 

 

 

Value of the discounts per order line expressed in the payment currency.

 

 

VAT

Optional (double)

 

 

 

Value of sales tax/VAT per order line expressed in the payment currency.

 

 

AffiliateCommission

Optional (double)

 

 

 

Value of the affiliate commission per order line, calculated from the NetDiscountedPrice expressed in the payment currency. Or NULL. Avangate does not take into account shipping costs when calculating affiliate commissions.

 

Code

Optional (string)

 

 

Unique product identifier your control. Max length 256 characters.

 

Quantity

Optional (integer)

 

 

Number of units

 

SKU

Optional (string)

 

 

SKU identifier.

 

CrossSell

Optional (Object)

      Details below. 

 

 

ParentCode

Optional (string)

 

 

 

The product code of the master product you set to trigger the campaign.

 

 

CampaignCode

Optional (string)

 

 

 

Unique, system-generated identifier for cross-sell campaigns.

 

Trial

Optional (Object)

      Details below. 

 

 

Period

Optional (integer)

 

 

 

The length of the trial subscription lifetime in days.

 

 

GrossPrice

Optional (double)

 

 

 

Total trial price in the payment currency before Avangate deducts any taxes, discounts, etc.

 

 

VAT

Optional (double)

 

 

 

The total value of taxes for the trial in the payment currency, before Avangate deducts any discounts.

 

 

NetPrice

Optional (double)

 

 

 

Total trial price in the payment currency, not including taxes, before Avangate deducts any discounts.

 

AdditionalFields

Optional (array of objects)

      Details below. 

 

 

Code

Optional (string)

 

 

 

The alpha-numeric characters, underscores and dashes that are set as the field identifier.

 

 

Text

Optional (string)

 

 

 

Field text visible to shoppers in the cart.

 

 

Value

Optional (string)

 

 

 

Selected field value.

 

Promotion

Optional (object)

      Details below. 

 

 

Name

Optional (string)

 

 

 

Promotion name.

 

 

Description

Optional (string)

 

 

 

Promotion description.

 

 

StartDate

Optional (string)

 

 

 

The date when you set the promotion to start. NULL for promotions that start immediately after you create them.

 

 

EndDate

Optional (string)

 

 

 

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

 

 

MaximumOrdersNumber

Optional (integer)

 

 

 

Avangate only applies the promotion to a maximum number of orders you define.

 

Can be NULL if you want the promotion to apply to an unlimited number of orders.

 

 

MaximumQuantity

Optional (integer)

 

 

 

Discount only applies to a maximum number of units purchased through a single order, smaller than the quantity you defined. Shoppers purchase any extra units at full price. Can be NULL if you want the promotion to apply to an unlimited number units.

 

 

InstantDiscount

Optional (boolean)

 

 

 

The instant discount option auto-applies the discount for ALL selected products, without the need for shoppers to enter a discount coupon.

 

 

Coupon

Optional (string)

 

 

 

Promotion coupon/voucher.

 

 

DiscountLabel

Optional (string)

 

 

 

Discounts can be set as a percentage from the product price or as a fixed amount in the chosen currency.

 

 

Enabled

Optional (string)

 

 

 

true or false, depending on whether a promotion is active or disabled. 

 

 

Type

Optional (string)

 

 

 

  • REGULAR – product/cart line level discounts.
  • ORDER – quantity discounts.
  • GLOBAL – order-level discounts.

Promotions

Optional (Array of objects)

    Details below. 

 

Name

Optional (string)

 

 

Promotion name.

 

Description

Optional (string)

 

 

Promotion description.

 

StartDate

Optional (string)

 

 

The date when you set the promotion to start. NULL for promotions that start immediately after you create them.

 

EndDate

Optional (string)

 

 

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

 

MaximumOrdersNumber

Optional (integer)

 

 

Avangate only applies the promotion to a maximum number of orders you define.

 

Can be NULL if you want the promotion to apply to an unlimited number of orders.

 

MaximumQuantity

Optional (integer)

 

 

Discount only applies to a specific number of units purchased at once, smaller than the maximum quantity you defined. Shoppers purchase any extra units at full price. Can be NULL if you want the promotion to apply to an unlimited number units.

 

InstantDiscount

Optional (boolean)

 

 

The instant discount option auto-applies the discount for ALL selected products, without the need for shoppers to enter a discount coupon.

 

Coupon

Optional (string)

 

 

Promotion coupon/voucher.

 

DiscountLabel

Optional (string)

 

 

Discounts can be set as a percentage from the product price or as a fixed amount in the payment currency.

 

Enabled

Optional (string)

 

 

true or false, depending on whether a promotion is active or disabled. 

 

Type

Optional (string)

 

 

  • REGULAR – product/cart line level discounts.
  • ORDER – quantity discounts.
  • GLOBAL – order-level discounts.

AdditionalFields

Optional (array of objects)

    Details below. 

 

Code

Optional (string)

 

 

The alpha-numeric characters, underscores and dashes that are set as the field identifier.

 

Text

Optional (string)

 

 

Field text visible to shoppers in the cart.

 

Value

Optional (string)

 

 

Selected field value.

Currency

Optional (string)

 

The currency ISO code for the payment - ISO 4217. Example: usd.

NetPrice

Optional (double)

 

Order value excluding sales tax/VAT expressed in the payment currency.

GrossPrice

Optional (double)

 

Total order value, including sales tax/VAT expressed in the payment currency. GrossPrice does not reflect any discounts.

NetDiscountedPrice

Optional (double)

 

The NetPrice order value excluding sales tax/VAT, from which Avangate deducts discounts. NetDiscountedPrice is expressed in the payment currency.

GrossDiscountedPrice

Optional (double)

 

Total costs shoppers incur, expressed in the payment currency. This value includes sales tax/VAT, Avangate and affiliate commissions, but Avangate deducts the value of any discounts.

 

For example:

  • Currency: "usd"
  • NetPrice: 396
  • GrossPrice: 486.29
  • NetDiscountedPrice: 376.2
  • GrossDiscountedPrice: 466.49
  • Discount: 19.8
  • VAT: 90.29
  • AffiliateCommission: 94.05

Discount

Optional (double)

 

Value of the discounts for an order expressed in the payment currency.

VAT

Optional (double)

 

Value of sales tax/VAT expressed in the payment currency.

AffiliateCommission

Optional (double)

 

Value of the affiliate commission for the order calculated from the NetDiscountedPrice expressed in the payment currency. Or NULL. Avangate does not take into account shipping costs when calculating affiliate commissions.

 

Update price options

Overview

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

  • Price options intervals cannot overlap. 

Parameters

Parameters Type/Description

sessionID

Required (string)

 

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

PriceOptionsGroup

Required (object)

 

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

 

You cannot update the

  • Code of the price options group. 

Response

bool(true)

Request

<?php
 
function callRPC($Request, $hostUrl, $Debug = true) {
    $curl = curl_init($hostUrl);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSLVERSION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
 
    if ($Debug) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }
 
    if (!empty($ResponseString)) {
//        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.0/';
 
$merchantCode = "YOURCODE12345";//your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "SECRET_KEY";//your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
 
$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);
 
$i = 1; // counter for api calls
 
// Call the login method for authentication
 
$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);
 
$SearchOptions = new stdClass ();
$SearchOptions->Name = 'New Users from API';
 
$SearchOptions->Types = array('INTERVAL', 'RADIO'); //RADIO, CHECKBOX, INTERVAL, COMBO, INTERVAL
 
$SearchOptions->Limit = 10;
$SearchOptions->Page = 1;
 
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'searchPriceOptionGroups',
'params' => array($sessionID, $SearchOptions)
);
 
$existentPriceOptions = callRPC((Object)$jsonRpcRequest, $host, true);
var_dump ($existentPriceOptions);
 
$updatedPriceOptions = $existentPriceOptions[0];
 
$existentPriceOptions[0]->Translations[0]->Name = 'New Users from API3';
$existentPriceOptions[0]->Translations[0]->Language = 'EN';
 
$updatedPriceOptions = $existentPriceOptions[0];
echo "$updatedPriceOptions->Name";
 
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'updatePriceOptionGroup',
'params' => array($sessionID, $updatedPriceOptions)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
 
 
?>

Add translations

Overview

Use the addPromotionTranslations method to add localized texts to existing promotions.

Parameters

Parameter Type/Description

sessionID

Required (string)

 

Output of the Login method.

promotionCode

Required (string)

 

The code corresponding to the promotion that you want to add translations to.

promotions

Required (array of PromotionTranslations objects)

PromotionTranslations  Object

 

language

Required (string)

 

 

ISO country code corresponding to the country you want to set the translation for.

 

name

Required (string)

 

 

Localized promotion name is applicable to the selected country.

Response

Parameters Type/Description

promotionTranslation

Object

Request

<?php

require ('PATH_TO_AUTH');

// Promotion code corresponding to the promotion you want to add translations to
$promotionCode = '';

// Defining a translation for German shoppers
$promotionTranslation1 = new stdClass;
$promotionTranslation1->Language = 'de'; 
$promotionTranslation1->Name = 'YOUR_GERMAN_PROMOTION_NAME';

// Defining a translation for Bulgarian shoppers
$promotionTranslation2 = new stdClass;
$promotionTranslation2->Language = 'bg'; 
$promotionTranslation2->Name = 'YOUR_BULGARIAN_PROMOTION_NAME';

$translations = [$promotionTranslation1, $promotionTranslation2];

try {
    $updatedPromotion = $client->addPromotionTranslations($promotionCode, $translations);
}

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

var_dump("UpdatedPromotion", $updatedPromotion);

 

Create a new customer

Overview

Use the createCustomer method to add the details of a customer entity into the Avangate system. By default, customer status is Inactive until you assign a specific subscription to the customer. Following that action, customer status reflects the status of the attached subscription(s).

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.

Customer

Object

Request

<?php

require ('PATH_TO_AUTH');

$newCustomer = new stdClass();
$newCustomer->AvangateCustomerReference = null;
$newCustomer->ExternalCustomerReference = 'ThisIsATestReference123456';
$newCustomer->FirstName = 'NewCustomer';
$newCustomer->LastName = 'NewCustomerLastName';
$newCustomer->Company = null;
$newCustomer->FiscalCode = null;
$newCustomer->Address1 = 'Address';
$newCustomer->Address2 = null;
$newCustomer->City = 'LA';
$newCustomer->Zip = '90210';
$newCustomer->CountryCode = 'us';
$newCustomer->Phone = null;
$newCustomer->Fax = null;
$newCustomer->Email = 'newcustomer@email.com';
$newCustomer->ExistingCards = null;
$newCustomer->Enabled = null;
$newCustomer->Trial = null;
$newCustomer->Language = 'en';

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

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

Response

Parameters Type/Description

AvangateCustomerReference

Int

 

System-generated customer reference.

Update a customer

Overview

Use the updateCustomerInformation method to update the details of a customer entity from the Avangate system.

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.

Customer

Object

Response

Boolean

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

Request


<?php
 
 
function callRPC($Request, $hostUrl, $Debug = true) {
    $curl = curl_init($hostUrl);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSLVERSION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
 
 
    if ($Debug) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }
 
    if (!empty($ResponseString)) {
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}
 
$host = 'https://api.avangate.com/rpc/3.0/';
 
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
 
$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);
 
$i = 1; // counter for api calls
// call login
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;
 
$sessionID = callRPC($jsonRpcRequest, $host);
 
var_dump($sessionID);
$customerReference = 298084139;
$externalCustomerReference = 'Apitest123456'; //Optional, but if you include it it needs to belong to the same customer as the internal Avangate customer reference
$jsonRpcRequest = array (
'method' => 'getCustomerInformation',
'params' => array($sessionID, $customerReference, $externalCustomerReference),
'id' => $i++,
'jsonrpc' => '2.0');
$existingCustomer = callRPC((Object)$jsonRpcRequest, $host, true);
$existingCustomer->Email = 'newemailaddress@email.com';

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

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

Update a promotion

Overview

Use the updatePromotion method via SOAP API 4.0 to alter the details of an existing promotion.

Parameters

Parameter Type/Description
sessionID Required (string)
  Output of the Login method.
promotion Required (object)
  Promotion object that you want to update.

Response

Parameter Type/Description
promotion Updated promotion object.

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.2checkout.com/soap/3.1/');
Client::setCredentials('YOUR_MERCHANT_CODE', 'YOUR_SECRET_KEY');
Client::login();

// Retrieve promotion details
$promotionCode = 'PROMOTION_CODE'; // code of the promotion that you want to update
$existingPromotion = Client::getPromotion($promotionCode); // Keep the promotion you want to update in $existingPromotion

// Set the fields to update
$existingPromotion->Name = 'YOUR_UPDATED_NAME';

// Update the promotion
$response = Client::updatePromotion($existingPromotion);
var_dump($response);

 

Place an order

Overview

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

Supported payment methods

  1. Credit/Debit cards: Visa, Visaelectron, MasterCard, Maestro, Amex, Discover, Dankort, Cartebleue, JCB. 2Checkout supports local Brazilian cards.
  2. PayPal and PayPal Express
  3. Puchase Order
  4. Wire
  5. Check
  6. Previous order references - In addition to the payment methods enumerated above, 2Checkout also supports 1-click purchase flows in which you use valid previous order references belonging to returning customers to pay for new orders with their previously used cards and PayPal accounts. 

For anti-fraud purposes, 2Checkout limits the number of successive purchases made using the same credit card.

Requirements

As reseller of your products, 2Checkout must validate your compliance with the PCI requirements, making sure you meet Payment Card Industry (PCI) standards when using the New Purchase 2Checkout API. You alone control the level of complexity of your PCI compliance. 

Details on some of the most frequent PCI compliance levels for ecommerce businesses and the associated steps you need to follow to obtain the compliance and be able to start using the New Purchase 2Checkout API are available here: New Purchase Avangate API PCI DSS Requirements.

You're required to include the following text when using 2Checkout API-client side encryption and to make it visible for your customers in the ordering interface. 

 

Order processed by 2Checkout, authorized reseller and merchant of the products and services offered within this store. 

Currency support

Check with 2Checkout support for a list of currencies available for each payment method. 

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.

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

Response

Order information

Object

Request


<?php
 
//The following script let's you place an new order with Credit/Debit cards as the payment method
 
$host   = "https://api.2Checkout.com";
$client = new SoapClient($host . "/soap/3.0/?wsdl", array(
    'location' => $host . "/soap/3.0/",
    "stream_context" => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    ))
));
function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}
$merchantCode = "YOUR_MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel.
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel.
$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;
}
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'US';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->AffiliateId = NULL;
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1; 
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false; 
$Order->Items[0]->AdditionalFields = NULL;

$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'FirstName';
$Order->BillingDetails->LastName = 'LastName';
$Order->BillingDetails->CountryCode = 'us';
$Order->BillingDetails->State = 'California';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '90210';
$Order->BillingDetails->Email = 'customer@email.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'TEST';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->CardNumber = "4111111111111111";
$Order->PaymentDetails->PaymentMethod->CardType = 'visa';
$Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019';
$Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12';
$Order->PaymentDetails->PaymentMethod->HolderName = 'John';
$Order->PaymentDetails->PaymentMethod->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->CCID = '123';
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;
try {
    $newOrder = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
    echo "newOrder: " . $e->getMessage();
    exit;
}
var_dump("newOrder", $newOrder);
?>

 

One click (1-click) purchase

Overview

Avangate supports 1-click purchases for returning customers who paid for their previous orders with:

  • Credit/Debit cards
  • PayPal

How does this work?

  1. Identify returning customers. 
  2. Access data on the previous purchases of returning customers.
  3. Validate previous order references for 1-click purchase scenarios using the isValidOrderReferencemethod.
  4. Place a new order using a valid previous order reference as the payment method. 
  5. Avangate charges returning customers using their payment-on-file information, either a card or their PayPal account. 

Availability

Select Avangate accounts. Contact Avangate for more details. 

Requirements

  • Use only references of previous orders  with one of the following statuses AUTHRECEIVED or COMPLETE.
  • The email address of the BillingDetails object is mandatory and it needs to match the email address used as a part of the billing details of the initial order whose reference you're now using to place a new order. Avangate checks whether the email addresses are identical, and throws an error if they're not, blocking the order placement process. Note: You need to provide only the email address of the shopper, and can ignore the rest of the required customer billing information. If you enter any billing details in addition to the email address, you'll have to provide all information required in the BillingDetails object.

Parameters

Parameters

Type/Description

sessionID

Required (string)

 

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

Order

Required (Object)

 

Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details.

Response

Order information

Object

Request


<?php
echo "<pre>";
function callRPC($Request, $hostUrl, $Debug = true) {
    $curl = curl_init($hostUrl);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSLVERSION, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
    $RequestString = json_encode($Request);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $RequestString);
 
 
    if ($Debug) {
        $RequestString;
    }
    $ResponseString = curl_exec($curl);
    if ($Debug) {
        $ResponseString;
    }
 
    if (!empty($ResponseString)) {
        $Response = json_decode($ResponseString);
        if (isset($Response->result)) {
            return $Response->result;
        }
        if (!is_null($Response->error)) {
            var_dump($Request->method, $Response->error);
        }
    } else {
        return null;
    }
}
 
$host = 'https://api.avangate.com/rpc/3.0/';
 
$merchantCode = "MERCHANT_CODE";// your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key = "SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
 
$string = strlen($merchantCode) . $merchantCode . strlen(date('Y-m-d H:i:s')) . date('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);
 
$i = 1; // counter for api calls
// call login
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, date('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;
 
$sessionID = callRPC($jsonRpcRequest, $host);
 
var_dump($sessionID);
$orderReference = '45452071';
$jsonRpcRequest = array (
'method' => 'isValidOrderReference',
'params' => array($sessionID, $orderReference),
'id' => $i++,
'jsonrpc' => '2.0'
);
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
$jsonRpcRequest = array (
'method' => 'getOrder',
'params' => array($sessionID, $orderReference),
'id' => $i++,
'jsonrpc' => '2.0'
);
$oldOrderExistent = callRPC((Object)$jsonRpcRequest, $host, true);
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'US';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->AffiliateId = NULL;
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1; 
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false; 
$Order->Items[0]->AdditionalFields = NULL;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->Email = $oldOrderExistent->BillingDetails->Email;;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'PREVIOUS_ORDER';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->RecurringEnabled = true;
$Order->PaymentDetails->PaymentMethod->RefNo = $orderReference;
$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));

 

Update promotion

Overview

Use the updatePromotion method to alter the details of an existing promotion.

Parameters

Parameter Type/Description
sessionID Required (string)
  Output of the Login method.
Promotion Required (object)
  Promotion object that you want to update.

Response

Parameter Type/Description
Promotion Updated promotion object.

Request

<?php
require ('PATH_TO_AUTH'); 

// Retrieve promotion details

$promotionCode = 'PROMOTION_CODE'; // code of the promotion that you want to update

try {
    $Discount = $client->getPromotion($sessionID, $promotionCode);
}
catch (SoapFault $e) {
    echo "Discount: " . $e->getMessage();
    exit;
}

var_dump("Discount", $Discount);

// Keep the promotion you want to update in $existingPromotion
try{
    $existingPromotion = $client->getPromotion($sessionID, $promotionCode);
}

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

// Set the fields to update 
$existingPromotion->Description = 'Updated description';

// Update the promotion
try {
    $updatedPromotion = $client->updatePromotion($sessionID, $existingPromotion);
}

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

var_dump("UpdatedPromotion", $updatedPromotion);

?>

 

Add promotion sources

Overview

Use the addPromotionSources method via JSON-RPC API 4.0 to define new sources for an existing promotion.

Parameters

Parameter Type/Description

sessionID

Required (string)

 

Output of the Login method.

promotionCode

Required (string)

 

The code corresponding to the promotion that you want to add products to.

promotionSources

Required (string array)

 

Array of strings defining the promotion sources.

Response

Parameter Type/Description

promotionSources

String array

 

Array of strings defining the promotion sources.

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

// Promotion code corresponding to the promotion you want to add sources to
$promotionCode = '';

// Sources array with the source values 
$sources = ['source1', 'source2'];

$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addPromotionSources',
'params' => array($sessionID, $promotionCode, $sources)
);
var_dump (callRPC($jsonRpcRequest, $host));

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