Hosted checkout
Your server creates a checkout for exactly what is being bought, then sends the buyer to ShipBill's checkout page. When they've paid, they come back to your site.
1. Create the checkout on your server
Name the products in line_items (or a custom amount: amount and currency), your own ID in reference, and where the buyer goes afterwards:
import { ShipBill } from "@shipbill/node";
const shipbill = new ShipBill(process.env.SHIPBILL_SECRET_KEY);
// In your "Buy" route, after your own checks:
const session = await shipbill.checkout.sessions.create({
line_items: [{ product: "prod_…", quantity: 1 }],
reference: order.id, // your ID: it comes back on every event
customer: { email: user.email }, // optional: filled in, and fixed on the checkout
success_url: "https://example.com/thanks", // ShipBill adds ?session_id=cs_…
cancel_url: "https://example.com/pricing",
});
// Send the buyer there: an HTTP 303 to session.url.
response.redirect(303, session.url);A checkout lasts 24 hours unless you set expires_in (30 minutes to 24 hours). Supplying the customer's email fills it in and fixes it on the checkout.
2. Send the buyer to it
Redirect to the session's url. The buyer chooses a method, pays, and sees ShipBill's confirmation with a button back to your success_url, to which ShipBill adds ?session_id=cs_….
3. When the buyer returns
The return can arrive a moment before your webhook. To show "paid" straight away, ask ShipBill — and check that the checkout is this buyer's, so nobody can paste someone else's session ID:
// GET /thanks?session_id=cs_…
const session = await shipbill.checkout.sessions.retrieve(request.query.session_id);
if (session.reference !== currentOrder.id) return forbidden(); // someone else's checkout
if (session.payment_status === "paid") {
// Paid: show it now. The webhook may still be on its way; apply it once, whichever comes first.
}4. Fulfil from the webhook
Your endpoint receives payment.succeeded with the payment, its reference, and its line_items. See Webhooks for checking it.
Custom amounts
Your server, with a secret key, can send amount, currency, and description instead of line_items. It's one line and a one-time payment, and no coupon applies to it. Each provider takes it within its own currencies and limits.
| Takes a custom amount | Never takes one |
|---|---|
| Stripe, Whop, Cryptomus, OxaPay, NOWPayments, Midtrans, Xendit, DOKU, Square, SumUp, and the test provider, in test mode | Polar, Dodo Payments, Creem, Paddle |
A merchant of record is the legal seller, so it charges the tax by the kind of product and sells only what it has reviewed. ShipBill makes its copy of a product at the first sale, and needs a product to copy.
When an amount repeats, such as top-ups of 5, 25, and 100, make a product for each and send line_items. Every provider takes a product, merchants of record included, and each sale shows the product's name in the dashboard.
If every provider enabled in the mode is a merchant of record, the API refuses a custom amount with custom_amount_unavailable. If none suits the buyer, by their currency or country, the checkout says "Payments aren't available for this checkout right now."
Several products, or several of one
line_items takes up to 20 of your products, each with a quantity from 1 to 99, all in one currency. A subscription is the first line, with only its own add-ons after it: it renews at its quantity, and its one-time add-ons are charged with the first payment only. Polar and Creem can't take a subscription with add-ons. Your invoice and the buyer's receipt list every line. Each provider is sent the order as it takes one:
| Providers | Several products | Several of one |
|---|---|---|
| Stripe, Cryptomus, OxaPay, NOWPayments, Midtrans, Xendit, DOKU, Square, SumUp, and the test provider | The total, with each line on ShipBill's checkout and invoice | The total, with each line on ShipBill's checkout and invoice |
| Polar, Creem | A product of its own named for the set, such as "Product A + Add-on X" | Its own units: "3 × Product A" |
| Dodo Payments, Paddle | Each line, at its price and quantity | Each line, at its price and quantity |
| Whop | One price: the total | One price: the total |
A copy named for a set is made once and reused for the same set, at most 50 at each provider; past that, a set goes to your other providers. When a line's price after a coupon doesn't divide by its quantity, or one unit is below a provider's least amount, it goes as one unit at its total, named "Product A × 3".
If no provider enabled in the mode can take the products together, because each is limited to providers the others aren't, or a set needs a copy where the only providers that could take it already keep 50, the API refuses the checkout with items_unavailable, saying which.
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.