Functions

initialize()

The initialize function is used to configure and bootstrap Tipser Script. Until it's called, no HTML replacements will be performed. It accepts two arguments:

tipserScript.initialize(posId: string, config?: object)
  • posId (required) - a unique Tipser publisher identifier. Must be specified in order to show your personalized store, show discounted product prices according to your current campaigns and - most important of all - grant you commissions for every purchase on your site! If you are not sure where to get it from, contact your account manager.
  • config - allows you to specify how Tipser Script will look and behave on your site. See the Configuration section that describes most common configuration options you need to know, while the complete index of all the supported configuration options can be found further in the API reference.

πŸ“˜

Please make sure that tipserScript.initialize() function is called only once, after the page is loaded. If you need to use the Tipser Script instance in several places in your code, feel free
to assign it to a variable (even a global one, if needed) and refer to it further in the code.

For example:

window.tipserScriptInstance = tipserScript.initialize(YOUR_POS_ID);

And then at some other place in the code:

const onButtonClicked = () => {
    window.tipserScriptInstance.goToProduct(productId);
}

In most cases, however, initializing Tipser Script in-place (without assigning it to a variable) will be just enough!


Internal functions

In case you need to open Tipser dialogs from the code or perform operations like adding a Tipser product to cart, we provide a set of JavaScript functions that serve that purpose.

πŸ“˜

Typical use case for calling the actions described here is when you want to build your own implementation of some of the components, e.g. the product tile component or the cart icon component.

All the below functions are accessible from the Tipser Script instance:

const tipserScriptInstance = tipserScript.initialize(posId, options);
tipserScriptInstance.goToProduct(productId);

goToProduct() function

tipserScriptInstance.goToProduct(productId);

Opens the product modal dialog for a product with a given Tipser product id. Alternatively, redirects to the URL defined in customUrls.baseProductUrl configuration option if specified.

goToCheckout() function

tipserScriptInstance.goToCheckout();

Opens the checkout modal dialog. Alternatively, redirects to the URL defined in customUrls.checkoutUrl configuration option if specified.

addToCart(productId) function

tipserScriptInstance.addToCart(productId).then(() => {
 console.log("adding to cart successful");
}).catch((e) => {
 console.log("adding to cart failed", e)
});

Adds to cart a product with a given Tipser product id. Returns a promise that will succeed or reject depending on the status of that operation.

removeFromCart(productId) function

tipserScriptInstance.removeFromCart(productId).then(() => {
    console.log("removing from cart successful");
}).catch((e) => {
    console.log("removing from cart failed", e)
});

Adds to cart a product with a given Tipser product id. Returns a promise that will succeed or reject depending on the status of that operation.

getCartItems() function

tipserScriptInstance.getCartItems().then((cartItems) => {
    console.log("cart items: ", cartItems)
}).catch((e) => {
    console.log("failed to get cart items", e)
});

Returns a Promise that will eventually return a list of all Tipser products currently in the shopping cart.

goToDirectToCheckout(productId)

tipserScriptInstance.goToDirectToCheckout(productId);

Opens a product dialog optimized for the direct checkout. The shopper will be moved directly to the payment site upon pressing "Buy now", skipping the cart and checkout pages.

addToCartAndGoToCheckout(productId) function

tipserScriptInstance.addToCartAndGoToCheckout(productId).then(() => {
    console.log("add to cart and go to checkout successful");
}).catch((e) => {
    console.log("add to cart and go to checkout  failed", e)
});

Adds to cart a product with a given Tipser product id and then opens the checkout modal dialog. Alternatively, redirects to the URL defined in customUrls.checkoutUrl configuration option if specified. Returns a promise that will succeed or reject depending on the status of that operation.