The tp.offer.startCheckout() function is used to programmatically initiate a checkout flow in Piano's subscription management system. This method is used when the checkout is not expected to start automatically. For example, in an Identity Linking implementation case, this will method will initiate the checkout process after the user has gone through the registration process on the publisher’s user management system.
Parameters
The parameter passed to the tp.offer.startCheckout method is a JSON object that may contain the following values:
{
termId(string, required): The ID of the term that should be automatically selected on showing the offer,
offerId(string, required): The ID of the offer presented to the user,
templateId(string, optional): The ID of the template being used to present the offer,
templateVariantId(string, optional): The ID of the variant of the offer template,
checkoutFlowId(string, optional): The ID of the checkout flow for passwordless checkout,
formNameByTermId(object, optional): The key-value pair of the termId and the custom form ID (i.e. '{"<term_id>":"<form_id>"}'),
trackingId(string, optional): Used for reporting the conversion based on the experience initially fired to start checkout
experienceId(string, optional): Defines the experience to be used in reporting for the conversion
}
Usage
The basic format for using the function is the following format:
tp.offer.startCheckout({offerId: "Your_Offer_ID", termId: "Your_Term_ID"});
Here, "Your_Offer_ID" and "Your_Term_ID" should be replaced with the IDs of the specific offer and term you want to initiate checkout for. Checkout will start with the default template and populate with the offer and term that has been described. To extend that to include different forms that you would need to have filled in depending on the term selected, the formNameByTermId would be used as follows
tp.offer.startCheckout({offerId: "Your_Offer_ID", termId: "Your_Term_ID", formNameByTermId: '{"<term_id>":"<form_id>"}'});
In the Identity Linking implementation case, you can simply pass the data object - params received in the loginRequired callback as described here. The object contains the required (and some optional) parameters necessary to start the checkout. In the case that login is processed off the original url and the user is returned to the url to continue checkout, it is possible to store the params data in a cookie and read from that cookie in order to continue checkout at the appropriate moment. This example is also described in the Identity Linking loginRequired documentation here.
Please note: The tp.offer.startCheckout() function is part of Piano's JavaScript library and requires the Piano JavaScript to be correctly implemented on your site. This should not be confused with the startCheckout method used in templates as described here