Skip to main content

Overview

The checkout() 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 to ApiResponse<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
Email Validation:
  • Must be a valid email address format
Coupon Validation (if provided):
  • 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

The Order object in the response contains:

Affiliate Tracking

The checkout function automatically includes affiliate tracking if an affiliate cookie (kmrza_ref) is present:
The affiliate cookie is set when customers visit your store through an affiliate link.

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 needed

Next Steps

Basket Management

Learn how to manage cart items

Products

Display and fetch product information
Last modified on November 27, 2025