Basket counts and other things
We recommend building-in some controls to enable/disable UB Checkout. We also provide a way to interrogate the basket to return data you can use in your app, should you wish to do that.
Database flags for controlling the service
We recommend that you build-in the ability to control when UB is active. The specific architecture or design of this within your system is up to you, but will most likely take the form of a set of database flags/switches.
Before UB becomes live on your system we will agree a period of limited testing where a subset of shops or users are active.
Each switch will enable two states:
UB active – A button or link in your UI, labelled ‘Add to basket’ which will place the item into the UB basket using the UB formatted URL.
UB inactive – A button or link in your UI labelled ‘Buy now’ (or similar – whatever is currently used) that will pass the user out to the retailer’s website.
We recommend switches for the following cases:
- Global – UB active/inactive.
- Per shop
- Per user
- Per group of users (VIP, Beta, etc.)
Extracting data from the basket
JavaScript##
It is possible to retrieve basket data from a website which UB Checkout is embedded by using JSONP.
var script = document.createElement('script');
script.src = 'https://ub.io/basket.json?partnerDomain=your_identifier&jsonp=myFunctionName";
document.head.appendChild(script);
function myFunctionName(basket) {
...
}
Apps##
Apps implementing UB Checkout are able to extract the basket data from the webview. (For example a count of the items currently in your user's basket.)
The basket object is always available as window.getBasket()
and can be extracted as follows:
iOS##
webview stringByEvaluatingJavaScriptFromString:@"window.getBasket()";
Android##
webview.evaluateJavascript(“window.getBasket()”);
This can be called at any time. The basket is available once the webpage showing the basket has completed loading. If the basket is empty, the window.basket object will be null.
It is also possible to define a callback function which can automatically receive updates to the basket when they occur in the app. This is done by overriding the following function.
window.basketLoaded(basket)
The basket is a JSON object with the following format:
basket
baseCurrency: STRING
itemsTotal: NUMBER
shipping:
text: STRING
value: NUMBER
subtotal:
text: STRING
value: NUMBER
total:
text: STRING
value: NUMBER
transactions[]:
...
We plan to support a method that will allow your users to add multiple items to the basket with a single interaction – to support ‘shop the look,’ for example.
Note. This option will be available in production shortly, and these docs will be updated accordingly. Please check with Mark if you are unsure about its availability.
Updated about 2 months ago