Contents

Appendix C. Developer Reference

Paddle.js on Your Pages developer

Paddle allows Paddle.Initialize() once per page, and only that call can set the event callback. So PaddleSubs never initializes Paddle in a template or layout: all its scripts go through window.PaddleSubsPaddle, from media/com_paddlesubs/js/paddle-client.js (web asset com_paddlesubs.paddle-client):

PaddleSubsPaddle.initialize(options)

Initializes Paddle with the client-side token and environment from the page's com_paddlesubs.paddle script options, the first time it is called. Returns whether Paddle is ready.

PaddleSubsPaddle.subscribe(listener)

Calls listener(event) for every Paddle.js event, such as checkout.completed, alongside PaddleSubs' own listeners.

If your own code needs Paddle.js on a page where PaddleSubs may also run, use these instead of calling Paddle.Initialize() yourself. From PHP, PaddleJs::useCheckout(), PaddleJs::usePricePreview() and PaddleJs::useProductPrices() load PaddleSubs' scripts with their options.

Price previews fill any element with data-paddlesubs-price-preview data-price-id="pri_…"; add data-recurring="1" to follow the amount with its billing period. The amount is what the price charges every billing period, before tax, also for a price with a trial; with Show estimated tax on, a the tax and the total go into an element with data-paddlesubs-price-tax (left hidden until then) inside the same data-paddlesubs-price card, as in the product.price layout, or else into a small.paddlesubs-price-tax added inside the element. They need PaddleJs::usePricePreview() on the page, which the {psprice} tags and the product page call. On the same page, an element with data-paddlesubs-trial data-price-id="pri_…" and data-amount-text="First year at %s" gets that text, with the paid trial's price before tax, in the visitor's currency, in place of %s.