Widget.js Library

Get Started

In order to speed up the integration, we have developed a simple and easy-to-use JavaScript plug-in Widget.js. The plugin can be quickly embedded on your website.

Widget.js allows you to:

  • Automatically geolocate the customer and display formatted product price and the correct sales tax in the customer's local currency.
  • Once the customer selects the subscription product and its billing plan, the checkout process starts with their prefilled data like email address, full name, etc.
Production Widget.js URL https://cdn.transaction.cloud/latest/widget.min.js production widget link
Sandbox Widget.js URL https://sandbox-cdn.transaction.cloud/latest/widget.sandbox.min.js sandbox widget link

Installation

In order to start using Widget.js, include the following HTML script snippet before your application code. In most cases, it has to be included in the beginning of the <head> tag.

Widget.js supports two ways of product embedding: HTML integration and JavaScript.

If you have a static website, we recommend choosing HTML integration. If you need more flexibility and/or are using JS frameworks like Angular, React, Vue.js, etc., we highly recommend starting with the JavaScript integration process.

HTML integration

Our Widget.js script automatically detects the special HTML data tags that allow you to embed the price and initiate the checkout process.

Displaying Product Price

Product name:

<span data-ts-product-name data-ts-product="TC-EXAMPLE-PRODUCT-ID"></span>

Product description:

<p data-ts-product-description data-ts-product="TC-EXAMPLE-PRODUCT-ID"></p>

Product image:

<div data-ts-product-image data-ts-product="TC-EXAMPLE-PRODUCT-ID"></div>

Displaying Product Price

To display the product price, simply include the following data tag on any HTML object, such as span, div, or any element that suits your layout.

Price (gross):

<span data-ts-price data-ts-product="TC-EXAMPLE-PRODUCT-ID"></span>

Price (net):

<span data-ts-price data-ts-show-net="true" data-ts-product="TC-EXAMPLE-PRODUCT-ID"></span>

Price (tax):

<span data-ts-price data-ts-show-tax="true" data-ts-product="TC-EXAMPLE-PRODUCT-ID"></span>

Starting Checkout Process

To initiate the checkout process for any product, use the following data tag on any HTML object, such as a button, span, div, or any element of your choice to trigger the checkout.

<button data-ts-button data-ts-product="TC-EXAMPLE-PRODUCT-ID"></button>

In the above example, the system applies standard styles. If you want to style the payment button with your own branding, add the data-ts-style="none" tag. Please see the example below:

<button
data-ts-button
data-ts-product="TC-EXAMPLE-PRODUCT-ID"
data-ts-style="none"></button>

By default, a payment form will replace the current page. If you prefer to open it in a pop-up, pass an additional parameter:

<button
data-ts-button
data-ts-popup="true"
data-ts-product="TC-EXAMPLE-PRODUCT-ID"></button>

Not all payment methods are available in this mode. For example, Apple Pay is not allowed in a pop-up view.

You can also pass additional information about the customer if you want to use prefilled details. Please see thee full example below:

<button
   data-ts-first-name="Test"
   data-ts-last-name="Test"
   data-ts-zip-code="18951"
   data-ts-company-name="Test"
   data-ts-company-id="123"
   data-ts-email="test@test.com"
   data-ts-non-editable-email="true"
   data-ts-coupon="SPECIAL-COUPON"
   data-ts-payload="secured-encrypted-string-here"></button>

In the above example, a payload is used to pass your customer’s data as an encrypted serialized string. You can also force the checkout form to make the customer's email address non-editable.

JavaScript integration

Our Widget.js script also opens the possibility of using public JS API for more advanced use cases. With this solution, you have even more control and flexibility in the integration process. It’s a perfect match for JS frameworks like Angular, React, or Vue.js. All public methods are available in the global window.tc variable and use the Promise pattern to handle asynchronous tasks.

To display a product price, use the code below:

tc.getPrice("TC-EXAMPLE-PRODUCT-ID").then(
    (price) => {
        console.log(price);
        // {
        // 	currency: string,
        // 	price: number,
        // 	priceNet: number,
        //	tax: number,
        //	taxName: string,
        //	taxRate: number
        // }
    },
    (error) => console.error(error)
);

To get a full product model, use the code below:

tc.getProduct("TC-EXAMPLE-PRODUCT-ID").then(
    (product) => {
        console.log(product);
        // {
        //     id: string,
        //     name: string,
        //     description: string,
        //     logoUrl: string,
        //     recurring: boolean,
        //     type: 'PRODUCT_TYPE_VAULTED', 'PRODUCT_TYPE_RECURRING', 'PRODUCT_TYPE_ONETIME',
        //     chargeFrequency: null | 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'HALF_YEARLY', 'YEARLY',
        //     price: {
        //         currency: string,
        //         price: number,
        //         priceNet: number,
        //         tax: number,
        //         taxName: string,
        //         taxRate: number
        //     }
        // }
    },
    (error) => console.error(error)
);

To start a payment for a given product, use the code below:

tc.buy("TC-EXAMPLE-PRODUCT-ID").then(
    () => {
        console.log('payment started');
    },
    (error) => console.error(error)
);

By default, a payment form will replace the current page. If you prefer to open it in a pop-up view, pass an additional parameter:

tc.buy("TC-EXAMPLE-PRODUCT-ID", { popup: true }).then(
    (data) => {
        console.log(data);
        // {
        //     type: 'CLOSE' | 'TRANSACTION',
        //     message: string,
        //     transaction null | {
        //         id: string,
        //         email: string,
        //         url: string
        //     }
        // }
    },
    (error) => console.error(error)
);

Not all payment methods are available in this mode. For example, Apple Pay is not allowed in a pop-up view.

You can also pass additional information about the customer if you want to use prefilled details. Please see the full example below:

tc.buy("TC-EXAMPLE-PRODUCT-ID", {
    firstName: 'Test',
    lastName: 'Test',
    companyName: 'Test',
    companyId: '123',
    zipCode: '18951',
    email: 'test@test.com',
    nonEditableEmail: true,
    coupon: 'SPECIAL-COUPON',
    payload: 'secured-encrypted-string-here'
}).then(
    () => {
        console.log('payment started');
    },
    (error) => console.error(error)
);

Please note, the second options argument is optional and can be skipped.

Payload

A Payload is an encrypted serialized string used to pass various types of data, such as internal order reference numbers, licenses, products purchased by customers, and user IDs. The maximum length of the payload string is 5000 characters. After a successful transaction, you can obtain the Payload through webhooks or by using the Retrieve Transactions endpoint. Additionally, the Edit Existing Payload endpoint allows updating existing Payloads.