Overview
Thecheckout() function creates an order from the current basket and automatically redirects the customer to Komerza’s hosted checkout page to complete payment.
The checkout function validates the basket, creates an order, and
automatically redirects to the payment page. No manual redirect handling
needed.
Basic Usage
Parameters
string
required
Customer’s email address for the order. Must be a valid email format.
string
Optional coupon/discount code to apply to the order. Must be 3-32 characters
if provided.
Returns
Returns a Promise that resolves toApiResponse<Order>:
If
success is true, the browser will automatically redirect to the
checkout page. The response is mainly useful for error handling.Validation
The checkout function performs validation before creating the order: Basket Validation:- Basket cannot be empty
- All items must have valid product and variant IDs
- Must be a valid email address format
- Must be at least 3 characters
- Cannot exceed 32 characters
Simple Example
Complete Example with Validation
Error Handling
Common error scenarios and how to handle them:Empty Basket
Validation Errors
General Errors
Response Object
TheOrder object in the response contains:
Affiliate Tracking
The checkout function automatically includes affiliate tracking if an affiliate cookie (kmrza_ref) is present:
Best Practices
Validate before submission - Check email format client-side for instant feedback Create basket backups - Save basket state before checkout to restore if payment fails Disable during processing - Prevent double-submissions by disabling the checkout button Handle all error cases - Account for empty basket, validation errors, and network failures Show loading states - Display progress indicators while checkout is processing Don’t auto-clear basket - The basket persists after checkout - clear it manually after payment confirmation if neededNext Steps
Basket Management
Learn how to manage cart items
Products
Display and fetch product information