StoreOS checkout guide
How checkout works — cart, discounts, delivery, and placing an order with StoreOS.
What checkout is
Checkout is when a customer turns their cart into a real order on StoreOS. Your app owns the cart UI and checkout form; StoreOS validates inventory, applies discounts (codes and automatic offers), calculates delivery, and creates the invoice.
Cart (your app) → previewDiscounts (optional) → createOrder → Order on StoreOSWho does what
| Step | Your app | StoreOS API |
|---|---|---|
| Cart items | Track productId, variantId, qty | — |
| Offer badges | "Buy 1 Get 1", free-shipping bar | activeOffers |
| Shipping form | Collect address, delivery area | — |
| Delivery fee | Display total | getTenant() → charges |
| Discounts + code field | Summary rows, apply button | previewDiscounts |
| Place order button | Submit | createOrder |
| Confirmation page | Show invoiceUID | Returns order object |
Flow
- Shipping address —
caption,latitude,longitude(location reference) - Delivery area — e.g.
DHAKAorOUTSIDE_CAPITAL(affects fee) - Delivery charge — read from
tenant.chargesviagetTenant() - Discounts (optional) —
previewDiscountswith line items, delivery area, and the code the customer typed - Payment method —
COD(cash on delivery) orONLINE createOrder— submits everything to StoreOS- Redirect —
/order-confirmation/[invoiceUID]
Discounts
Merchants create discounts in the console under Discounts. There are four types, each either a code the customer types or automatic:
| Type | Example |
|---|---|
| Amount off products | 20% off the Summer collection |
| Amount off order | ৳200 off orders over ৳2,000 |
| Buy X get Y | Buy 1 shirt, get 1 free |
| Free shipping | Free delivery in Dhaka over ৳1,500 |
createOrder always applies eligible automatic discounts and the couponCode you send. Call previewDiscounts with the same input to show the breakdown before the customer places the order. Its hints tell the customer what's missing ("Add 1 more item to get 1 free"), and codeError explains why a code didn't apply.
Cart
Save the shopper cart with upsertCart, or use useCart from the React SDK. Pass the same cartId to createOrder so the cart is marked converted.
// Example cart line — display fields plus the ids checkout needs
{
productId: "…",
variantId: "…",
quantity: 2,
product: { name: "Linen shirt", unitPrice: 1200 },
}SDK example
import { store } from "@/lib/store";
// 1. Load delivery rules
const tenant = await store.getTenant();
// 2. Preview discounts (automatic offers + optional code)
const preview = await store.previewDiscounts({
lineItems: cartItems,
code: "SAVE10",
deliveryArea: "DHAKA",
});
// 3. Place order — StoreOS applies the same discounts
const { order, authToken } = await store.createOrder({
lineItems: cartItems,
shippingAddress: {
caption: "House 12, Road 5, Dhaka",
latitude: 23.8103,
longitude: 90.4125,
},
paymentMethod: "COD",
deliveryArea: "DHAKA",
// Required when the region lists sub-areas in tenant.charges.deliveryRegions
deliverySubArea: "Mirpur",
couponCode: preview.code,
cartId,
});
// 4. Redirect — order.invoiceUID is the public order ID
router.push(`/order-confirmation/${order.invoiceUID}`);Guest vs logged-in
| Customer | What to do |
|---|---|
| Guest | Call createOrder without a token; pass name/phone in order input if required |
| Logged in | store.setAccessToken() before checkout — order links to their account |
| Guest after order | API may return authToken — SDK saves it for getOrder() tracking |
Payment methods
| Value | Meaning |
|---|---|
COD | Cash on delivery — no payment gateway needed |
ONLINE | Online payment — your app integrates the payment provider |