# 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.

> **Fulfil on the webhook, not on the redirect**
>
> The buyer coming back to your page, or the checkout's `onComplete`, only says they were there. Deliver the order when your server receives a verified [webhook](https://shipbill.io/docs/webhooks), or after your server asks ShipBill for the checkout and finds it paid.

## 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`.

```html
<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](https://shipbill.io/docs/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](https://shipbill.io/docs/hosted-checkout#add-ons). |

> **A reference set in a page can be edited by the buyer**
>
> They could pay to upgrade someone else's account, or pick the cheaper of your products — never change a price, or get anything without paying. When you must be certain who is paying, create the checkout on your server: see [Embedded checkout](https://shipbill.io/docs/embedded-checkout) and [Selling subscriptions to signed-in users](https://shipbill.io/docs/selling-subscriptions).

## 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's `data-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`:

```js
document.addEventListener("shipbill:complete", () => {
  showThanks(); // fulfilment still waits for your webhook
});
```

## Without the attributes

```js
ShipBill.checkout.open({ product: "prod_…", customerEmail: "ana@example.com" });
```

Last checked against the product on 31 October 2026.
