ORBCOMMERCE DOCUMENTATION
A checkout with a page per step
Contact, delivery and payment each on their own address, with the browser's back button, a reload and the provider's return all landing on the right step.
Give each step of the checkout its own page: /checkout/contact, /checkout/delivery,
/checkout/payment. The Cart says which step a buyer may open, your router shows it.
You need a React storefront with a router and a Cart, such as the one from Add to cart. React checkout explains steps on one page first.
1. One route, one component
Every step's page renders the same <Checkout> with the same children. step says which step
this page is, and onStepChange asks for another one. With React Router, as one route
/checkout/:step:
import { useNavigate, useParams } from "react-router";
import type { CommerceCart } from "@orbcart/client";
import {
Checkout,
CheckoutAddress,
CheckoutContact,
CheckoutExtensions,
CheckoutPayment,
CheckoutShipping,
CheckoutStep,
CheckoutSummary,
} from "@orbcart/react";
import "@orbcart/react/styles.css";
export function CheckoutStepPage({ cart }: { cart: CommerceCart }) {
const { step = "contact" } = useParams();
const navigate = useNavigate();
return (
<Checkout
cart={cart}
locale="en-GB"
step={step}
onStepChange={(name) => navigate(`/checkout/${name}`)}
onOrdered={(order) => navigate(`/orders/${order.number}`)}
>
<CheckoutStep name="contact" heading="Contact">
<CheckoutContact />
</CheckoutStep>
<CheckoutStep name="delivery" heading="Delivery">
<CheckoutShipping part="way" />
<CheckoutAddress />
<CheckoutShipping part="methods" />
<CheckoutExtensions />
</CheckoutStep>
<CheckoutStep name="payment" heading="Payment">
<CheckoutPayment />
</CheckoutStep>
<CheckoutSummary />
</Checkout>
);
}A name is what stands in the address, so keep it short and stable. The steps that are not this
page's show as their heading, with one line of what the buyer gave once they are complete.
2. When the checkout asks for another step
onStepChange(name) is called in three cases. Navigate to that step's page in each:
| The buyer | name is |
|---|---|
| pressed "Continue" and the step lacks nothing | the first step that still lacks something |
| pressed "Change" on a complete step, or a notice's button | that step |
| opened a page the Cart does not allow yet | the first step that still lacks something |
The last case covers a bookmarked /checkout/payment with an empty contact. The check runs when
the buyer enters a page. What happens on a page never sends them away from it: a payment page
whose Cart lost something it needs, such as a shipping method that is no longer offered, says
what is missing with a button to the step that asks it.
Navigate to the step's own address, without the query the last page had. After a payment at the
provider the buyer returns with ?payment=…; a next page that kept it would resume that payment
once more.
3. What survives the way between pages
- The Cart. Each step saves on "Continue". The next page reads it again.
- What the buyer typed and did not save, in the tab's
sessionStoragefor that Cart: contact, addresses and answers to the fields you ask. It is there after the back button and after a reload, and gone once the Cart is ordered. - What the checkout last said. A field the runtime refused at the order is marked on the page its notice leads to, and the reason of a declined payment is still said on the payment page.
- Not the card. A provider's field lives on its page, so the buyer types the card on the payment page and orders there. This is why there is no review page after the payment.
What the buyer sees
| Moment | The page shows |
|---|---|
| They press "Continue" | The next step's page, with its heading focused. |
| They press the browser's back button | The step before, with what they gave, ready to change. |
| They reload | The same step, with what they typed. |
| They open the payment page too early | The first step that still lacks something. |
| A payment method needs a phone number | A notice on the payment page with a button to the contact page. |
| The runtime refuses the address at the order | A notice on the payment page with a button to the delivery page, the field marked there. |
| They come back from the provider without an order | The payment page, with the reason. |
| They come back with a filled Cart | The payment page: one click from the order. |
Next
- React checkout: every prop, the regions, labels and theming.
- Express checkout: the wallets' buttons before the first step.
- A checkout without React: the store these pages share.
A checkout without React
Your own checkout page in plain TypeScript, with the checkout store of @orbcart/client. Details, the binding total, a card field and every outcome of the order button.
Free shipping and a welcome code
Free standard shipping from €50 without a code, 10 % off with WELCOME10, a code field in the bag, and a test that proves both.