Skip to content

Hierarchical Checkout (Flat)

proceedbackproceedbackchild.exitbackchangePaymentsubmitOrderbackproceedchangePaymentrestartCartShippingPaymentReviewShippingPaidConfirmation
1
Cart
2
Shipping
3
Payment
4
Review
5
Done

Wireless Headphones

$99.99 each

$99.99

Bluetooth Speaker

$49.99 each

$99.98
Total$199.97
import { createHSM } from "matchina/hsm";
export function createFlatCheckoutMachine() {
return createHSM({
initial: "Cart",
states: {
Cart: {
on: { proceed: "Shipping" }
},
Shipping: {
on: {
back: "Cart",
proceed: "Payment"
}
},
Payment: {
initial: "MethodEntry",
states: {
MethodEntry: {
on: { authorize: "Authorizing" }
},
Authorizing: {
on: {
authRequired: "AuthChallenge",
authSucceeded: "Authorized",
authFailed: "AuthorizationError"
}
},
AuthChallenge: {
on: {
authSucceeded: "Authorized",
authFailed: "AuthorizationError"
}
},
AuthorizationError: {
on: { retry: "MethodEntry" }
},
Authorized: {
// Final payment state - child.exit automatically triggered
}
},
on: {
back: "Shipping",
"child.exit": "Review"
}
},
Review: {
on: {
back: "ShippingPaid",
changePayment: "Payment",
submitOrder: "Confirmation"
}
},
ShippingPaid: {
on: {
back: "Cart",
proceed: "Review",
changePayment: "Payment"
}
},
Confirmation: {
on: { restart: "Cart" }
}
}
});
}