Skip to main content

Place orders with cross-selling campaigns

Overview

Cross-selling allows you to recommend additional products to customers and increase the average order value. The 2Checkout Public API supports classic cross-sell campaigns which means you can recommend more products from your own product catalog to your shoppers.

CrossSell Object for the placeOrder API method

Use the CrossSell object below to recommend additional products to customers via JSON-RPC API 6.0.

Parameter name Type Required/Optional Description
ParentCode String Required Product code of the product to be recommended to the shopper.
CampaignCode String Required The upsell campaign code.

Request Example

{ 
  "Currency": "USD", 
  "Language": "EN", 
  "Country": "US", 
  "CustomerIP": "10.10.10.10", 
  "Source": "sourceAPI.net", 
  "CustomerReference": 421820775, 
  "Items": [ 

    { 
      "Code": "15", 
      "Quantity": 1 
    }, 
    { 
      "Code": "34924C876E", 
      "Quantity": 1, 
      "CrossSell":{ 
        "ParentCode" : "15", 
        "CampaignCode" : "2Xrl83KSkemCv3G3dL%2B9eA%3D%3D" 
      } 
    } 
  ], 

   "BillingDetails":{ 

      "FirstName":"Customer First Name", 
      "LastName":"Customer Last Name", 
      "CountryCode":"US", 
      "State":"California", 
      "City":"San Francisco", 
      "Address1":"Example Street", 
      "Zip":"90210", 
      "Email":"example@email.com" 

   }, 

  "PaymentDetails": { 
    "Type": "CC", 
    "Currency": "USD", 
    "CustomerIP": "10.10.10.10", 
    "PaymentMethod": { 

      "Vendor3DSReturnURL": "https:\/\/example.com", 
      "Vendor3DSCancelURL": "https:\/\/example.com", 
      "CardNumber": "4111111111111111", 
      "CardType": "VISA", 
      "ExpirationYear": "2020", 
      "ExpirationMonth": "12", 
      "CCID": "123", 
    } 
  } 
} 

Response

Using the same structure, the getContents method will take into account the discount associated with the cross-sell campaign and display the appropriate prices and taxes.

{ 
    "Country": "DE", 
    "Currency": "EUR", 
    "Items": [ 
        { 
            "Code": "NIQRPI0GTU", 
            "Quantity": 1 
        }, 

        { 
            "Code": "0XICS3OVDK", 
            "Quantity": 1, 

"CrossSell":{ 
        "ParentCode" : " NIQRPI0GTU ", 
        "CampaignCode" : "2Xrl83KSkemCv3G3dL%2B9eA%3D%3D" 
      } 

        } 
    ], 

    "BillingDetails": { 
        "FirstName": "Customer First Name", 
        "LastName": "Customer Last Name", 
        "CountryCode": "DE", 
        "City": "Bucharest", 
        "Address1": "Example Street", 
        "Zip": "73331", 
        "Email": "example@email.com" 
    } 
} 

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. Avangate 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, Avangate 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 antifraud purposes, Avangate limits the number of successive purchases made using the same credit card.

Requirements

As reseller of your products, Avangate must validate your compliance with the PCI requirements, making sure you meet Payment Card Industry (PCI) standards when using the New Purchase Avangate 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 Avangate API are available here: New Purchase Avangate API PCI DSS Requirements.

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

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

Currency support

Check with Avangate 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. 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
 
//The following script let's you place an new order with Credit/Debit cards as the payment method
 
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.
$key = "YOUR_SECRET_KEY";// your account's secret key available in the 'System settings' area of the cPanel.
 
$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);
$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->Items[0]->SubscriptionStartDate = NULL; //If empty or null, subscriptions become active when purchase is made.
$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 = 'email@avangate.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->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;

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

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

Set up subscription upgrades

Overview

Make sure that your customers use the latest iteration of your products, and that they're able to upgrade to newer versions. The 2Checkout upgrade functionality supports scenarios such as switching to a different subscription plan or to another version of the same product.

Requirements

  • The upgrade product has the renewal/recurring billing system enabled (subscriptions are generated): the upgradable products also need to have the renewal/recurring billing system switched on.
  • The upgrade product doesn't use subscriptions (the renewal/recurring billing system is not enabled): all products are valid upgrade options, whether subscriptions are generated for them or not.

Upgrade scenarios

A different product Product A to Product B
A different version of the current product Product A v1 to Product A v2
A different subscription plan Product A 1 user to Product A 3 users
An upgraded product

Product A to Product B

and

Product A to Product C

(set up upgrades for one product to multiple products with different upgrade set-ups)

Set a product upgrade

  1. Select the products that are eligible.
  2. Set the pricing scheme and customize it.
  3. Set the subscription details for the upgrade.

Step 1: Configure upgrade products

Upgrades can be set up by configuring the Upgrade product.

  1. Navigate to Products, under Setup, and run a search to identify the upgraded product. Click to edit it, and then select the Upgrade tab.
  2. Choose the upgradable products from the list in the Edit your upgrade options area. Multiple selections are possible when holding down the CTRL key.

You can configure multiple products to upgrade to the same offering. 

The Available products area lists only items with subscriptions as valid options for upgrade products with subscriptions.

Step 2: Choose the pricing scheme

Choose the pricing scheme that you want to apply for the upgrade.

Pricing

In addition to defining the pricing strategy for the original and the upgrade products, the 2Checkout upgrade area offers additional controls impacting the costs customers incur during the upgrade process. Shoppers can pay:

  • Option 1. The full upgrade product price.
  • Option 2. The difference between the original subscription and the upgraded product.
  • Option 3. A prorated upgrade price calculated using the most recent costs incurred by the customer (Upgrade costs can differ from product price as they reflect the most recent transaction made for the subscription and reflect the impact of discounts offered, custom charges, on-the-fly pricing, etc.).
  • Option 4. A prorated upgrade price calculated using the product's pricing set-up at the time of the order (Upgrade costs are not impacted by previous discounts, custom charges, personalized pricing, etc.).

You can also customize the upgrade price by adding or subtracting a specific percent.

Prorated upgrade price

2Checkout offers the option of upgrading an ongoing subscription anytime during its lifecycle, except for when it's expired or disabled/canceled. Note: Expired subscriptions can still be upgraded during the grace period, while their status is Past due.

Using this feature together with the Upgrade option will result in a successful calculation of a prorated price for any model. 2Checkout will calculate the period of time that the customer has left from the current subscription cycle and how much he needs to be charged extra.

Note: When calculating the subscription period consumed, seconds are used as a time unit.

Ignore subscription past due period when calculating prorated upgrade price

Customers may renew their subscriptions even after they expire, taking advantage of the Grace Period you can set in the product Renewal setup. To avoid charging an unnecessary extra amount for the upgrade, you can ignore the previous past due period set on a subscription when computing the prorated price.

On the product upgrade page, mark the option Ignore grace period when calculating Upgrade to ignore the grace period set in your Renewal Settings when computing the prorated price for the upgrade.

Ignore grace period

Setup examples

1. Options selected:

  • The shopper will pay: The full upgrade product price
  • The upgrade does not affect the original subscription duration or
  • Create a new subscription (disable the existing one) or
  • Prolong the subscription from the upgrade purchase date

Product 1 price

Discounts or special pricing

Days used

Reference upgrade cost

Product 2 cost

$100/30 days

$10 or 10%

10

Irrelevant

$200/30 days

P1 to P2 upgrade price formula

The shopper will pay $200 for the upgrade, the full price of the upgraded product.

 

2. Options selected:

  • The shopper will pay: The difference between the original subscription and the upgraded product
  • The upgrade does not affect the original subscription duration or
  • Create a new subscription (disable the existing one) or
  • Prolong the subscription from the upgrade purchase date

Product 1 price

Discounts or special pricing

Days used

Reference upgrade cost

Product 2 cost

$100/30 days

$10 or 10%

10

$100

$200/30 days

P1 to P2 upgrade price formula

The shopper will pay $100 for the upgrade, the difference between the cost of Product 2 and the price of Product 1.

 

3. Options selected:

  • The shopper will pay: A prorated upgrade price calculated using the most recent costs incurred by the customer
  • Create a new subscription (disable the existing one) or
  • Prolong the subscription from the upgrade purchase date

Product 1 price

Discounts or special pricing

Days used

Reference upgrade cost

Product 2 cost

$100/30 days

$10 or 10%

10

$90

$200/30 days

P1 to P2 upgrade price formula

Product 2 price - Reference costs for Product 1 * Lifetime left from Product 1 subscription/ Total lifetime of Product 1 subscription = $140

This scenario is not supported for imported subscriptions, until a charge happens on them.

4. Options selected:

  • The shopper will pay: A prorated upgrade price calculated using the most recent costs incurred by the customer
  • The upgrade does not affect the original subscription duration

Product 1 price

Discounts or special pricing

Days used

Reference upgrade cost

Product 2 cost

$100/30 days

$10 or 10%

10

$90

$200/30 days

P1 to P2 upgrade price formula

Product 2 price - Reference costs for Product 1 * Lifetime left from the Product 1 subscription/ Total lifetime of Product 1 subscription - Product 2 price * (Total lifetime of Product 2 subscription - Lifetime left from the Product 1 subscription) / Total lifetime of Product 2 subscription = $73.4

 

5. Options selected:

  • The shopper will pay: A prorated upgrade price calculated using the product's pricing setup at the time of the order
  • Create a new subscription (disable the existing one) or
  • Prolong the subscription from the upgrade purchase date

Product 1 price

Discounts or special pricing

Days used

Reference upgrade cost

Product 2 cost

$100/30 days

$10 or 10%

10

$90

$200/30 days

P1 to P2 upgrade price formula

Product 2 price -Product 1 price * Lifetime left from the Product 1 subscription / Total Lifetime of Product 1 subscription = $133.3

 

6. Options selected:

  • The shopper will pay: A prorated upgrade price calculated using the product's pricing setup at the time of the order
  • The upgrade does not affect the original subscription duration

Product 1 price

Discounts or special pricing

Days used

Reference upgrade cost

Product 2 cost

$100/30 days

$10 or 10%

10

$90

$200/30 days

P1 to P2 upgrade price formula

Product 2 price - Product 1 price * Lifetime left from the Product 1 subscription/ Total Lifetime of Product 1 subscription - Product 2 price * (Total lifetime of Product 2 subscription - Lifetime left from the Product 1 subscription) / Total lifetime of Product 2 subscription = $66.8

Customize your upgrade price

Available only for the following options:

  • The full upgrade product price
  • The difference between original subscription and the upgrade product

These options enable you to modify the actual upgrade price by adding or subtracting a specific percentage.

Subscription period option for the upgrade

When configuring an upgrade for a product with the renewal/recurring billing system enabled (for which subscriptions are generated), you'll also be able to configure how the upgrade process impacts existing subscriptions. Note: Options are not displayed for products with the subscription renewal system disabled.

Three options are available:

  • Generate a new subscription for the upgraded product and disable the one created for the upgradable offering;
  • Prolong the subscription of the upgradable offering, even though the customer will be using the upgraded product;
  • The subscription duration of the upgraded product will not impact the subscription of the upgradable offering.

Using product catalog pricing

Enable the Use product catalog pricing option to ignore all custom upgrade prices set for a product, using instead its initial price, defined in the product catalog. Removing custom prices also disables any existing retention campaigns for the selected subscriptions.

Step 3: Subscription verification system

Optionally, you can enable the subscription verification system, directing shoppers to a generic product upgrade page and requiring them to provide the subscription activation key before they can see the available upgrade options. The subscription verification system only applies to subscriptions that require an activation code.

Zero value upgrades

When upgrading a subscription to one with a lower value, automatic renewal is kept regardless of the Collect Payment details for full discount or orders with 'zero' value option in Ordering options.

Retrieve a promotion

Overview

Use the getPromotion method to extract information on a promotion you set up for your account.

Parameters

Parameters Type/Description

sessionID

Required (string)

 

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

PromotionCode

Required (string)

 

System-generated identifier Avangate associated with promotion campaigns.

Response

Promotion object.

Request

<?php

require ('PATH_TO_AUTH');

$promotionCode = 'YOUR_COUPON_CODE';

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

?>

Update order/product additional fields

Overview

Parameters

Response

bool(true)

Request

<?php

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


function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}

$merchantCode = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key          = "SECRET_KEY"; //your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$now          = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')

$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);

try {
    $sessionID = $client->login($merchantCode, $now, $hash);
}

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

$AdditionalField                             = new stdClass();
$AdditionalField->Label                      = 'Do you agree with the new newsletter policy 2015?';
$AdditionalField->Type                       = 'LISTBOX';
$AdditionalField->Code                       = 'NewsletterPolicy1234576';
$AdditionalField->ApplyTo                    = 'ORDER';
$AdditionalField->Values                     = array();
$AdditionalField->Values[0]                  = 'YES';
$AdditionalField->Values[1]                  = 'NO';
$AdditionalField->ValidationRule             = null;
$AdditionalField->Translations               = array();
$AdditionalField->Translations[0]            = new stdClass();
$AdditionalField->Translations[0]->Label     = "Êtes-vous d'accord avec la politique de la newsletter?";
$AdditionalField->Translations[0]->Values    = array();
$AdditionalField->Translations[0]->Values[0] = 'Oui';
$AdditionalField->Translations[0]->Values[1] = 'Non';
$AdditionalField->Translations[0]->Language  = 'fr';
$AdditionalField->Translations[1]            = new stdClass();
$AdditionalField->Translations[1]->Label     = 'Haben Sie mit dem Newsletter Politik zu?';
$AdditionalField->Translations[1]->Values    = array();
$AdditionalField->Translations[1]->Values[0] = 'Ja';
$AdditionalField->Translations[1]->Values[1] = 'Nein';
$AdditionalField->Translations[1]->Language  = 'de';

$FieldCode = 'NewsletterPolicy1234576';

try {
    $UpdateAdditionalField = $client->updateAdditionalField($sessionID, $FieldCode, $AdditionalField);
}

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

var_dump("UpdateAdditionalField", $UpdateAdditionalField);


?>

Retrieve account's time zone

Overview

Use the getTimezone method to retrieve information on the time zone used by your account for the 2Checkout API.

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.

Response

Timezone

String

 

The time zone you selected or the default GMT+02:00 time zone of the 2Checkout system.

Request


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

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

 

Retrieve account's time zone

Overview

Use the getTimezone method to retrieve information on the time zone used by your account for the 2Checkout API.

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.

Response

Timezone

String

 

The time zone you selected or the default GMT+02:00 time zone of the 2Checkout system.

Request


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

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

 

Assign order/product additional fields

Overview

Use the assignAdditionalField method to update additional fields for your account.

Parameters

sessionID

Required (string)

 

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

FieldCode

Required (string)

 

Field identifier. Alpha-numeric chars, underscores and dashes.

Required

Boolean

 

True or False depending on whether you want make the field mandatory or not.

ProductCode

Required (string)

 

The unique product code that you control not the system-generated product identifier.

Response

bool(true)

Request

<?php

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


function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}

$merchantCode = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$key          = "SECRET_KEY"; //your account's secret key available in the 'System settings' area of the cPanel: https://secure.avangate.com/cpanel/account_settings.php
$now          = gmdate('Y-m-d H:i:s'); //date_default_timezone_set('UTC')

$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);

try {
    $sessionID = $client->login($merchantCode, $now, $hash);
}

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

$ProductCode = 'AAA4643116';
$FieldCode = 'NewsletterPolicy123457106';
$Required = true;
try {
    $AssignedAdditionalField = $client->assignAdditionalField($sessionID, $FieldCode, $Required, $ProductCode);
}

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

var_dump("AssignedAdditionalField", $AssignedAdditionalField);

?>

In-context checkout for Express PayPal Payments

Overview

In-context checkout provides a single-page checkout experience, improving conversion rates by enabling shoppers to pay in a couple of clicks without leaving your website.

 

Recommended resources

Purchase flow

  1. Shoppers select PayPal as their payment method and place the order.

2. The PayPal In-context checkout window appears and prompts shoppers to log in to their PayPal account.

 

3. Shoppers log in and confirm the payment.

4. 2Checkout redirects shoppers to the shopping cart and they place the order.

Availability

In-context checkout is available for 2Monetize accounts (on the reseller business model) and it is supported by the best-converting 2Checkout purchase flows:

  • One-page checkout with review
  • One-page checkout without review
  • Express checkout
  • Available worldwide

Supported currencies

2Checkout supports express PayPal payments in the following currencies:

  • USD (US Dollar)
  • EUR (Euro)
  • GBP (British Pounds)
  • AUD (Australian Dollar)
  • CAD (Canadian Dollar)

Costs

Using in-context checkout does not incur any additional costs on top of the existing 2Checkout commission.

Benefits

1. Keep shoppers on your website. Shoppers can now pay for their orders with PayPal without being redirected to PayPal's website.

2. Simplified design. A friendly and easy to use interface keeps shoppers focused on what matters most, completing purchases in only a few clicks.

3. Cross-platform support. The fast checkout experience is consistent across platforms and devices, even if your shoppers use computers, tablets, or smartphones. Since mobile shopping usage is increasing, the checkout experience is optimized for mobile screens.

F.A.Q.

1. Will pop-up blockers prevent the in-context checkout window from being displayed?

No. As long as the JavaScript is loaded using the on-click or submit events, rather than on-load, pop-up blockers will not prevent the in-context checkout window from being displayed.

2. Can shoppers resize, dismiss and expand the in-context checkout window?

Yes. Dismissing (clicking the x on) the window takes the consumer back to the merchant site to continue shopping. Expanding the in-context checkout window will show the full-page checkout experience.

3. Will the in-context checkout window lose focus behind another window?

No. The in-context checkout window stays on top if shoppers click the parent window. If the in-context checkout window does lose focus (by minimizing the window, for instance), shoppers can bring it back by clicking the link on the greyed-out merchant page.

4. Does the in-context checkout window appear on mobile devices?

No. The smaller screen sizes favor a full-page checkout experience.

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';
 
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'getAssignedPriceOptionGroups',
'params' => array($sessionID, $productCode)
);

var_dump (callRPC((Object)$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