Skip to main content

What checkout() does

1

Checks the basket and the form

The basket can’t be empty, the email address has to be valid, and a coupon code, if you pass one, has to be 3 to 32 characters. Nothing is sent until these pass.
2

Runs a bot check

Most buyers never see it. Now and then one is asked to confirm they’re human in a small dialog. See Security.
3

Creates the order

Komerza prices it from the basket’s product IDs and quantities, and checks stock, quantity limits and the coupon.
4

Redirects to the hosted checkout

The browser goes to checkout.komerza.com, where the buyer chooses a payment method, answers any custom fields, links Discord if the product needs it, and pays.
You don’t redirect anyone yourself. By the time checkout() resolves successfully, the page is already on its way to the hosted checkout.

Parameters

Returns

Promise<ApiResponse<Order>>. The call doesn’t throw when checkout fails - it resolves with success: false and says why:

When checkout fails

Show invalidFields next to the field they name, and message for everything else. Both are written for the buyer, so you can display them as they are. Caught in the browser, before anything is sent: Refused by Komerza when it creates the order: A coupon that doesn’t apply fails the whole checkout - the order isn’t created without it - so the buyer can fix or remove the code and try again. Network problems resolve too: after 15 seconds without an answer, message is Request timed out.

The basket afterwards

checkout() doesn’t empty the basket, and your storefront isn’t told when the buyer finishes paying. To give buyers a fresh cart once they’ve ordered, clear it as soon as checkout() succeeds:
The trade-off: a buyer who backs out of paying comes back to an empty cart. Leave the call out if you’d rather keep it.

Affiliates

If the buyer arrived through an affiliate link, checkout() credits the affiliate automatically. There’s nothing to pass. See Affiliate links.

Complete example

Good practice

  • Show progress and block double clicks. The bot check and order creation can take a few seconds. Disable the button until checkout() resolves.
  • Check stock and limits while the buyer shops, not at checkout - see what the basket doesn’t check.
  • Keep subscriptions apart from one-time products. buyNow() is the simple way.
  • Only call checkout() from a user action, like a form submit - never on page load.

Next

Basket

Managing what goes into the order

Built-in features

Affiliates, analytics and security
Last modified on October 15, 2026