Adding a checkout to your website: four ways

The four ways to put a checkout on a website, from one snippet to your own payment form, with the code for each and what goes wrong with each.

There are four ways to take payments on your own website: a buy button that opens a checkout over your page, a hosted checkout page you send the buyer to, an embedded checkout that opens in a window on your page, and a custom checkout built on a payments API. They differ in how much work they take, how much of the experience you control, and what breaks when you get them wrong; most sites should start with the first two.

A provider is the payment company that takes the money. Stripe, Paddle, Midtrans, a crypto gateway: whichever you connect, the buyer’s card number or wallet login goes to the provider, never to your website. That single fact shapes all four integrations: your page decides what is being bought, and the provider’s page or fields take the payment.

If you don’t have a website at all, there is a fifth way, the payment link, covered in our guide to getting paid as a freelancer. This guide is for when you do.

The code below uses ShipBill’s API and shipbill.js, because they are the examples we can show working end to end. The four patterns are the same at every payment platform; the names of the calls change, the shape doesn’t.

The four, side by side

Buy button Hosted checkout Embedded checkout Custom checkout
Effort A snippet on the page One API call from your server An API call and a script A full build
Needs a server No Yes Yes Yes
Buyer leaves your page No: a window opens over it Yes, then comes back No: a window opens over it Usually, to the provider’s page
Knows who the buyer is Only their email, typed at checkout Yes, your server sets it Yes, your server sets it Yes
Who designs the payment form The checkout The checkout The checkout You, up to the provider’s own fields
What usually breaks Fulfilling on the browser’s signal The return page treated as proof Same as hosted, plus script loading Every edge case is yours
Good for Selling one product to anyone Most sites with a backend Keeping the buyer on the page A product whose checkout is part of the product

Every one of the four ends the same way: the checkout service (ShipBill here, or the provider if you connect it directly) tells your server the payment succeeded, in a signed message called a webhook. That message is the proof, and it is the one part none of the four lets you skip.

1. The buy button: a snippet, no server

A buy button is five lines of HTML. Load the script, mark a button with the product it sells, and give it your publishable key, a key that is safe to show in a web page because it can only open a checkout for one of your own products at its stored price.

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

When the buyer clicks, the checkout opens in a window over your page. They type their email, choose how to pay, and pay. When it’s done, the page hears about it:

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

Why it’s safe without a server. The price is stored with the product, on the payment platform’s side. The button only says which product; the browser can’t change what it costs. Anyone can open the page’s source and see the product ID, and that’s fine: all they can do with it is buy the product.

What breaks. The shipbill:complete event (or its equivalent anywhere else) only means the buyer reached the end in their browser. A buyer can close the tab before it fires, or a curious one can fire it by hand. If you unlock a download or send a licence key from that event, you will sooner or later give something away. Show a thank-you; deliver on the webhook.

What it can’t do. It doesn’t know who the buyer is in your app. If a signed-in user buys an upgrade with a buy button, you’d have to match them by the email they typed, which may not be the one on their account. For that case, use a server-created checkout.

The full guide is in the buy button docs.

2. The hosted checkout: one call from your server

Your server creates a checkout for this purchase and sends the buyer to the address it gets back. The buyer pays on the checkout page and returns to your success page.

curl https://api.shipbill.io/v1/checkout/sessions \
  -H "Authorization: Bearer $SHIPBILL_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order_1001-checkout" \
  -d '{
    "line_items": [{ "product": "prod_…", "quantity": 1 }],
    "reference": "order_1001",
    "success_url": "https://example.com/thanks"
  }'

Three details in that call do most of the work:

  • The secret key stays on your server. It can do everything, so it never appears in a page.
  • reference is your own ID for this purchase: an order number, or your user’s ID. It comes back on every event about the purchase, so your webhook handler never has to look up which of your orders a payment belongs to.
  • Idempotency-Key makes the call safe to repeat. If your server times out and retries, the second call returns the first checkout instead of creating a second one.

Why most sites should start here. You decide what is bought and for whom on your server, where nobody can tamper with it; the payment form is someone else’s well-tested page; and there is nothing to load or style in your own page.

What breaks. The success page. Arriving at /thanks means the buyer came back, not that they paid: they can open the address by hand, and a payment by bank transfer can still be pending when they return. Treat the success page as a place to say thank you and to show the status your server reads, not as the trigger to deliver.

The full guide is in the hosted checkout docs.

3. The embedded checkout: the hosted one, inside your page

The embedded checkout is the hosted checkout opened in a window over your page instead of on its own. Your server creates the checkout as before, but returns its client token to the page instead of sending the buyer away:

// On your server
const session = await shipbill.checkout.sessions.create({
  line_items: [{ product: "prod_…", quantity: 1 }],
  reference: "order_1001",
  success_url: "https://example.com/thanks",
});
// …answer the page with { clientToken: session.client_token }
// In your page
const { clientToken } = await fetch("/checkout", { method: "POST" }).then((r) => r.json());
ShipBill.checkout.open(clientToken, {
  onComplete: () => showThanks(), // fulfil from the webhook, never from here
});

Why choose it. The buyer never leaves your page, which matters when the purchase is a step inside your product (an upgrade, a top-up, a seat) and a full redirect would lose their place.

What breaks. Everything that breaks the hosted checkout, plus two things of its own: a content security policy or an ad blocker that stops the script from loading, and a page that creates a new checkout on every click, leaving a trail of abandoned sessions. Load the script from the official address, allow it in your policy, and create the checkout when the buyer clicks, not when the page loads.

The full guide is in the embedded checkout docs.

4. The custom checkout: your own page on a payments API

A custom checkout replaces the checkout page with your own. Your server creates a payment for an amount, your page shows the methods you choose, and when the buyer picks one, your server confirms it with the provider. The buyer then either goes to the provider’s page (a bank redirect, a crypto payment page, a wallet) or types their card into the provider’s fields mounted inside your page.

The order of operations, whatever the platform:

  1. Create a payment for the amount and currency, with your reference.
  2. Confirm it with the method the buyer chose.
  3. Hand over to the provider: send the buyer to its page, or mount its fields.
  4. Come back to your page, which shows the status your server reads.
  5. Fulfil from the webhook.

Why choose it. When the checkout is part of your product: a booking flow that asks questions before payment, a platform with its own rules, a design system that a standard checkout breaks.

What breaks. Everything a checkout page normally handles is now yours: a method that isn’t available for this currency, a buyer who pays twice, a redirect that never returns, a payment that is still processing when the buyer comes back, a provider that is down. A custom checkout is the right answer for a small minority of sites, and those sites usually know it.

The steps are in the custom checkout docs.

The part all four share: fulfil on the webhook

Whichever of the four you choose, the buyer’s browser is not a reliable witness. Pages close, connections drop, buyers refresh, and a few people try to fake success. The provider, on the other hand, knows exactly whether it took the money, and your server hears it in a webhook: an HTTP request to an address you choose, signed with a secret only you and the sender know.

A handler that’s safe to put in production does four things:

import express from "express";
import { WebhookSignatureError, webhooks } from "@shipbill/node";

const app = express();

app.post("/webhooks/shipbill", express.raw({ type: "application/json" }), async (req, res) => {
  let event;
  try {
    // 1. Check the signature over the raw body, exactly as received.
    event = webhooks.verify(req.body, req.headers["shipbill-signature"], process.env.SHIPBILL_WEBHOOK_SECRET);
  } catch (error) {
    if (error instanceof WebhookSignatureError) return res.status(400).send(error.message);
    throw error;
  }
  // 2. Skip an event you've already handled: delivery is at least once.
  if (await alreadyHandled(event.id)) return res.sendStatus(200);
  // 3. Act on the event you care about, by your own reference.
  if (event.type === "payment.succeeded") await fulfil(event.data.object.reference);
  await markHandled(event.id);
  // 4. Answer 2xx; queue slow work.
  res.sendStatus(200);
});

If your server is down or answers with an error, ShipBill retries for about three days, after 1 minute, 5 minutes, 30 minutes, 2 hours, and so on, so a deploy at the wrong moment doesn’t lose an order. The details, including how to check the signature by hand in any language, are in the webhooks docs.

What the buyer sees in each

It helps to walk through each one as the buyer, on a phone, because that is where most of them will be.

Buy button. They tap “Buy” on your page. A checkout slides up over the page with the product’s name and price. They type their email, pick a way to pay, and pay. The window closes and your page says thank you. They never saw another address in the browser’s bar, unless the method they chose sends them to their bank or wallet to approve the payment, in which case they come back to your page afterwards.

Hosted checkout. They tap “Buy” and the page changes to the checkout’s address, with your name and logo at the top. They pay, and the browser goes back to your success page. Some buyers like seeing a familiar payment page; others hesitate at a different address. A clear name and logo on the checkout, the same as on your site, settles most of that.

Embedded checkout. The same as the buy button from the buyer’s side, except that it happens inside your app: they upgrade, the window opens, they pay, and they are still on the screen they were using, now with the new plan.

Custom checkout. Whatever you design. A well-built one feels like the rest of your product until the moment of payment, when the buyer either types their card into the provider’s own fields on your page or goes to the provider’s page and comes back. A badly built one is the place where buyers abandon: a method that fails without saying why, or a return page that shows nothing while the payment is still processing.

Wallets, local methods, and the bank’s own page

The four integrations don’t only differ for cards.

  • Apple Pay and Google Pay need the domain that shows the payment button to be registered with the provider. With a buy button, hosted, or embedded checkout, the checkout’s own domain is the one that matters, so the payment platform registers it once and you don’t. With a custom checkout using the provider’s fields on your page, your own domain must be registered.
  • Bank transfers and virtual accounts don’t finish while the buyer waits. The checkout shows the account number or the steps, and the payment arrives minutes or hours later. Your success page must be able to say “we’re waiting for your transfer” without treating it as a failure, and your webhook handler must deliver when the payment arrives, not when the buyer left.
  • Bank redirects and some wallets send the buyer to their bank’s or wallet’s own page to approve the payment. Every integration handles the return the same way: the buyer comes back, and your server checks the status rather than trusting the trip.
  • Crypto shows an address and an exact amount, and confirms when the network does. A buyer who sends the wrong amount, or on the wrong network, is a case your page should explain rather than hide.

If you sell in more than one country, prefer an integration where the checkout keeps the list of methods for you; that is far easier than maintaining it yourself in a custom page. ShipBill’s checkout offers every method you connect, in a fixed order, and sends each one to the provider you choose. It hides no method by the buyer’s country, with one exception: Paddle isn’t offered to buyers in countries under sanctions.

Receipts, invoices, and who the seller is

Every payment should leave the buyer with a receipt, and many buyers need a proper invoice: a numbered document with your business details, theirs, and the tax. With the first three integrations, the checkout platform usually sends both. With a custom checkout, check that yours still does, because it’s easy to build a beautiful payment page that forgets the paperwork.

One exception changes whose name is on the receipt. Some payment companies act as the merchant of record: they become the legal seller and handle the tax, and their name appears on the buyer’s card statement and receipt. If you connect one of those, the tax invoice is theirs, and ShipBill’s document becomes a receipt that names the merchant of record as the seller and says it isn’t a tax invoice (with Creem, ShipBill sends no receipt at all). Nothing about the four integrations changes; only the paperwork does.

Choosing in five questions

  1. Do you have a server? No: buy button (or a payment link). Yes: keep going.
  2. Does it matter who the buyer is in your app? Yes: hosted or embedded, created on your server with their ID as the reference.
  3. Is the purchase a step inside your product? Yes: embedded. No: hosted is less to maintain.
  4. Does a standard checkout break your flow in a way you can name? Yes: custom. “It doesn’t match our brand” is usually not that reason; a booking flow that needs answers before payment is.
  5. Do you need to deliver automatically? Then whichever you chose, write the webhook handler first.

Common mistakes, and the one-line fix for each

Mistake What happens Fix
Delivering on the success page Someone opens /thanks and gets the product Deliver on the verified webhook
Trusting a price sent by the browser A buyer edits the request and pays less Name the product; let the server or the stored price decide
Creating a checkout on page load Hundreds of abandoned checkouts, confusing analytics Create it on click
Parsing the webhook body before checking the signature Every signature fails Verify the raw bytes, then parse
Treating a repeated webhook as a new order Duplicate deliveries Store the event ID and skip repeats
Testing with real cards Real charges, real fees, real refunds Use test mode and test keys

Testing before you go live

Every integration above has a test mode: separate keys (sk_test_…, pk_test_…), separate data, and no real money. Build against test mode, pay a few test checkouts, watch your webhook handler receive them, then switch the keys. A checklist for the switch:

  • [ ] Test keys replaced by live keys, and the secret key only on the server.
  • [ ] A live webhook endpoint added, with its own signing secret.
  • [ ] Your site’s address allowed for the publishable key, if you use a button or the embedded checkout.
  • [ ] One small real payment made and refunded, end to end.

ShipBill is built around these four patterns, with every provider you connect behind the same checkout and the same payment.succeeded webhook, so switching or adding a provider doesn’t change your integration. Whichever platform you use, the order of work is the same: pick the simplest of the four that fits, write the webhook handler, test in test mode, then go live.

Questions

Which checkout converts best?

There is no single answer that holds across sites: a hosted page is well tested and little work, while an embedded checkout keeps the buyer on your page. Start with the simplest one that fits who your buyer is, measure completed payments against started checkouts, and change only if the numbers say so.

Do I need a server to take payments on my website?

No. A payment link or a buy button works on any page, including a static site, because the price is stored with the product and nothing in the browser can change it. You need a server when you must know who the buyer is (a signed-in user) or when you deliver automatically after payment.

Can I build my own payment form and still never touch card numbers?

Yes. A custom checkout collects what you choose on your page and then hands the buyer to the payment company's own page, or mounts its fields inside your page. The card number goes from the buyer's browser to the payment company, never to your server.

ShipBill is one checkout in front of the payment providers you already use. Start free