Buy button
A button for one product, on any page, with no server: the checkout opens over your page for that product at its stored price.
The snippet
Your product's ID and your publishable key; the dashboard's Website integration page fills both in for you. Add your website to Allowed websites first: anywhere else the button shows the buyer a short message, and your onError gets origin_not_allowed.
<script src="https://js.shipbill.io/v1/shipbill.js"></script>
<button data-shipbill-product="prod_…">Buy Pro plan</button>
<script>
ShipBill.init("pk_live_…"); // publishable key: safe in a web page
</script>A page with three products has three buttons with three product IDs: ShipBill knows which was clicked because each carries its own.
Attributes
| Attribute | Meaning |
|---|---|
data-shipbill-product | The product's ID. It must be active; a button can't set a price. |
data-shipbill-quantity | 1 by default. A subscription renews at this quantity. |
data-shipbill-email | Fills in the buyer's email. They can still change it. |
data-shipbill-reference | Your ID for the buyer, returned on every event for the purchase. |
data-shipbill-theme | light, dark, or system: the checkout's look over this page, when Settings → Checkout lets your website choose. |
data-shipbill-coupon | A discount code applied when the checkout opens; the buyer can remove it. See Discounts. |
data-shipbill-addons | Your own choice of the product's add-ons, prod_x,prod_y:2: each ID, with a quantity after a colon. The checkout then shows no boxes; empty, none. Without it, the product's add-ons offered at the checkout are boxes. With the next release of shipbill.js. See Add-ons. |
Add-ons
A product's add-ons are other products of yours sold with it. The buyer gets them in one of two ways:
- Your own selection. Your page or server picks them: a checkout's
line_items, after the product; a buy button'sdata-shipbill-addons. The checkout shows those items and no boxes. ShipBill checks each is one of the product's add-ons, so a page can't attach another product to a cheaper one, and prices it. - ShipBill's selection. An add-on marked Offer at the checkout is a box with its price, unticked, beside the items already chosen. Ticking prices the order again: its tax, its currency, and the payment methods that can take it. A buy button offers the product's unless its page sends its own selection; a checkout your server creates offers them with
offer_addons: true; a payment link offers those it was made to.
On a subscription, a one-time product is charged with the first payment only. A subscription product with the subscription's period and currency is a recurring add-on: it renews with it, each period at its own price. The subscriber, on their page, or you, on the subscription's page or with POST /v1/subscriptions/{id}/addons/{product}, can remove one at the end of the period or add one from the next renewal, with nothing charged or refunded at the change. What each provider takes on a subscription:
| Providers | Add-ons on a subscription |
|---|---|
| Stripe, Dodo Payments, Paddle, Cryptomus, OxaPay, NOWPayments, Midtrans, Xendit, DOKU, Square, SumUp, and the test provider | One-time and recurring add-ons; a recurring one can be removed or added later |
| Polar, Creem | Neither: its bundles are one-time, so a renewal would charge the add-ons again |
| Whop | One-time add-ons, with the first payment; no recurring ones, since a membership's price can't change |
A subscription with add-ons that none of your enabled providers can take is refused with items_unavailable, naming them.
Events on the page
The button sends shipbill:ready, shipbill:complete, shipbill:close, and shipbill:error DOM events, which bubble to document:
document.addEventListener("shipbill:complete", () => {
showThanks(); // fulfilment still waits for your webhook
});Without the attributes
ShipBill.checkout.open({ product: "prod_…", customerEmail: "[email protected]" });