Cart & Checkout
Checkout
Create orders from the cart
Create Order
const order = await client.checkout.createOrder({
email: '[email protected]',
phone: '+420123456789',
shippingAddress: {
firstName: 'Jan',
lastName: 'Novak',
street: 'Vodickova 12',
city: 'Praha',
zip: '11000',
country: 'CZ',
},
billingAddress: {
firstName: 'Jan',
lastName: 'Novak',
street: 'Vodickova 12',
city: 'Praha',
zip: '11000',
country: 'CZ',
},
customerNote: 'Ring the bell twice',
redeemLoyaltyPoints: 500, // optional — redeem loyalty points
});After a successful checkout:
- Cart is automatically cleared
order:createdandcart:clearedevents are emitted- Cart session is reset
Checkout Input
| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Customer email |
phone | string | No | Customer phone |
shippingAddress | Address | Yes | Shipping address |
billingAddress | Address | No | Billing (defaults to shipping) |
customerNote | string | No | Note from customer |
redeemLoyaltyPoints | number | No | Points to redeem (1-1,000,000) |
Security
All financial operations are atomic and race-condition safe:
- Stock is decremented atomically — overselling is impossible
- Gift cards use conditional balance check — double-spend blocked
- Discount codes with usage limits are claimed atomically
- Loyalty points are deducted inside the same transaction
- Cart is verified non-empty inside the transaction
Guest checkout may be disabled by the shop admin. If allowGuestCheckout is false, customers must register before checking out.
Events
client.on('order:created', (order) => {
router.push(`/thank-you?order=${order.orderNumber}`);
});