Checkout Integration Guide
This guide covers the complete checkout flow for physical products, including cart validation, shipping calculation, and payment processing. Follow this guide to avoid common pitfalls.Critical Concepts
Frontend Displays, Backend Calculates
All Amounts Are in Cents
Every monetary value in the Khaime API is in cents (smallest currency unit).Shipping is Calculated Server-Side
Shipping fees are calculated by the backend based on:- Merchant’s shipping rules configuration
- Delivery address (country, state, zip code)
- Cart contents (weight, dimensions, quantity)
- Shipping method selected
Shipping Rules System
Merchants can configure multiple shipping rules that apply to different destinations. The API evaluates all rules and returns both the matched rule and available options.Shipping Rule Types
Charge Types
API Response Structure
When validating a cart, the response includes shipping details inpricing_summary:
Example Response
The location Field
For specific_locations rules, the customer must select a merchant-defined location (city, area, or zone). This is separate from the city field:
Send the selected location in
delivery_details.address[0].location:
location is omitted, the backend falls back to matching against city.
Displaying Shipping Options
Whenavailable_destinations has multiple options, let users choose their shipping method:
How Shipping Selection Works
Shipping rules are selected during cart validation, not payment intent. Correct Flow:- The
locationfield tells the backend whichspecific_locationsrule to match - The
cart_unique_idhas the shipping fee cached - don’t overwrite it - Payment intent uses the cached shipping from the
cart_unique_id
Rule Configuration Examples
Checkout Flow Overview
Step 1: Build Cart Items
Cart items must include specific fields. The requirements differ based on whether products have variations.Cart Item Structure
Building Cart Items Correctly
Step 2: Validate Cart with Shipping Address
Call cart validation WHEN THE USER SUBMITS THEIR SHIPPING ADDRESS, not when they click “Pay”. This ensures they see the full total (including shipping) before entering payment details.Delivery Details Structure
Validate Cart API Call
Cart Validation Response
Extract Shipping and Update UI
Step 3: Create Payment Intent
After cart validation, create a payment intent when the user is ready to pay.Payment Intent Request
Payment Intent Response
Step 4: Render Payment Element
UseKhaime.confirmPayment() to render the Stripe Payment Element.
Display Modes
Inline Mode (Recommended for Custom Checkout)
React Integration: Critical Timing Issue
Wrong Approach (Will Fail)
Correct Approach (Use useEffect)
Order Summary: Transparency Best Practices
Always show a clear breakdown of costs:Format Currency Helper
Complete Checkout Flow Example
Troubleshooting
”Container element not found”
Cause:confirmPayment called before React rendered the container.
Fix: Use useEffect to wait for the container to exist. See React Integration.
Amount mismatch between frontend and payment
Cause: Backend adds shipping, fees, or taxes that frontend doesn’t know about. Fix:- Call
validateCartwith delivery details to get shipping - Display
amount_to_payfrom payment intent as the final total - Show shipping as a line item for transparency
”main_variant is not allowed to be empty”
Cause: Sendingmain_variant: '' for a product without variations.
Fix: Only include main_variant and least_sub_variant_id for products where has_variation: true.
Unexpectedly high shipping
Cause: Shipping rules configured in dollars instead of cents, or per-item rates. Fix: Check merchant shipping rules configuration. All amounts must be in cents.Multicurrency Support
Khaime supports 35+ currencies with automatic detection and real-time conversion.How It Works
- Auto-detect currency from customer’s IP (or let them manually select)
- Convert prices using live exchange rates via
/pricing/calculate - Process payment in customer’s currency
- Merchant receives payout in their baseline currency
What Gets Converted Where
The skipConversion Pattern
Implement a formatPrice function that can skip conversion:
Displaying Prices Correctly
Calculating Total When API Doesn’t Provide It
When the API doesn’t return a total but you have shipping, you must manually combine:Detect Customer Currency
Convert Price to Customer’s Currency
Currency Selector Component Pattern
Supported Currencies
Merchant Configuration Checklist
Before going live, verify:- Shipping rates are in cents (450 = 450)
- Shipping zones are configured correctly
- Tax settings are correct for your regions
- Platform fees are understood and accounted for
- Test with various cart sizes and addresses
- Multicurrency: Test with different currencies
- Currency selector is visible and functional
- Prices display correctly after currency conversion
