Skip to main content

Calculate and display shopping cart taxes

Overview

When selling internationally, charging the appropriate amount for taxes can be tricky, as the correct taxation can depend on the shopper's country or US state, the product type, and the order total amount. 

However, merchants on the 2Monetize package do not have to worry, as the API calculates and handles the VAT and Sales taxes based on the order information. 

Availability

Available to all 2Checkout accounts.

getContents API Method

Information about VAT and sales taxes is handled by the getContents (for JSON-RPC and SOAP protocols) or by making a PUT request to /orders/0/ on REST.

This API method will take into account the product configuration (NET or GROSS price type, product category, pricing options, etc.), any marketing campaign (like discounts) together with the shopper's location, and return all the information needed to display to the shopper.

Request object

The getContents API call accepts as an input an order object, the same object used for placing an order. However, the only required objects for calculating the taxes are the items information (what products the shopper has in their cart) and the BillingDetails (needed in order to locate the customer and retrieve the taxes that should be applied). 

Switching the currency

Switching the currency and converting prices is supported both for prices set in multiple currencies in the product configuration, as well as on the fly. 

In order to do this, the currency ISO code needs to be updated in the root object Currency element.

Request example

{
    "Country": "DE",
    "Currency": "EUR",
    "Items": [
        {
            "Code": "NIQRPI0GTU",
            "Quantity": 2
        },
        {
            "Code": "0XICS3OVDK",
            "Quantity": 1
        }
    ],
    "BillingDetails": {
        "FirstName": "Customer First Name",
        "LastName": "Customer Last Name",
        "CountryCode": "DE",
        "City": "Bucharest",
        "Address1": "Example Street",
        "Zip": "73331",
        "Email": "example@email.com"
    }
}

Response Object

The API will respond with the full order object, including the price and tax information, both on a line item (unit) level as well as on a cart level.  

{
    "Currency": "eur",
    "NetPrice": 266.71,
    "GrossPrice": 309.38,
    "NetDiscountedPrice": 266.71,
    "GrossDiscountedPrice": 309.38,
    "Discount": 0,
    "VAT": 42.67,
    "AffiliateCommission": 0,
    "Errors": null,
    "Items": [
        {
            "AdditionalFields": null,
            "Code": "NIQRPI0GTU",
            "ExternalReference": "",
            "LineItemReference": "7fe4770c0c95d44dec5c02ee1bc752b568b47808",
            "CrossSell": null,
            "Quantity": 2,
            "Price": {
                "Currency": "eur",
                "NetPrice": 169.88,
                "GrossPrice": 197.06,
                "NetDiscountedPrice": 169.88,
                "GrossDiscountedPrice": 197.06,
                "Discount": 0,
                "VAT": 27.18,
                "AffiliateCommission": 0,
                "UnitNetPrice": 84.94,
                "UnitGrossPrice": 98.53,
                "UnitVAT": 13.59,
                "UnitDiscount": 0,
                "UnitNetDiscountedPrice": 84.94,
                "UnitGrossDiscountedPrice": 98.53,
                "UnitAffiliateCommission": 0,
                "ItemUnitNetPrice": null,
                "ItemUnitGrossPrice": null,
                "ItemNetPrice": null,
                "ItemGrossPrice": null,
                "VATPercent": 16,
                "HandlingFeeNetPrice": 0,
                "HandlingFeeGrossPrice": 0
            },
            "PriceOptions": [],
            "ProductDetails": {
                "Name": "100 USD NET API Product",
                "ShortDescription": "<p>100 USD NET API Product<\/p>",
                "Tangible": false,
                "IsDynamic": false,
                "ExtraInfo": null,
                "RenewalStatus": false,
                "Subscriptions": null,
                "DeliveryInformation": {
                    "Delivery": "NO_DELIVERY",
                    "DownloadFile": null,
                    "DeliveryDescription": "",
                    "CodesDescription": "",
                    "Codes": []
                }
            },
            "Promotion": null,
            "PurchaseType": "PRODUCT",
            "RenewalInformation": null,
            "SKU": null,
            "SubscriptionStartDate": null,
            "Trial": null,
            "SubscriptionCustomSettings": null
        },
        {
            "AdditionalFields": null,
            "Code": "0XICS3OVDK",
            "ExternalReference": "",
            "LineItemReference": "7fe4770c0c95d44dec5c02ee1bc752b568b47808",
            "CrossSell": null,
            "Quantity": 1,
            "Price": {
                "Currency": "eur",
                "NetPrice": 96.83,
                "GrossPrice": 112.32,
                "NetDiscountedPrice": 96.83,
                "GrossDiscountedPrice": 112.32,
                "Discount": 0,
                "VAT": 15.49,
                "AffiliateCommission": 0,
                "UnitNetPrice": 96.83,
                "UnitGrossPrice": 112.32,
                "UnitVAT": 15.49,
                "UnitDiscount": 0,
                "UnitNetDiscountedPrice": 96.83,
                "UnitGrossDiscountedPrice": 112.32,
                "UnitAffiliateCommission": 0,
                "ItemUnitNetPrice": null,
                "ItemUnitGrossPrice": null,
                "ItemNetPrice": null,
                "ItemGrossPrice": null,
                "VATPercent": 16,
                "HandlingFeeNetPrice": 0,
                "HandlingFeeGrossPrice": 0
            },
            "PriceOptions": [],
            "ProductDetails": {
                "Name": "2nd API NET product",
                "ShortDescription": "<p>2nd API NET product<\/p>",
                "Tangible": false,
                "IsDynamic": false,
                "ExtraInfo": null,
                "RenewalStatus": false,
                "Subscriptions": null,
                "DeliveryInformation": {
                    "Delivery": "NO_DELIVERY",
                    "DownloadFile": null,
                    "DeliveryDescription": "",
                    "CodesDescription": "",
                    "Codes": []
                }
            },
            "Promotion": null,
            "PurchaseType": "PRODUCT",
            "RenewalInformation": null,
            "SKU": null,
            "SubscriptionStartDate": null,
            "Trial": null,
            "SubscriptionCustomSettings": null
        }
    ],
    "Promotions": [],
    "AdditionalFields": null,
    "BillingDetails": {
        "FirstName": "Customer First Name",
        "LastName": "Customer Last Name",
        "CountryCode": "de",
        "State": null,
        "City": "Bucharest",
        "Address1": "Example Street",
        "Address2": null,
        "Zip": "73331",
        "Email": "example@email.com",
        "Phone": null,
        "Company": null,
        "FiscalCode": null,
        "TaxOffice": null
    },
    "DeliveryDetails": {
        "FirstName": "Customer First Name",
        "LastName": "Customer Last Name",
        "CountryCode": "de",
        "State": null,
        "City": "Bucharest",
        "Address1": "Example Street",
        "Address2": null,
        "Zip": "73331",
        "Email": "example@email.com",
        "Phone": null,
        "Company": null
    },
    "DeliveryInformation": {
        "ShippingMethod": {
            "Code": null,
            "TrackingUrl": null,
            "TrackingNumber": null,
            "Comment": null
        }
    },
    "Affiliate": {
        "AffiliateCode": null,
        "AffiliateSource": null,
        "AffiliateName": null,
        "AffiliateUrl": null
    },
    "CustomParameters": null
}

Unit price information

Per Line Item, each product contains a Price object, with all relevant information for the product's price and taxes:  

Key name Type Description

Currency

String

The currency ISO 4217 code; This currency is used in all the price values for that product. Example: USD.

UnitNetPrice

Float

The value per product unit (quantity = 1), excluding sales tax/VAT. Discounts are not reflected in this price.

UnitGrossPrice

Float

Total value per product unit (quantity = 1), including sales tax/VAT.  Discounts are not reflected in this price.

UnitVAT

Int

Sales tax/VAT per product unit.

UnitNetDiscountedPrice

Float

The value per product unit,, excluding sales tax/VAT, from which 2Checkout deducts the unit discount.

UnitGrossDiscountedPrice

Float

Total costs shoppers incur per product unit. This value includes sales tax/VAT, 2Checkout, and affiliate commissions, but 2Checkout deducts the value of any discounts.

VATPercent

Int

Percentage of VAT charged on the order.

VAT

Float

Value of VAT per order line.

Discount

Float

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

NetDiscountedPrice

Float

The NetPrice value per order line, excluding sales tax/VAT, from which 2Checkout deducts discounts.

GrossDiscountedPrice

Float

Total costs shoppers incur per order line. This value includes sales tax/VAT, 2Checkout, and affiliate commissions, but 2Checkout deducts the value of any discounts.

Order price information

On order level, in the response object root level, you can find all relevant information for the order's price and taxes:

Key name Type Description

NetPrice

Float

Order value excluding sales tax/VAT.

GrossPrice

Float

Total order value, including sales tax/VAT. GrossPrice does not reflect any discounts.

NetDiscountedPrice

Float

The NetPrice order value excluding sales tax/VAT, from which 2Checkout deducts discounts.

GrossDiscountedPrice

Float

Total costs shoppers incur. This value includes sales tax/VAT, 2Checkout, and affiliate commissions, but 2Checkout deducts the value of any discounts.

Discount

Float

Value of the discounts for an order.

VAT

Float

Value of sales tax/VAT.

Integration test cases

  1. Create a simple product (be it a catalog product in the Control Panel, or a dynamic product), using a round number as the price (like 100) in order to be able to easily check the calculated taxes. 
  2. Using the getContents API call, build your checkout flow, and display the taxes as needed. 
  3. As an easy comparison, you can use a catalog product and generate a buy-link in ConvertPlus and compare the way the taxes are displayed.
  4. If needed, implement the currency switching in the checkout flow.  
  • Keep in mind that, where prices in other currencies are specified in the product catalog, they will be used instead of the prices automatically converted by 2Checkout. 

Use WeChat Pay

Overview

Place an order for catalog products defined in your Control Panel and collect the payment using WeChat Pay.

Requirements

Only Chinese shoppers are able to purchase using WeChat Pay. Make sure the billing country code is set to CN.

Supported currencies

  • USD
  • HKD
  • CNY

Workflow

  1. Shoppers select WeChat as a payment option in the interface you provide to them.
  2. Create the order object. Use WE_CHAT_PAY as the type of the PaymentDetails object, and include ReturnURL and CancelURL.
  3. Use the placeOrder method to send the data to 2Checkout.
  4. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING.
  5. 2Checkout returns an Order object as the output of the placeOrder method. 
  6. Use the PaymentMethod object to create a redirect URL for the shoppers, concatenating the values of the Href and avng8apitoken parameters. Here's an example of the redirect URL:
    https://api.2checkout.com/4.0/scripts/we_chat_pay/authorize/?avng8apitoken=1abc7fd72d008428
  7. After being redirected to WeChat Pay, shoppers need to scan the QR code provided, using the WeChat smartphone app.
  8. After customers enter their payment password, WeChat notifies 2Checkout if the payment is approved, and the status of the order becomes COMPLETE.
  9. Shoppers are redirected to the RedirectURL from the Order information object. In case the payment fails, shoppers are redirected to the CancelURL. 

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.

To place an order with WeChat, use WE_CHAT_PAY as the type of the PaymentDetails object and provide a ReturnURL and a CancelURL as part of the PaymentMethod object. See code sample. 

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 = 'CN';
$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 = 'Test Cosmin API';
$Order->BillingDetails->LastName = 'Cosmin API';
$Order->BillingDetails->CountryCode = 'CN';
$Order->BillingDetails->State = 'California';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '90210';
$Order->BillingDetails->Email = 'cosmin.deftu@2checkout.com';
$Order->BillingDetails->Phone = NULL;
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;

$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'WE_CHAT_PAY';
$Order->PaymentDetails->Currency = 'USD';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '91.220.121.21';
$Order->PaymentDetails->PaymentMethod->ReturnURL = 'http://yourreturnurl.com';
$Order->PaymentDetails->PaymentMethod->CancelURL= 'http://yourcancelurl.com';

$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;

try {
   $newOrder = $client->placeOrder($sessionID, $Order);
}
catch (SoapFault $e) {
    echo "newOrder: " . $e->getMessage();
    exit;
}

$wechatredirect = $newOrder->PaymentDetails->PaymentMethod->Authorize->Href."/?avng8apitoken=".$newOrder->PaymentDetails->PaymentMethod->Authorize->Params->avng8apitoken;

header('Location:' . $wechatredirect);

 

Renew a subscription

Overview

Renew a subscription in the 2Checkout system on-demand, controlling the number of days, price, and currency of the extension. Use the renewSubscription method to renew a subscription.

Parameters

Parameters Type/Description

sessionID

Required (string)

 

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

subscriptionReference

Required (string)

 

Unique, system-generated subscription identifier.

 

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

days

Required (int)

 

The number of days the 2Checkout system extends the lifetime of the subscription.

price

Required (double)

 

The price that 2Checkout charges the customer for the renewal. The type of price, Gross or Net, is decided by the product setting in the Merchant Control Panel.

currency

Required (string)

 

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

Response

Parameters Type/Description

Boolean

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

Request

<?php

require ('PATH_TO_AUTH');

$subscriptionReference = 'YOUR_SUBSCRIPTION_REFERENCE';
$days = 4;
$price = 50;
$currency = 'eur';

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

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

Retrieve a pricing configuration by code

Overview

Use the getPricingConfigurationByCode method to extract information on a specific pricing configuration you set for a product.

Parameters

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.

PricingConfigurationCode

Required (string)

 

The code of the pricing configuration.

Response

PricingConfiguration

Object

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 = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key          = "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;
}
 
$ProductCode = 'subscr1';
$PricingConfigurationCode = '0123456';
 
try {
    $ProductPricingConfiguration = $client-> getPricingConfigurationByCode ($sessionID, $ProductCode, $PricingConfigurationCode);
}

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

var_dump("Pricing Configuration", $ProductPricingConfiguration);
 
 
?>

 

Single Sign On in cart

Overview

Use the getSingleSignOnInCart method. 2Checkout attaches a unique token to links, designed to identify the returning shoppers and support the automatic extraction of payment data and billing information from the 2Checkout system. For example, you can generate single sign-on in cart links for existing customers logged into your website based on their external or 2Checkout customer IDs.

How does this work?

 

When accessing the shopping cart using tokenized payment links:

  • 2Checkout prefills automatically customer billing and delivery details associated with their 2Checkout customer accounts (linked based on their unique customer IDs).
  • 2Checkout presents shoppers with an optimized payment area featuring the credit/debit cards used to make previous purchases/transactions in the 2Checkout system. Customers have the option of selecting one of the payment methods depending on available card-on-file data.

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.

IdCustomer

Required (string)

 

Unique customer identifiers. Can be either the ExternalCustomerReference you control or the system-generated 2CheckoutCustomerReference.

CustomerType

Required (string)

 

Possible values:

  • ExternalCustomerReference
  • 2CheckoutCustomerReference

Url

Required (string)

 

The shopping cart URL. 2Checkout redirects shoppers to this URL.

 

Possible values:

 

Any buy link you generate from the cPanel or using the API. Note: For the time being, payment tokenization does not support Express Payments Checkout or the 2Checkout mobile shopping cart.

ValidityTime

Optional (int)

 

The time, in seconds, before the single sign-on URL expires. By default, the URL expires after 10 seconds. (optional)

ValidationIp

Optional (string)

 

The IP address of the shopper, necessary for security purposes. Can be an empty string or a valid IP, or null.

Response

Single sign-on URL

String

 

The generated string is the tokenized time-limited single sign-on URL pointing to 2Checkout shopping cart.

 

Note: Each SSO link cleans any previous cart sessions. Shoppers using multiple SSO links would purchase only a single product at a time.

 

If shoppers add multiple products to cart via SSO buy links and then use a non-SSO link, they’ll purchase all items using the same order.

When you use single sign-on in cart for customers without card on files in the 2Checkout system, the generated tokenized link prefills the billing information but the purchase process requires that shoppers provide payment information, such as a credit or debit card.

Example: https://store.YourCustomDomain.com/order/checkout.php?PRODS=1112233&logintoken=8b74ac97f8277654563c44da6915b054ba0d21be

 

Important! You can use the value of the logintoken to retrieve customer information by SSO token.

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.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
 
$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);
$IdCustomer = '352365983';
$CustomerType = '2CheckoutCustomerReference';
$Url = 'https://store.avancart.com/order/checkout.php?PRODS=4639321&QTY=1&CART=1&CARD=2';
$ValidityTime = 50;
$ValidationIp = null;

$jsonRpcRequest = array (
'method' => 'getSingleSignOnInCart',
'params' => array($sessionID, $IdCustomer, $CustomerType, $Url, $ValidityTime, $ValidationIp),
'id' => $i++,
'jsonrpc' => '2.0');

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

Place an order with installments

Overview 

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

Supported payment methods 

Credit/Debit cards: Visa and MasterCard local Brazilian cards.

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

  1. Payment methods: Visa, MasterCard or AMEX
  2. Country: Brazil
  3. Currency BRL
  4. Specified number of installments under the PaymentMethod object. (Minimum installment threshold is 5 BRL.)
    • Phone number
    • Fiscal code (CPF/CNPJ)
  5. Mandatory billing information must include:

  6. Transaction: non-recurring
  7. Installments are available only for:
    • Brazilian customers
    • Local Visa, MasterCard and AMEX cards
    • Non-recurring transactions


<?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 = "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(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);
 
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'brl';
$Order->Country = 'BR';
$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]->Promotion = NULL;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'FirstName';
$Order->BillingDetails->LastName = 'LastName';
$Order->BillingDetails->CountryCode = 'BR';
$Order->BillingDetails->State = 'DF';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '70403-900';
$Order->BillingDetails->Email = 'customer@email.com';
$Order->BillingDetails->Phone = "556133127400";
$Order->BillingDetails->FiscalCode = "056.027.963-98";
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'brl';
$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->CCID = '123';
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;

$jsonRpcRequest = array (
'method' => 'getInstallments',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);
echo '<BR>';
echo 'The content of the current session:';
echo '<BR>';
$installments = callRPC((Object)$jsonRpcRequest, $host, true);
var_dump ($installments);
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'brl';
$Order->Country = 'BR';
$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]->Promotion = NULL;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->FirstName = 'FirstName';
$Order->BillingDetails->LastName = 'LastName';
$Order->BillingDetails->CountryCode = 'BR';
$Order->BillingDetails->State = 'DF';
$Order->BillingDetails->City = 'LA';
$Order->BillingDetails->Address1 = 'Address example';
$Order->BillingDetails->Address2 = NULL;
$Order->BillingDetails->Zip = '70403-900';
$Order->BillingDetails->Email = 'customer@email.com';
$Order->BillingDetails->Phone = "556133127400";
$Order->BillingDetails->FiscalCode = "056.027.963-98";
$Order->BillingDetails->Company = NULL;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'CC';
$Order->PaymentDetails->Currency = 'brl';
$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->InstallmentsNumber = 2;
$Order->PaymentDetails->PaymentMethod->CardType = 'visa';
$Order->PaymentDetails->PaymentMethod->ExpirationYear = '2019';
$Order->PaymentDetails->PaymentMethod->ExpirationMonth = '12';
$Order->PaymentDetails->PaymentMethod->HolderName = 'John';
$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'
);
echo '<BR>';
echo 'The content of the current session:';
echo '<BR>';
var_dump (callRPC((Object)$jsonRpcRequest, $host, true));

Add a subscription plan/product

 

Use the addProduct method to create subscription plans/products for your 2Checkout account in SOAP API 4. 

Parameters

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.

Product

Required (object)

 

Use this object to configure your subscription plans/products.

 

You can set all Product parameters except 2CheckoutID and GroupName. The 2Checkout system sets the unique product ID. The 2CheckoutID and GroupName not editable.

Mandatory parameters

 

ProductName
ProductCode
PricingConfigurations

Response

bool(true)

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 = "YOURCODE123"; //your account's merchant code available in the 'System settings' area of the cPanel: https://secure.2checkout.com/cpanel/account_settings.php
$key          = "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;
}

$Product                 = new stdClass();
$Product->2CheckoutId     = null;
$Product->ProductCode    = 'API_Imported_1234567899';
$Product->ProductType    = 'REGULAR';
$Product->ProductName    = 'API_Subscription Imported New';
$Product->ProductVersion = '1.0';

//Shipping classes

/* $Product->ShippingClass = new stdClass();
$Product->ShippingClass->Name = '2o9rlujkvg';
$Product->ShippingClass->Amount = 89.40;
$Product->ShippingClass->Currency = 'GBP';
$Product->ShippingClass->ApplyTo = 'ct29dr3fj4';
$Product->ShippingClass->Type = 'bii521vp6k'; */

$Product->GiftOption                 = false;
$Product->ShortDescription           = 'Placeat cumque necessitatibus est minus praesentium ut non quibusdam. Molestias provident tempore eligendi mollitia quia.';
$Product->LongDescription            = 'Corrupti inventore vitae nesciunt ab. Nemo cum non maiores. Non repudiandae est iste voluptatibus.';
$Product->SystemRequirements         = null;
$Product->ProductCategory            = null;
$Product->Platforms                  = array();
$Product->Platforms[0]               = new stdClass();
$Product->Platforms[0]->PlatformName = null;
$Product->Platforms[0]->Category     = null;
$Product->Platforms[1]               = new stdClass();
$Product->Platforms[1]->PlatformName = null;
$Product->Platforms[1]->Category     = null;
$Product->ProductImages              = array();
$Product->ProductImages[0]           = new stdClass();
$Product->ProductImages[0]->URL      = null;
$Product->ProductImages[0]->Default  = false;
$Product->ProductImages[1]           = new stdClass();
$Product->ProductImages[1]->URL      = null;
$Product->ProductImages[1]->Default  = true;
$Product->TrialUrl                   = null;
$Product->TrialDescription           = null;
$Product->Enabled                    = True;

//Product additional fields

/* $Product->AdditionalFields = array();
$Product->AdditionalFields[0] = new stdClass();
$Product->AdditionalFields[0]->Label = 'i44wak1dzp';
$Product->AdditionalFields[0]->Code = 'ITYAK0OEWJ';
$Product->AdditionalFields[0]->Enabled = false;
$Product->AdditionalFields[0]->Required = false;
$Product->AdditionalFields[0]->URLParameter = 'id1ktigl6d';
$Product->AdditionalFields[1] = new stdClass();
$Product->AdditionalFields[1]->Label = 'aig699lmo1';
$Product->AdditionalFields[1]->Code = 'V28TP07PQN';
$Product->AdditionalFields[1]->Enabled = false;
$Product->AdditionalFields[1]->Required = true;
$Product->AdditionalFields[1]->URLParameter = '8to9p6y54j'; */

//Product localization

/* $Product->Translations = array();
$Product->Translations[0] = new stdClass();
$Product->Translations[0]->Name = 'zsg7wtg4e5';
$Product->Translations[0]->Description = 'Voluptate iure ut quam omnis impedit. Deserunt facere id dolores doloribus quis. Minima nostrum ut possimus incidunt vel est sint. Odit tempora omnis iste nesciunt commodi accusantium placeat.';
$Product->Translations[0]->Language = 'pt';
$Product->Translations[0]->LongDescription = 'Pariatur molestiae sit dignissimos modi. Aut modi libero numquam repudiandae. Doloribus explicabo delectus fugiat amet. Excepturi quo consequatur sint adipisci.';
$Product->Translations[0]->SystemRequirements = 'c16tvyg88c';
$Product->Translations[0]->TrialUrl = 'UNCAUGHT TYPE: anyURI';
$Product->Translations[0]->TrialDescription = 'Voluptas rem sit ut voluptas molestias quidem ut. Maiores facilis tempora voluptates. Consequuntur illum recusandae hic magni iste.';
$Product->Translations[1] = new stdClass();
$Product->Translations[1]->Name = 'cv2sx15aby';
$Product->Translations[1]->Description = 'Ut distinctio asperiores et a placeat voluptatem et. Et eveniet temporibus aut vel. Nemo occaecati praesentium dolor fugiat rerum assumenda expedita.';
$Product->Translations[1]->Language = 'fr';
$Product->Translations[1]->LongDescription = 'Et ut nostrum molestiae voluptates soluta. Molestiae cum in ut qui. Voluptatem voluptates vero odit quia corporis. In impedit eligendi sed expedita nihil temporibus nobis.';
$Product->Translations[1]->SystemRequirements = 'cfv2amk25j';
$Product->Translations[1]->TrialUrl = 'UNCAUGHT TYPE: anyURI';
$Product->Translations[1]->TrialDescription = 'Voluptatem ut possimus consequatur iste. Recusandae id quia sed quibusdam aut debitis. Cupiditate harum architecto quod quia.'; */


$Product->PricingConfigurations                                     = array();
$Product->PricingConfigurations[0]                                  = new stdClass();
$Product->PricingConfigurations[0]->Default                         = false;
$Product->PricingConfigurations[0]->Code                            = null;
$Product->PricingConfigurations[0]->Name                            = 'API Pricing Configuration Test';
$Product->PricingConfigurations[0]->BillingCountries                = array();
$Product->PricingConfigurations[0]->PricingSchema                   = 'DYNAMIC';
$Product->PricingConfigurations[0]->PriceType                       = 'NET';
$Product->PricingConfigurations[0]->DefaultCurrency                 = 'USD';
$Product->PricingConfigurations[0]->Prices                          = new stdClass();
$Product->PricingConfigurations[0]->Prices->Regular                 = array();
$Product->PricingConfigurations[0]->Prices->Regular[0]              = new stdClass();
$Product->PricingConfigurations[0]->Prices->Regular[0]->Amount      = 100;
$Product->PricingConfigurations[0]->Prices->Regular[0]->Currency    = 'USD';
$Product->PricingConfigurations[0]->Prices->Regular[0]->MinQuantity = 1;
$Product->PricingConfigurations[0]->Prices->Regular[0]->MaxQuantity = 10;
$Product->PricingConfigurations[0]->Prices->Regular[0]->OptionCodes = array();
$Product->PricingConfigurations[0]->Prices->Regular[1]              = new stdClass();
$Product->PricingConfigurations[0]->Prices->Regular[1]->Amount      = 200;
$Product->PricingConfigurations[0]->Prices->Regular[1]->Currency    = 'USD';
$Product->PricingConfigurations[0]->Prices->Regular[1]->MinQuantity = 11;
$Product->PricingConfigurations[0]->Prices->Regular[1]->MaxQuantity = 100;
$Product->PricingConfigurations[0]->Prices->Regular[1]->OptionCodes = array();
$Product->PricingConfigurations[0]->Prices->Renewal                 = array();
$Product->PricingConfigurations[0]->Prices->Renewal[0]              = new stdClass();
$Product->PricingConfigurations[0]->Prices->Renewal[0]->Amount      = 50;
$Product->PricingConfigurations[0]->Prices->Renewal[0]->Currency    = 'USD';
$Product->PricingConfigurations[0]->Prices->Renewal[0]->MinQuantity = 1;
$Product->PricingConfigurations[0]->Prices->Renewal[0]->MaxQuantity = 10;
$Product->PricingConfigurations[0]->Prices->Renewal[0]->OptionCodes = array();
$Product->PricingConfigurations[0]->Prices->Renewal[1]              = new stdClass();
$Product->PricingConfigurations[0]->Prices->Renewal[1]->Amount      = 60;
$Product->PricingConfigurations[0]->Prices->Renewal[1]->Currency    = 'USD';
$Product->PricingConfigurations[0]->Prices->Renewal[1]->MinQuantity = 11;
$Product->PricingConfigurations[0]->Prices->Renewal[1]->MaxQuantity = 100;
$Product->PricingConfigurations[0]->Prices->Renewal[1]->OptionCodes = array();
$Product->PricingConfigurations[0]->PriceOptions                    = array();

/* $Product->BundleProducts = array();
$Product->BundleProducts[0] = new stdClass();
$Product->BundleProducts[0]->ProductCode = '540Q45PQBN';
$Product->BundleProducts[0]->ProductId = 48439;
$Product->BundleProducts[1] = new stdClass();
$Product->BundleProducts[1]->ProductCode = 'PA3JDB5SZ2';
$Product->BundleProducts[1]->ProductId = 46439;
*/
$Product->Fulfillment = 'NO_DELIVERY';
$Product->Prices      = array();

$Product->GeneratesSubscription                            = True;
$Product->SubscriptionInformation                          = new stdClass();
$Product->SubscriptionInformation->DeprecatedProducts      = array();
$Product->SubscriptionInformation->BundleRenewalManagement = null;
$Product->SubscriptionInformation->BillingCycle            = 1;
$Product->SubscriptionInformation->BillingCycleUnits       = 'M';
$Product->SubscriptionInformation->IsOneTimeFee            = false;

$Product->SubscriptionInformation->ContractPeriod                       = new stdClass();
$Product->SubscriptionInformation->ContractPeriod->Period               = -1;
$Product->SubscriptionInformation->ContractPeriod->PeriodUnits          = 'days';
$Product->SubscriptionInformation->ContractPeriod->IsUnlimited          = TRUE;
$Product->SubscriptionInformation->ContractPeriod->Action               = 'RESTART';
$Product->SubscriptionInformation->ContractPeriod->EmailsDuringContract = 'altenwerth.elise@gmail.com';

//$Product->SubscriptionInformation->UsageBilling = 77;

$Product->SubscriptionInformation->GracePeriod              = new stdClass();
$Product->SubscriptionInformation->GracePeriod->Type        = 'GLOBAL';
$Product->SubscriptionInformation->GracePeriod->Period      = 14;
$Product->SubscriptionInformation->GracePeriod->PeriodUnits = 'D';
$Product->SubscriptionInformation->GracePeriod->IsUnlimited = false;

$Product->SubscriptionInformation->RenewalEmails                                               = new stdClass();
$Product->SubscriptionInformation->RenewalEmails->Type                                         = 'CUSTOM';
$Product->SubscriptionInformation->RenewalEmails->Settings                                     = new stdClass();
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal                      = new stdClass();
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->Before30Days        = true;
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->Before15Days        = true;
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->Before7Days         = true;
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->Before1Day          = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->OnExpirationDate    = true;
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->After5Days          = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->ManualRenewal->After15Days         = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal                   = new stdClass();
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->Before30Days     = true;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->Before15Days     = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->Before7Days      = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->Before1Day       = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->OnExpirationDate = true;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->After5Days       = false;
$Product->SubscriptionInformation->RenewalEmails->Settings->AutomaticRenewal->After15Days      = true;

$Product->FulfillmentInformation                                = new stdClass();
$Product->FulfillmentInformation->IsStartAfterFulfillment       = false;
$Product->FulfillmentInformation->IsElectronicCode              = false;
$Product->FulfillmentInformation->IsDownloadLink                = false;
$Product->FulfillmentInformation->IsBackupMedia                 = false;
$Product->FulfillmentInformation->IsDownloadInsuranceService    = false;
$Product->FulfillmentInformation->IsInstantDeliveryThankYouPage = false;
$Product->FulfillmentInformation->IsDisplayInPartnersCPanel     = false;

/* $Product->FulfillmentInformation->CodeList = new stdClass();
$Product->FulfillmentInformation->CodeList->Code = '5C6F821DA1';
$Product->FulfillmentInformation->CodeList->Name = 'General delivery';
$Product->FulfillmentInformation->CodeList->Type = 'STATIC';  */

//$Product->FulfillmentInformation->BackupMedia = new stdClass();

//$Product->FulfillmentInformation->ProductFile = new stdClass();

/* $Product->FulfillmentInformation->AdditionalInformationByEmail = 'arlene03@hotmail.com';
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations = array();
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[0] = new stdClass();
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[0]->Name = 'kbaa1aj7po';
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[0]->Description = 'Velit delectus sed amet sunt. Sunt deserunt quos recusandae consequuntur est. Velit aut optio error eius rerum. Nihil ipsam possimus ipsum dolores consequatur adipisci.';
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[0]->Language = 'fr';
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[1] = new stdClass();
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[1]->Name = 'l4ocvz9wwa';
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[1]->Description = 'Esse voluptatem delectus officiis eos quas asperiores. Quas non hic reiciendis enim. Consequatur similique recusandae laboriosam et autem.';
$Product->FulfillmentInformation->AdditionalInformationEmailTranslations[1]->Language = 'pt';
$Product->FulfillmentInformation->AdditionalThankYouPage = 'rvlhvkmxkp';
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations = array();
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[0] = new stdClass();
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[0]->Name = 'rl981w4nua';
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[0]->Description = 'Qui explicabo molestiae dolorem consequuntur. Ullam maiores temporibus vitae. Totam eos et consequatur. Est sit minima animi nam ut aut.';
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[0]->Language = 'en';
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[1] = new stdClass();
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[1]->Name = 'qye8hlwz3e';
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[1]->Description = 'Id est rerum deserunt non et quia magnam. Minus aut nostrum dicta est officiis quia. Commodi nobis sit porro accusamus rerum quis. Fugit et asperiores eum.';
$Product->FulfillmentInformation->AdditionalThankYouPageTranslations[1]->Language = 'fr';
*/


try {
    $NewSubscriptionPlan = $client->addProduct($sessionID, $Product);
}

catch (SoapFault $e) {
    echo "AddedProductInfo: " . $e->getMessage();
    exit;
}
var_dump("AddedProductInfo", $NewSubscriptionPlan);
?>

 

Update additional fields

Overview

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

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.

AdditionalField

Object

 

Additional field object.

Response

bool(true)

Request

<?php

require ('PATH_TO_AUTH');

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

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

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

var_dump("UpdateAdditionalField", $UpdateAdditionalField);

 

Add/Import test subscriptions with credit/debit card data

Overview

Import test subscription and data from your or a third-party system with payment information assigned, and test advanced renewal and upgrade scenarios in the 2Checkout platform. Contact 2Checkout directly for additional details.

Use the addSubscription method to import a test subscription into the 2Checkout system.

Requirements

Test subscriptions can be imported only for eStore orders. Only dummy credit card data can be assigned to subscriptions. Check here the list of credit cards that can be used for import.

Cardholder name is composed as FirstName + " " + LastName.

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.

Subscription import

Required (Object)

 

Object designed to provide 2Checkout with all the information to create a subscription.

Test Optional (integer)
  To add test subscriptions, set the Test parameter to 1. Default value is 0, and belongs to regular subscriptions.

CardPayment

Optional (Object)

 

Object containing card details. Check here the list of credit cards that can be used for import.

Response

Parameters Type/Description

SubscriptionReference

String

 

Unique, system-generated subscription identifier.

Request

<?php

require ('PATH_TO_AUTH');

$Product = new stdClass ();
$Product->ProductCode = 'my_subscription_1';
$Product->ProductId = 4639321;
$Product->ProductName = '2Checkout Subscription Imported';
$Product->ProductVersion = 1.0;
$Product->ProductQuantity = 3;
$Product->PriceOptionCodes = array();

$EndUser = new stdClass ();
$EndUser->Address1 = 'Address line 1';
$EndUser->Address2 = 'Address line 2';
$EndUser->City = 'LA';
$EndUser->Company = 'Company Name';
$EndUser->CountryCode = "US";
$EndUser->Email = 'customerAPI@2Checkout.com';
$EndUser->FirstName = 'Customer'; // first name and last name are used for determining the CardHolder Name
$EndUser->Language = 'en';
$EndUser->LastName = '2Checkout'; // first name and last name are used for determining the CardHolder Name
$EndUser->Phone = '1234567890';
$EndUser->State = 'California';
$EndUser->Fax = NULL;
$EndUser->Zip = '90210';

$Subscription = new stdClass();
$Subscription->ExternalSubscriptionReference = '12345678912ImportedSubscription';
$Subscription->SubscriptionCode= NULL;
$Subscription->StartDate = '2013-01-01';
$Subscription->ExpirationDate = '2017-12-30';
$Subscription->Product = $Product;
$Subscription->EndUser = $EndUser;
$Subscription->ExternalCustomerReference = '12354678ExtCustRef';
$Subscription->Test = 1; // send 1 for test subscription, 0 for regular subscriptions.

$PaymentCard = new stdClass ();
$PaymentCard->CardNumber = '4111111111111111' ;
$PaymentCard->CardType = 'VISA';
$PaymentCard->ExpirationYear = '2018';
$PaymentCard->ExpirationMonth = '12';
$PaymentCard->CCID = '123';
$PaymentCard->HolderNameTime = '15';
$PaymentCard->CardNumberTime = '15';
$PaymentCard->AutoRenewal = true;

try {
    $importedSubscriptionNoPayData = $client->addSubscription($sessionID, $Subscription, $PaymentCard);
}
catch (SoapFault $e) {
    echo "importedSubscriptionNoPayData: " . $e->getMessage();
    exit;
}
var_dump("importedSubscriptionNoPayData", $importedSubscriptionNoPayData);

One Click (1-click) Ordering for Hosted 2Checkout Carts

Overview

Repeat customers tend to outspend new shoppers by 67%. 2Checkout supports 1-click ordering for returning customers who paid for their previous orders with Credit/Debit cards. You can facilitate new orders, subscription renewals and upgrades for existing subscribers. Customers get all the benefits of utilizing payment-on-file data and none of the hassles associated with churn-driving cart funnels. 

Benefits

  • Increase Customer Lifetime Value (CLTV)
  • Boost conversion rate
  • Offer fully PCI compliant ordering experiences

Case study

Bitdefender increased Conversion Rate from 4.8% to 14% and AOV by 12% using 1-Click Ordering – case study.

SingleSignOn for hosted 2Checkout carts

Streamline the 2Checkout hosted cart and:

  • Display previously used credit cards for returning customers. 
  • Remove the friction from more traditional checkout experiences.
  • Create checkout experiences for returning customers when offering subscription renewals, new upgrades, upsells or cross sells.

Payment tokenization works with unique customer IDs from the 2Checkout platform. 

Use case

Custom carts and ordering interfaces  – display previously used credit cards (embedded).  

Embed payment interfaces into sites or apps. Customers get to choose their payment method from those on file.  They complete transactions without:

  • Being redirected to a shopping cart.
  • Being required to provide billing or payment details.

Documentation: Hosted 2Checkout carts SSO

Check out the Hosted 2Checkout carts SSO guide.

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