Checkout with expiration using the signature in InLine Cart
Overview
Use the expiration key to define the validity of a buy-link. The expiration needs to be signed before using the checkout in InLine Cart. In case the expiration is overdue, then the signature is considered invalid.
Use case
- Add an HTML link or button on your page like the one below.
- Create a JavaScript click handler to execute the Inline Client desired methods.
- In order to set expiration, use the TwoCoInlineCart.cart.setExpiration(TIMESTAMP) method.
- Use the TwoCoInlineCart.products.add({code, quantity, options, price}) method or the TwoCoInlineCart.products.addMany(products) method to prepare your product(s).
- Below it is a signature token request payload for this example. A success response contains a JSON with the property “signature“ which needs to be used to the next step to set the signature using the TwoCoInlineCart method.
{
"merchant": "AVLRNG",
"currency": "USD",
"expiration": 2524608000,
"products": [
{
"code": "74B8E17CC0"
}
]
}
In this example we used a timestamp for January 1st, 2050 as an example. The signature obtained is 16ef22d988d356356ee2437d26114370e29e6293fb4f2e8b58cefad31020950d.
6. Use the TwoCoInlineCart.cart.setExpiration(2524608000) method to set the expiration.
7. Use the TwoCoInlineCart.cart.setSignature('16ef22d988d356356ee2437d26114370e29e6293fb4f2e8b58cefad31020950d') method to set the signature. It is important that you employ the TwoCoInlineCart.cart.removeAll() method just before the TwoCoInlineCart.products.addMany(products) or TwoCoInlineCart.products.add(product) to clear the products, as the signature is based on the products' definition, or simply request a new signature.
8. Use the TwoCoInlineCart.cart.checkout() method to show the cart on your page.
Sample request
HTML
<a href="#" class="btn btn-success" id="buy-button">Buy bundle now!</a>
JavaScript
window.document
.getElementById('buy-button')
.addEventListener('click', function() {
TwoCoInlineCart.cart.setExpiration(2524608000);
TwoCoInlineCart.products.add({
code: "74B8E17CC0"
});
TwoCoInlineCart.cart.setSignature('16ef22d988d356356ee2437d26114370e29e6293fb4f2e8b58cefad31020950d');
TwoCoInlineCart.cart.checkout();
});