Contents

Appendix C. Developer Reference developer

Abstract

For template and extension developers: starting a checkout from markup, using Paddle.js alongside PaddleSubs, overriding the layouts, and the data PaddleSubs keeps in Paddle.

Starting a Checkout From Markup

On a page that loads PaddleSubs' checkout script, any element with data-paddlesubs-checkout opens Paddle's overlay checkout when clicked:

<button type="button" data-paddlesubs-checkout data-price-id="pri_01h...">Buy</button>
data-price-id (required)

The Paddle price to buy.

data-product-id

The Paddle product, passed on to the Purchase Complete page.

data-discount-id

A Paddle discount (dsc_…) to apply.

data-license-id

A license this purchase renews. It is sent as customData.paddlesubs_license_id, and checked against the buyer when the purchase is processed.

The product page loads the script. Anywhere else (a module, a template override, a custom component view), load it from PHP before the page is rendered:

use CodeAlfa\Component\PaddleSubs\Administrator\Helper\PaddleJs;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;

$user = Factory::getApplication()->getIdentity();

PaddleJs::useCheckout([
    'customerEmail' => $user->guest ? '' : $user->email,
    'successUrl'    => Route::_('index.php?option=com_paddlesubs&view=checkoutComplete', false),
]);

The options, all optional, are customerEmail (prefilled in the checkout), successUrl (where to go after paying; the transaction, checkout, price and product IDs are added to it), discountId, licenseId and theme (light or dark). Attributes on an element win over these page-wide values.

The product page adds two more when the signed-in customer qualifies for an automatic discount: discountedCheckoutUrl and token (Joomla's form token). A click then posts price_id and license_id to index.php?option=com_paddlesubs&task=checkout.discounted, which works the discount out again for the logged-in user, creates the Paddle transaction with it and answers {"transactionId": "txn_…"}; the overlay then opens that transaction. An answer of {"transactionId": null}, or any error, opens the usual checkout. A trigger with its own data-discount-id never asks.

Tip

For a site owner without PHP, {pslink} with ?price= leads to the product page with one price, which does the same with no code; see the section called “Link to a Product Page”.