Skip to main content
knowledgecenter.2checkout.com

Inline Checkout methods and parameters

Overview

Minimize your customers' effort by collecting their order/billing information and passing it to Inline Checkout. Simplify the checkout experience and enable your customers to place orders only by confirming their payment information.

Advanced Inline Checkout experience

Inline Checkout offers you advanced control over the ordering process, for minimizing the customer's effort during the purchase. You can send the billing and delivery information directly to the cart if they are collected on your website by a shopping cart application. Inline Checkout enables you to:

  • Place test orders
  • Set coupons codes in cart
  • Set the cart language
  • Set the cart currency
  • Set a redirect URL after a finalized purchase

Send information to Inline Checkout

After you integrate the Inline Checkout JavaScript code in your website application, you get access to the library that allows you to add products, control billing and shipping details and start the checkout process. Follow the instructions below to control the information displayed by Inline Checkout.

Handling products

Products are handled by the products service. This service allows you to retrieve the list of added products, add products to cart, remove individual products or remove all the products from the cart.

Use the methods and product attributes listed below to add/remove products from the cart.

Product attributes

Attributes Type/Description
code

String

Product code assigned by you when creating the product. Required for catalog products.

type

String

Product type. Required only for dynamic products. Possible values:

[PRODUCT, SHIPPING, TAX]. Default value is PRODUCT.

name

String

Product name. Required for dynamic products.

price

String - for dynamic products

Product price. It is required for dynamic products.

 

Object - for catalog products with on-the-fly pricing

Product price. It is required for catalog products with on-the-fly pricing and includes value and currency.

tangible

String

Product tangible flag. Required only for dynamic products. Default value is FALSE.

quantity

String

Product quantity. Default value is 1. Required for catalog products with on-the-fly pricing.

options

Array

The product price options. It is supported for both catalog and dynamic products. Required for catalog products with on-the-fly pricing.

 

Product price options structure for dynamic products:

  • Name (String)- The price option name
  • Value (String, Number, Array of strings or numbers) - The price option value
  • Surcharge (string) - The price option surcharge - applicable only for dynamic products

Product price options structure for catalog products:

  • Name (String) – The unique code of the pricing OPTION GROUP
  • Value (String) – The unique code of the pricing OPTION
recurrence

Object

Required for dynamic products.

Possible values:

  • DAY
  • WEEK
  • MONTH
  • YEAR
  • FOREVER (available only for duration)

This parameter is conditioned by two other parameters: duration and renewalPrice.

duration

Object

Sets the duration of the recurrence. Required for dynamic products.

renewalPrice

Integer

Sets the price to be applied to the renewal order. Required for dynamic products.

Product methods

Methods Description
add Adds a single product to the list. Use the above list of parameters to add a product to cart.
remove Removes a product from the list.
addMany

Adds an array of product objects to the main list.

removeAll

Removes all products from the list.

getAll

Retrieves the products list.

HANDLING billing details

Billing details are handled by the billing service. Each billing information is controlled by a setter method.

Use the attributes and methods listed below to control the billing information displayed in cart. Customers are able to fill in their billing information in the overlay provided by Inline Checkout. In case your shopping cart application collects customer's billing information, use the attributes and methods listed below to pass that information over to the cart.

Billing details attributes

Attributes Type/Description
name

String

Customer billing name. Example: "John Doe". 

email

String

Customer billing email. Example: "john.doe@email.com".

phone

String

Customer billing phone number. Example: "403940281923".

country

String

Customer billing country. Example: "US".

city

String

Customer billing city. Example: "Los Angeles".

state

String

Customer billing state. Example: "California".

zip

String

Customer billing zip code. Example: "90078".

address

String

Customer billing address. Example: "1093 Rodeo Drive".

address2

String

Customer billing additional address information. "293 Postal Box".

Billing details methods

Methods Description
setData

Sets the entire billing data.

setName Sets the billing name.
setEmail Sets the billing email.
setPhone

Sets the billing phone.

setCountry Sets the billing country.
setCity Sets the billing city.
setState Sets the billing state.
setZip

Sets the billing zip code.

setAddress Sets the billing address.
setAddress2 Sets additional billing address information.
reset Resets the billing data.

Retrieve billing information from the cart by using the getData method.

Handle shipping details 

Shipping details are handled by the shipping service. Each shipping information is controlled by a setter method.

Use the attributes and methods listed below to control the shipping information displayed in the cart. In case you use a shopping cart application that collects the shipping information, use the attributes and methods listed below to pass that information over to the cart.

Shipping details attributes

Attributes Type/Description
name

String

Customer shipping name. Example: "John Doe". 

email

String

Customer shipping email. Example: "john.doe@email.com".

phone

String

Customer shipping phone number. Example: "403940281923".

country

String

Customer shipping country. Example: "United States of America".

city

String

Customer shipping city. Example: "Los Angeles".

state

String

Customer shipping state. Example: "California".

zip

String

Customer shipping zip code. Example: "90078".

address

String

Customer shipping address. Example: "1093 Rodeo Drive".

address2

String

Customer shipping additional address information. "293 Postal Box".

Shipping details methods

Methods Description
setData

Sets the entire shipping data.

setName Sets the shipping name.
setEmail Sets the shipping email.
setPhone

Sets the shipping phone.

setCountry Sets the shipping country.
setCity Sets the shipping city.
setState Sets the shipping state.
setZip

Sets the shipping zip code.

setAddress Sets the shipping address.
setAddress Sets additional shipping address information.
reset Resets the shipping data.

Retrieve shipping information form cart by using the getData method.

HANDLE the Checkout process 

Control the cart behavior by using the cart service. Use the checkout method to start the Inline Checkout experience.

Cart attributes

Attributes Type/Description
source

String

Sale originating source. Example: "YouTube Channel".

language

String

Cart language code. Example: "FR".

currency

String

Cart currency code. Example: "USD".

test

Boolean

Test order flag. Possible values:

  • true for test orders
  • false for real orders
setReturnMethod

String

Sets the ReturnMethod object. 

URL to which customer is redirected after a successful payment. Example: https://www.merchant-website.com.

coupon

String

Order promotion coupon. Example: "50%off".

token

String

Token for the authorization code.

expiration

String

The expiration date for the authorization.

orderExternalRef

String

The unique identifier of an order placed in the 2Checkout system, mirroring the reference you're using to manage order data in your system.

CustomerReference Integer/The 2Checkout system generates default customer numerical (integer) IDs automatically for all orders containing products that feature subscriptions. Can be used for new acquisitions aggregating new subscriptions under an existing Customer account.
ExternalCustomerReference String/The external customer reference.

Cart methods

Methods Description
register*

Makes the products, billing, shipping, cart and formParser services available.

These services are unavailable unless this method is called.

checkout

Starts the cart service which displays the overlay payment form.

addCoupon

Adds a coupon to the coupons list.

addCoupons Adds coupons in the cart from a list array.
removeCoupon

Removes a coupon from the coupons list.

removeCoupons

Clears all coupons from the cart instance.

setSource

Sets the order source.

setCurrency

Sets the currency on the cart instance.

setLanguage

Sets the language code for the order.

setReturnMethod

Sets the ReturnMethod object. 

URL to which customer is redirected after a successful payment. Example: https://www.merchant-website.com.

setTest

Send true for placing a test order.

setLoaderState Handles the overlay window visibility.
setIframeState

Handles the loader visibility.

reloadCart

Reloads the cart instance.

setOrderExternalRef Sets the order external reference.
setCustomerReference Sets 2Checkout customer reference.
setExternalCustomerReference Sets external customer reference.
setCartLockedFlag

Boolean

Lock cart flag. Possible values:

  • true 
  • false

Retrieve cart attributes from Inline Checkout by using get methods: getTest, getLanguage, getCurrency, getSource, getCoupons, getSuccessURL, getCustomerReference, getExternalCustomerReference, getCartLockedFlag.

*When inserting the JavaScript code snippet from your Control Panel into your e-commerce website, you will get access to the library that allows you to add products, control billing and shipping details and start the checkout process, without having to call the register() method.

Subscribe to shopping cart events

To subscribe to shopping cart events you need to call the events service 'subscribe' method with the event name as the first argument and a callback function as the second argument.

Below you can find a list of events that are supported by the shopping cart and you can subscribe to:

1. 'cart:opened' - triggers when the shopping cart is opened.
2. 'cart:closed' - triggers when the shopping cart is closed.
3. 'payment:finalized' - triggers when the payment has finalized.
4. 'fulfillment:finalized' - triggers when the fulfillment is completed.

TwoCoInlineCart.events.subscribe('cart:opened', function () {
    console.log('cart:opened triggered');
});

Sample request for catalog products

TwoCoInlineCart.setup.setMerchant('merchantCode'); // your Merchant code
TwoCoInlineCart.register();

TwoCoInlineCart.billing.setCountry('US'); // customer billing country
TwoCoInlineCart.billing.setName('John Doe'); // customer billing Name
TwoCoInlineCart.billing.setEmail('john.doe@email.com'); // customer email address

TwoCoInlineCart.shipping.setName('Jane Doe'); // customer Delivery name
TwoCoInlineCart.shipping.setEmail('jane.doe@email.com'); // customer Delivery email

TwoCoInlineCart.products.add({
    code: 'the-2co-product-code',
    quantity: 3
    options: [{
       name: 'color',
       value: 'red'
   }]
});

TwoCoInlineCart.products.addMany([
    {
        type: 'PRODUCT', 
        name: 'product 1', 
        price: 10, 
        tangible: true, 
        quantity: 1, 
    },
    {
        type: 'PRODUCT', 
        name: 'product 2', 
        price: 30, 
        tangible: true, 
        quantity: 1, 
    }                
]);

TwoCoInlineCart.cart.addCoupon('50%OFF'); // discount code
TwoCoInlineCart.cart.setCurrency('GBP'); // order currency
TwoCoInlineCart.cart.setLanguage('fr'); // language code
TwoCoInlineCart.cart.setOrderExternalRef('1231231'); // order external reference
TwoCoInlineCart.cart.setExternalCustomerReference('ID123extern'); // external customer reference 
TwoCoInlineCart.cart.checkout(); // start checkout process

Sample request for dynamic products

TwoCoInlineCart.setup.setMerchant('merchantCode'); // your merchant code
TwoCoInlineCart.setup.setMode('DYNAMIC'); // product type
TwoCoInlineCart.register();

TwoCoInlineCart.cart.setCurrency('USD'); // order currency

TwoCoInlineCart.products.add({
name        : 'A test dynamic product',
recurrence:{
    unit: 'WEEK',
    length: 2
},
duration: {
    unit: 'YEAR',
    length: 1
},
renewalPrice: 100.99
});
TwoCoInlineCart.cart.checkout(); //start checkout process
  • Was this article helpful?