Checkout
This page is the full checkout knowledge transfer: every listing, the orchestrated Buy-click sequence, the amount-sync matrix, dead-PI recovery, and the completion contract. Amounts are EUR decimal major units and the server totals engine is the only amount authority: the client never supplies an amount anywhere in this flow.
Auth for every endpoint on this page: anon x-client-id (checkout is
guest-capable; the one exception is the store setting
accounts_mode='required', see complete).
SDK module: @cartbase/storefront/api/checkout (+ carts.completeCart from
@cartbase/storefront/api/carts).
The two checkout paths
Orchestrated (recommended, what production storefronts run):
listShippingOptions(cart_id)andlistPaymentProviders(cart_id)render the pickers.- On the Buy click,
prepareCheckout(cart, {address, shipping_method_id, carrier_metadata, payment_provider XOR payment_method_id}): one call, one write, everything or nothing. - For
pp_stripe,stripe.confirmPayment(client_secret); a payment method (bank transfer, COD) skips this step. completeCart(cart)answers{type: "order", order}.
While checkout stays mounted: syncPaymentAmount() after anything that
changes the total; refreshPaymentIfTerminal() from Stripe Elements
loaderror (never proactively).
Manual (step-by-step, for custom flows): updateCart (address+email),
then addShippingMethod, then createPaymentCollection, then
initiatePaymentSession, then completeCart. Both paths are executed against the live server below.
The page: static, and what it reads
The checkout page is a static page. Its form is in the prerendered HTML and paints with the store's header; nothing on the server is awaited before a shopper can start typing. The reference page is two lines:
// src/app/checkout/page.tsx
export default function CheckoutPage() {
return <CheckoutPageClient /> // a client component, no cookies(), no await
}
// src/app/checkout/checkout-page-client.tsx
<CheckoutProvider orderConfirmedPath="/order/{key}">
<CheckoutClient client={browserClient} customer={null} />
</CheckoutProvider>Mounted with the transport alone, CheckoutClient (through
useCheckoutOrchestration) reads the three things that belong to one
shopper from the browser, in one parallel round, after the paint,
through the store's same-origin /api/store rewrite:
| What | How it is read | Until it lands |
|---|---|---|
| the cart | GET /api/store/carts/:id, the id from the browser's cart cookie |
the summary marks where its numbers go |
| the delivery methods | GET /api/store/shipping-options?cart_id&rates=deferred, asked the instant the cookie's id is known |
the address gate as always; two rows once the address is ready |
| the tenders | GET /api/store/payment-providers?cart_id, the platform scoping it to the cart's market |
two rows, no Buy button |
rates=deferred matters: the listing answers in the time of a database
read, the rows are on screen, and each Carrier calculated row is then
priced through /calculate as its carrier answers, instead of every row
waiting for the slowest carrier inside one listing.
When a carrier is asked for a price: when the cart's contents change,
and at no other time. A carrier's price follows the parcel and the kind
of delivery, never the town, the postcode or the office picked. So the
package asks for the prices the moment the cart arrives, before the
shopper has typed anything; the platform keeps each answer with the cart;
and from then on the listing carries the kept prices with the rows
(status: "available"). A shopper who types an address, picks an office,
or leaves the checkout and comes back with the same cart is shown the
prices at once and no carrier is asked. A line added, removed or changed
in quantity asks again, once. WHEN THE ROWS ARE SHOWN is a separate rule:
the list still waits for the destination (the country and a valid
postcode), and by then its prices are there.
Each input is a feed (@cartbase/storefront/checkout/checkout-feed):
a store that reads the cart or a listing on its server hands it in as the
value, or as a promise that settles into a result and never rejects
(settleFeed(read)), so a failed server read reaches the section as data
and the section says so with a Try again while the rest of the page keeps
working. A rejecting promise would be logged on the server and thrown at
the client boundary, taking the whole checkout with it. The old props
(cart as a value, availableShippingMethods, availablePaymentMethods,
paymentMethodsByShippingOption) are still honoured.
What the shopper sees when a read fails: the cart could not be read,
the page's own error words with Try again; no cart, an empty cart or one
completed in another tab, the empty notice with the way back
(CheckoutEmptyState, the label pack's words); a listing that failed, its
section says so once with Try again, undimmed, before any address. Every
failure reaches the merchant's checkout error log as cart_read_failed,
delivery_listing_failed or payment_listing_failed. A stale cookie
naming a cart the store no longer has is "no cart", not a failure.
A failed read is asked a second time before anyone is told. When one
of the three reads the browser makes fails on the network or on the
platform's side (no status, or 500 and above), the package asks it once
more after FEED_RETRY_DELAY_MS (400 ms) and shows and logs a failure only
when the second ask fails too (settleFeedWithRetry,
checkout/checkout-feed). A read changes nothing, so asking twice is safe.
A refusal (any 4xx) is an answer and is never asked again. A store that
reads on its server and hands the result in decides its own retries.
The way back from a payment redirect (Revolut Pay, a bank
challenge): the page knows it from its first paint (usePaymentReturn,
checkout/payment-return, read from the address bar's redirect_status
and payment_intent marks without a hydration mismatch) and shows one
screen, CheckoutReturnScreen (checkout/checkout-return-screen, the
label pack's returnTitle and returnText): a spinner, "Confirming your
payment". No form, no skeletons, no courier quoted, no tender listed, no
funnel step; only the cart is read, because placing the order needs it.
The platform may be placing that very order itself (its succeeded webhook
lands while the shopper is away): POST /complete waits for it and answers
the same order, and the return asks again on cart_locked, three times two
seconds apart. A refusal after that shows on the same screen with Try
again (retryReturn); redirectReturn on the orchestration says where the
return stands (idle, pending, failed).
Cart freshness is the hook's. A tab that comes back into view
(visibilitychange) re-reads its cart once and adopts the answer when the
cart moved, by the cart's own updated_at; a summary door's decorated
cart (promo, gift card) is adopted on the spot. No page refresh, ever,
and no window focus listener anywhere in the package or the reference
page. A page that refreshes on window focus or visibility fires on a
phone at every keyboard, autofill sheet and card iframe hand-back, several
server renders a second, each waiting on a live carrier quote. A store that keeps
its own copy of the cart still gets onCartChange; refreshing on it is the
store's choice, not the package's.
A store's own rule on the cart (a minimum order, which the platform
does not carry) is the gate prop: gate={(cart) => shortOfMinimum(cart) ? <YourNotice /> : null}. It is judged once the cart is there, and again
on every cart the client adopts, so a basket that falls under the rule
mid-checkout loses the form the same way. The card and wallet marks
(paymentMarks) may be handed in or left to the client, which reads them
once after the paint.
What the form does before the cart arrives: everything but talk to the
server about the cart. Typing works; the address autosave, the carrier
quotes, the choice writes, the payment sync, the funnel and the 3DS return
all wait for cartLoaded and run the moment it is true. When the cart
arrives, its address, email and company fields fill every field the shopper
has not touched in this tab, and its remembered courier and pickup point
restore a choice this tab has not made yet.
GET /api/store/shipping-options: list (rule-filtered)
- Purpose: render the shipping picker. Pass
cart_id, it prices the options in the cart currency AND gives the checkout-rules engine its evaluation context. - Auth: anon
x-client-id. - Request:
GET ?cart_id=cart_…(optional; without itamountis null and cart-dependent hide rules cannot match) and&rates=included|deferred(optional;includedis the default and quotes calculated carriers inside this response;deferredanswers at once and asks no carrier: a calculated option the cart already holds a price for arrives with itsamountandrate_availability.status: "available", and one it holds none for arrives withamount: nullandstatus: "deferred", for/calculateto price). - Response: list envelope;
count/limit= the full filtered list (no pagination):
{
"shipping_options": [{
"id": "so_…", "name": "Standard",
"provider_id": "boxnow", // the connected carrier adapter
"service_zone_id": "sz_…", "shipping_profile_id": "sp_…",
"data": { "fulfillment_option": "boxnow-locker" },
"carrier": {
"id": "boxnow", "name": "BoxNow",
"mark_url": "/api/store/integrations/marks/boxnow",
"fulfillment_option": {
"id": "boxnow-locker", "mode": "locker", "label": "Locker"
},
"pickup_scope": "global" // every carrier
},
"type": { "label": "Express" }, // the option's display label, or null
"amount": 5, // stored price or confirmed live carrier quote
"price_type": "calculated",
"rate_availability": { "status": "available" }
}],
"count": 1, "offset": 0, "limit": 1
}- Eligibility: four gates run server-side before an option lists:
the option's shipping profile must be among the cart products' profiles;
its zone must cover the shipping address; its visibility rules must
pass; and a price must exist for the cart. Conditional rates (tiers by
order amount, cart weight, or cart volume) resolve here,
amountis always the tier the cart actually satisfies. - Carrier contract: when an option is bound to a carrier,
carriercontains the adapter identity, mark, destination mode and pickup scope. The pickup scope isglobalfor every carrier: a picker holds the carrier's whole network, whatever town the shopper typed, and the field stays for the storefronts that read it. Checkout renders every office/locker carrier from this contract through the shared picker; it does not carry a carrier-name switch. A carrier with exactly one destination mode is bound automatically, including older options whosedatawas saved before this rule existed. Carriers with multiple modes require the merchant to choose one. - Calculated-rate failure contract: a complete cart is quoted in this
same server read. A carrier that cannot return a price leaves its own row
in the list with
amount: nullandrate_availability: {status: "unavailable", code: "carrier_unavailable"}. The checkout keeps that row's carrier and full delivery-method name visible, shows the error beneath it, disables selection, and offers a per-row Try again action. Repeated clicks for the same row share one request; a response for an older cart is discarded. Only a confirmed current rate restores selection. Flat methods and successful carriers remain selectable. A cart is priced before any address is typed: its country is the address's own, or the region's when the region sells to one country. Only a cart whose country is not known yet, or a country the platform holds no reference destination for, carriesstatus: "requires_address"on its calculated rows until it has a town. No fallback or guessed amount is ever used. A quote has a five-second deadline, after which that method settles into the same unavailable state instead of leaving checkout loading indefinitely. - Errors: 404
cart_not_found(badcart_id). - SDK:
checkout.listShippingOptions(client, {cart_id, rates?}). - Components: shipping picker, carrier/locker pickers (carrier
metadata is collected client-side and handed to
prepareCheckout). - Settings: checkout rules (
target_type=shipping_option) hide options server-side;checkout_method_orderorders them; fail-open (a broken rule never bricks the listing). Hidden-method enforcement is at complete (checkout_method_hidden), not only here. - Greyed out, with the reason (
&unavailable=include): a rule may show the option it takes away greyed out instead of hiding it, or let an A/B test decide which. A checkout that draws such an option asks withunavailable=include: the option then stays in its place withavailable: false,unavailable_reason(the merchant's line) and no price, it cannot be chosen, and every other option carriesavailable: true. The answer also carriesexperiments, the keys of the running experiments that shaped it: report them throughPOST /api/store/experiments/exposuresfrom the browser (experiments.md), which is what counts the shopper. Asked without the parameter, such an option is left out like a hidden one.&preview=<experiment key>:<variant key>(comma separated) forces those variants for this answer and names no experiment, so nothing is counted. A greyed-out option is never priced, and complete refuses it as a hidden one.
# Payable cart for the whole page (seeded Linen Shirt M + address + email).
CART_JSON=$(curl -sf -X POST "$BASE/api/store/carts" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"email":"checkout-doc-'"$RUN"'@example.test","currency_code":"eur",
"items":[{"variant_id":"variant_01tst000000000000000002","quantity":1}]}')
CART_ID=$(echo "$CART_JSON" | grep -o '"id":"cart_[^"]*"' | head -1 | cut -d'"' -f4)
REGION_ID=$(echo "$CART_JSON" | grep -o '"region_id":"[^"]*"' | head -1 | cut -d'"' -f4)
test -n "$CART_ID" && test -n "$REGION_ID"
OPTS_JSON=$(curl -sf "$BASE/api/store/shipping-options?cart_id=$CART_ID" \
-H "x-client-id: $CLIENT_ID")
echo "$OPTS_JSON" | grep -q '"price_type":"flat"'
# Pick a PRICED option: an option without a price row for the cart currency
# lists amount: null and cannot be calculated or prepared. (The listing is
# shared dev-tenant state; never grab blindly the first row.)
SO_ID=$(echo "$OPTS_JSON" | grep -o '"id":"so_[^"]*","name":"Flat Rate (Bulgaria)"' \
| head -1 | cut -d'"' -f4)
test -n "$SO_ID"
# A checkout that draws greyed-out options reads each option's availability
# and the experiments to report.
INCLUDE_JSON=$(curl -sf "$BASE/api/store/shipping-options?cart_id=$CART_ID&unavailable=include" \
-H "x-client-id: $CLIENT_ID")
echo "$INCLUDE_JSON" | grep -q '"available":true'
echo "$INCLUDE_JSON" | grep -q '"experiments":\['POST /api/store/shipping-options/:id/calculate: price one option
- Purpose: price one calculated option for a cart: the row a deferred listing left unpriced.
- The answer is kept, and every door reads it. Every price a carrier
answers for a cart, here or inside the listing, is kept for that cart and
option with what it was asked for: the cart's lines, the option and the
country. The town, the postcode and the chosen point are NOT part of it.
This door, the listing,
prepare-checkoutandPOST /carts/:id/shipping-methodsall answer the kept price without asking the carrier while the lines are unchanged, the option and the carrier's settings have not been saved since, and the price is under twelve hours old; otherwise the carrier is asked, once, and its answer is kept. Asking this door again for the same cart costs a database read. - Before any address. A cart with no town and no postcode is priced to the country's reference destination (its capital), so the checkout holds its prices before the shopper types.
- Auth: anon
x-client-id. - Request:
{cart_id, data?},datamay carry the selected office or locker; it is no part of the price. - Response:
200 {shipping_option}withamountin the cart currency. - Errors: 404
cart_not_found|shipping_option_not_found; 400shipping_price_missing(no price row in the cart currency) |shipping_price_unavailable(the calculated carrier could not confirm a rate) |validation_failed. - SDK:
checkout.calculateShippingOption(client, id, {cart_id}).
curl -sf -X POST "$BASE/api/store/shipping-options/$SO_ID/calculate" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"cart_id":"'"$CART_ID"'"}' | grep -q '"amount"'GET /api/store/payment-providers: list (rule-filtered)
- Purpose: render the payment-method picker.
- Auth: anon
x-client-id. - Request:
GET ?region_id=…&cart_id=…&shipping_option_id=…, all optional. Withoutregion_id: the tenant's enabled providers (global catalog ∩ tenant enablement). With it: providers linked to that region.cart_idfeeds the rules engine, storefronts SHOULD pass it during checkout.shipping_option_idevaluates a prospective delivery click immediately, before its separate cart-preference write finishes. - Response: list envelope, full filtered list. Two entry shapes share
the array: connected PROCESSORS (
{id}, pp_stripe) and merchant payment METHODS ({payment_method_id, name, kind, instructions, fee_amount, fee_label}, "Bank transfer", the COD method). Methods carry no provider id anywhere; a fresh store with nothing configured gets an honestly empty list. Withregion_id, BOTH families filter by the region's claims (region_payment_provider/region_payment_method, availability is a per-region merchant choice):
{
"payment_providers": [
{ "id": "pp_stripe", "is_enabled": true, "created_at": "…" },
// one entry PER enabled, region-claimed merchant method:
{ "payment_method_id": "pm_…", "name": "Bank transfer",
"kind": "manual", "instructions": "IBAN BG…",
"fee_amount": null, "fee_label": null },
{ "payment_method_id": "pm_…", "name": "Cash on delivery",
"kind": "cod", "instructions": null,
"fee_amount": 4.99, "fee_label": "COD fee" }
// pp_giftcard is INTERNAL tender and is never listed
],
"payment_providers_by_shipping_option": {
"so_boxnow": [{ "id": "pp_stripe", "is_enabled": true }],
"so_speedy": [
{ "id": "pp_stripe", "is_enabled": true },
{ "payment_method_id": "pm_cod", "name": "Cash on delivery", "kind": "cod" }
]
},
"count": 3, "offset": 0, "limit": 3
}- Selecting a method: initiate the session with the method id alone:
POST …/payment-sessions { payment_method_id: "pm_…" }. The server validates it (tenant's, enabled, claimed for the cart's region, 400 otherwise), the session lands withprovider_idNULL, and the method's identity is snapshotted intosession.data(payment_method_id/name/kind) so payment surfaces say "Bank transfer" without a join. Renderinstructionsto the shopper after selection and on the confirmation screen.fee_amount/fee_labellet the checkout PREDICT the fee before the session exists, the authority stays the server totals (payment_method_fee_total). - Errors: none beyond the standard envelope (empty list when nothing
is enabled); initiate 400s on unknown/disabled/foreign method ids and
payment_method_not_in_regionfor an unclaimed region. - SDK:
checkout.listPaymentProviders(client, {region_id, cart_id, shipping_option_id}). - Delivery-dependent payment rules: selecting a delivery option is
remembered on the cart before the atomic Buy call. The initial listing's
payment_providers_by_shipping_optionmap is evaluated by the server from the same cart context and live rules.CheckoutClientselects the mapped list synchronously on every carrier click; older fallback responses are discarded, and remembered choices are serialized with latest-intent wins. The completion guard repeats the decision against the attached shipping method. - Greyed out, with the reason (
&unavailable=include): as on the delivery listing: a way to pay a rule greys out stays in its place withavailable: falseandunavailable_reason, in the list and in every entry ofpayment_providers_by_shipping_option; the answer namesexperimentsand, per delivery option,experiments_by_shipping_option, so a checkout that switches delivery on the map reports the keys of the option chosen.&preview=forces variants as there. - Components: payment picker.
- Settings: Stripe connects in Settings, Payments (provisions
pp_stripe+ credentials); payment methods live in the same screen (the COD switch + named manual methods, each with optionalfee_amount/fee_labeland per-region availability); checkout rules (target_type=payment_method, method entries participate under theirpayment_method_id) +checkout_method_order.
curl -sf "$BASE/api/store/payment-providers?cart_id=$CART_ID" \
-H "x-client-id: $CLIENT_ID" | grep -q '"payment_method_id"'
PAY_JSON=$(curl -sf "$BASE/api/store/payment-providers?region_id=$REGION_ID&cart_id=$CART_ID" \
-H "x-client-id: $CLIENT_ID")
echo "$PAY_JSON" | grep -q '"payment_method_id"'
# The seeded Bank transfer method carries the rest of this page.
PM_ID=$(echo "$PAY_JSON" | grep -o '"payment_method_id":"pm_[^"]*"' | head -1 | cut -d'"' -f4)
test -n "$PM_ID"POST /api/store/carts/:id/prepare-checkout: the atomic Buy click
ONE call takes everything the customer toggled on /checkout and writes it
in ONE transaction: the address, the shipping method
priced for that destination, the promotions and tax lines that follow from
both, the payment collection at the order's total, and the payment
session at the FINAL amount (real Stripe PaymentIntent, idempotency key =
session id; a plain NULL-provider row for a payment method; a method's fee
is in the total it is computed from). The server reads the cart once,
computes every row, and writes them together: everything or nothing, so a
failure leaves the cart exactly as it was, with nothing to undo. A cart
that changed while the call was computing is read and computed again, never
overwritten; two calls for one cart are served one after the other. The
call is recorded in the execution ledger (workflow prepare-checkout,
states done/reverted; failures also land in checkout_error_logs, step
prepare-checkout).
- Auth: anon
x-client-id. - Request (
.strict(); the platform's DTO, verbatim), all address fields required exceptaddress_2/company/province;phoneis required (courier recovery channel). The tender is exactly ONE ofpayment_provider(a connected processor,pp_stripe, neverpp_giftcard) orpayment_method_id(a merchant method from the listing):
{
"shipping_address": {
"first_name": "Jane", "last_name": "Dow",
"address_1": "Vitosha 1", "address_2": "",
"company": "", "province": "",
"city": "Sofia", "postal_code": "1000",
"country_code": "bg", "phone": "+359888123456"
},
"shipping_method_id": "so_…", // a shipping-option id
"shipping_method_data": {}, // optional, stored on the method row
"carrier_metadata": { // optional, opaque per-carrier keys
"office_code": "X1", "office_name": "Center"
},
"payment_method_id": "pm_…", // XOR payment_provider: "pp_stripe"
"save_payment_method": false, // optional, subscription carts only;
// same semantics + consent duty as on
// payment-sessions below
"expected_total": 151.9 // optional: the total the shopper was shown
} expected_total is the total the checkout showed for this delivery and
this way to pay (the figure selection-totals answered). When the
platform's own total differs to the cent, the call answers 409
total_changed with details: {total, expected_total, currency_code},
total being the platform's, and nothing is written: show the new total
and let the shopper press again. Leave it out and no check runs.
Billing mirrors shipping (own row). carrier_metadata merges into
cart.metadata; keys written by the PREVIOUS prepare call are removed
first (tracked under the reserved _prepared_carrier_keys marker),
switching carriers can never leak the old carrier's fields into the
order.
- Response (verbatim
PrepareCheckoutResult):
{
"cart_id": "cart_…",
"payment_collection_id": "pc_…",
"client_secret": "pi_…_secret_…", // Stripe only; null for method sessions AND zero-remainder carts
"provider_id": null, // the processor, when one was chosen
"payment_method_id": "pm_…" // the method, when one was chosen
}- Zero-remainder gift path: when applied gift cards cover the whole
total, the tender session is skipped entirely (
client_secret,provider_idandpayment_method_idcome back null) and the cart completes on the gift session alone, no Stripe involved (gift-cards.md). - A Carrier calculated delivery is charged at the price its carrier
already answered for the cart as it stands (see
/calculateabove), so a Buy click on a price the shopper was shown makes no carrier call. When no such price stands, the carrier is asked inside this call, and a refusal answers 400shipping_price_unavailablewith nothing written. The receiver is still checked as the carrier's booking needs: a phone no carrier can dial answers the same 400. - The stock, before the card: the first check of the
call, before anything is priced or minted: every line is planned against
live stock exactly as the order write will hold it, a set through its
parts. A line the
store cannot hold refuses the whole call with 409
insufficient_inventoryanddetails: {line_item_id, variant_id, title, quantity, requested, available}, and no intent is minted, so a cart left for days with a line that sold out in between never reaches the card. The seconds between this check and the write are the one race left, and the write answers it by releasing the money (see complete below). - The hold: a Stripe intent is minted with a HOLD for the methods that can hold (cards and the wallets on them, Revolut Pay, PayPal, Klarna): the shopper's confirmation authorizes the money and the order's write captures it. iDEAL, Bancontact and SEPA cannot hold and capture at confirmation as before.
- Errors: 404
cart_not_found|shipping_option_not_found; 409cart_completed|total_changed(the total is no longer theexpected_totalsent) |insufficient_inventory(the line named indetails); 400validation_failed|invalid_provider(pp_giftcard) |shipping_price_missing|shipping_price_unavailable|stripe_not_configured. - SDK:
checkout.prepareCheckout(client, cartId, input). - Components: the checkout form's Buy button; carrier/locker pickers
feed
carrier_metadata. - Settings: Stripe credentials (admin integrations), COD fee, gift cards; checkout rules are enforced at the listings and at complete, not here.
PREP_JSON=$(curl -sf -X POST "$BASE/api/store/carts/$CART_ID/prepare-checkout" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"shipping_address":{"first_name":"Doc","last_name":"Run",
"address_1":"Vitosha 1","city":"Sofia","postal_code":"1000",
"country_code":"bg","phone":"+359888123456"},
"shipping_method_id":"'"$SO_ID"'",
"carrier_metadata":{"office_code":"X1"},
"payment_method_id":"'"$PM_ID"'"}')
echo "$PREP_JSON" | grep -q '"payment_method_id":"'"$PM_ID"'"'
echo "$PREP_JSON" | grep -q '"client_secret":null'
PC_ID=$(echo "$PREP_JSON" | grep -o '"payment_collection_id":"pc_[^"]*"' | cut -d'"' -f4)
test -n "$PC_ID"
# Error contract: pp_giftcard is never a selectable provider.
GC_RES=$(curl -s -X POST "$BASE/api/store/carts/$CART_ID/prepare-checkout" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"shipping_address":{"first_name":"Doc","last_name":"Run",
"address_1":"Vitosha 1","city":"Sofia","postal_code":"1000",
"country_code":"bg","phone":"+359888123456"},
"shipping_method_id":"'"$SO_ID"'",
"payment_provider":"pp_giftcard"}')
echo "$GC_RES" | grep -q '"code":"invalid_provider"'POST /api/store/carts/:id/sync-payment-amount: align amounts in place
Aligns the pending provider session with the cart's CURRENT total, in
place when possible, the happy path returns the same client_secret
so <Elements> never remounts (the fix for the "InitiateCheckout fires
four times when I change shipping" bug class). Call after anything that
changes the total while checkout is mounted (quantity change, gift card
applied/removed, shipping switch).
- Auth: anon
x-client-id. - Request:
{provider_id? | payment_method_id?}(.strict(); empty object fine, never both). Passing a DIFFERENT tender than the pending session's forces rotation to it. - Response matrix:
| state | response |
|---|---|
| completed cart | {"synced":false,"reason":"cart-completed"} |
| no payment collection | {"synced":false,"reason":"no_payment_collection"} |
| no pending provider session (gift sessions excluded) | {"synced":false,"reason":"no_pending_session"} |
| tender matches, amount current | {"synced":true,"rotated":false,"client_secret":…,"provider_id":…,"payment_method_id":…} (no-op) |
| tender matches, amount drifted | in-place update (Stripe paymentIntents.update; plain field for method sessions), answering {"synced":true,"rotated":false,…}, same secret |
| tender mismatch OR update refused (terminal PI) | rotation: old session retired (+ PI voided best-effort), fresh session at the new remainder, answering {"synced":true,"rotated":true,…} |
A session's tender identity is its provider_id for processors and its
snapshot payment_method_id for NULL-provider method sessions. Rotation
retires the old session BEFORE recomputing so session-dependent totals
(the method fee) settle for the NEW tender; a final resync pass aligns
collection + session + PI. client_secret is null for method sessions.
- Errors: 404
cart_not_found; 400validation_failed|stripe_not_configured. Failures land incheckout_error_logs(stepsync-payment-amount). - SDK:
checkout.syncPaymentAmount(client, cartId, {provider_id?, payment_method_id?}). - Components: checkout totals watcher (debounced), payment-method switcher (pass the new tender id).
# No-drift no-op on the prepared method cart: same-session, not rotated.
SYNC_JSON=$(curl -sf -X POST "$BASE/api/store/carts/$CART_ID/sync-payment-amount" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}')
echo "$SYNC_JSON" | grep -q '"synced":true'
echo "$SYNC_JSON" | grep -q '"rotated":false'
echo "$SYNC_JSON" | grep -q '"payment_method_id":"pm_'POST /api/store/carts/:id/refresh-payment-if-terminal: dead-PI recovery
A Stripe PaymentIntent can die out-of-band (canceled in the Dashboard,
Stripe's 24h auto-cancel, captured externally) while the local session
stays pending; mounting Elements on the dead client_secret fails with
"PaymentIntent is in a terminal state". This route reconciles against
Stripe's ACTUAL PI and rotates a fresh session/PI only when the intent is
truly dead. Call it reactively: Elements loaderror / page mount for
aged carts, never proactively per render (the proactive variant caused a
production reload loop).
- Auth: anon
x-client-id. No body. - Response,
rotated:
{"rotated":true,"reason":"pi-terminal"|"pi-missing", "previous_status":…}(terminal =succeeded/canceled/requires_capture, or aresource_missingPI). Not rotated:cart-completed|no-stripe-session(also when the pending session is non-Stripe) |no-pi-id|stripe-not-configured|still-usable(+status) |stripe-error(+error), any transient Stripe error refuses to rotate (rotating on transient failures was the loop bug). Every rotation writes an audit row (checkout_error_logssteprefresh-payment, coderotated). - Errors: 404
cart_not_found. - SDK:
checkout.refreshPaymentIfTerminal(client, cartId). - Components: Stripe Elements mount error handler.
# Method session: the documented no-op reason (a Stripe rotation needs the
# store's Stripe credentials, which this anonymous run does not have).
curl -sf -X POST "$BASE/api/store/carts/$CART_ID/refresh-payment-if-terminal" \
-H "x-client-id: $CLIENT_ID" | grep -q '"reason":"no-stripe-session"'POST /api/store/carts/:id/complete: place the order
The last call of every checkout. Server-side it reads the cart
once, checks and computes everything, then writes the order in ONE
transaction. The checks, in the order a refusal is answered: idempotency, then
validation, then the total against the payment, then the checkout-rules
completion guard, then the stock plan (a set through its parts), then
subscription contracts (carts with plan lines: one contract per plan,
cycle 1 tied to this order, cycle 2 scheduled at the next CHARGE date;
guests are refused with 400 customer_required), then the payment's
answer (the gift tender's burns
planned against live balances; the Stripe intent read for pp_stripe;
method sessions accepted as they stand). The one write then lands, together
or not at all: the stock holds, the order with its rows, the contracts, the
pool codes and promotion usage, the gift card burns, the payment records,
and the cart's completion stamp. order.placed (+ subscription.created
per contract) follows on the durable bus. A refusal at any point, inside
the write included, leaves nothing behind: no order, no hold, no burned
gift card, no used code, and the cart stays open and retryable. Note:
subscription carts auto-save the card at the payment-session step (see
save_payment_method above), by complete time the mandate already exists.
The money. A held card
(prepare above) is recorded by the write as authorized and CAPTURED right
after the order exists, under the session's own key, so Stripe's succeeded
event that follows records nothing twice; the order is paid before the
answer is sent. A write refused for good, a cart that cannot be placed as
it stands (insufficient_inventory, checkout_method_hidden,
payment_amount_mismatch, the promotion and gift card refusals, the
validation family), RELEASES the money in the same request: a hold is
voided (no charge, no fee), a charge the method captured at confirmation is
refunded in full, the session is over, and the refusal says which in
details.payment_released (voided | refunded | none); the next Place
order mints a fresh intent. A refusal a retry can clear (the database or
Stripe away, the other door mid-write) releases nothing. Money that still
has no order ten minutes later, whatever the cause, is refunded by the
platform's watch.
- Auth: anon
x-client-id(guest checkout). Store settingaccounts_mode='required': guest carts (no attached customer) get 403account_required;disabled/optionalleave guests untouched. - Request:
POST, empty body. - Response:
200 {"type":"order","order":{…}}, the order withsummaryand flatteneditems. Idempotent: re-calling returns the SAME order; concurrent completes are serialized by the write itself (it locks the cart's row), and the loser returns the winner's order (the succeeded webhook placing the order while the shopper returns from a redirect, a second tab). 409cart_lockedwhen the cart kept changing under the call (three reads in a row), or when a cart carries a completion stamp with no order for twelve seconds.Contract note (code wins over store-api.md): the documented
{type:"cart", cart, error}failure union is never returned, failures throw the standard error envelope. - Errors:
- 400 validation:
cart_email_required|cart_empty|shipping_address_required|shipping_method_required(only when a linerequires_shipping, digital-only carts, e.g. digital gift cards, skip it) |payment_collection_required|payment_session_required|insufficient_inventory(409;detailsnames the line:line_item_id,variant_id,title,quantity,requested,available) |customer_required(plan lines on a guest cart, subscribing needs an account; normally already refused at the payment-session step). - Every refusal that releases the money carries
details.payment_released:voided(the hold went, no charge),refunded(the charge went back) ornone(nothing was at Stripe, or the release failed and the watch will refund). Say it to the shopper (paymentErrors.paymentVoided/paymentRefundedin the label pack;translatePaymentErrorappends it by itself). - 400
checkout_method_hidden, the checkout-rules security boundary: every live payment session's chosen tender (the method'spayment_method_idfor NULL-provider sessions, else the provider id; internalpp_giftcardexempt) and every chosen shipping option is re-validated against the live rules with the full cart context. A stale session that picked a method before a rule started matching, or a hostile client that skipped the filtered listings, is rejected here and the rejection is recorded incheckout_error_logs(stepcomplete). - 402 payment family:
requires_action(3DS,details.client_secretcarries the intent to confirm) |payment_not_authorized|payment_not_initiated(Stripe session without a PI, re-initiate) |payment_incomplete(gift tender no longer covers a session-less total) |gift_card_insufficient_balance(lost double-spend race) |gift_card_not_redeemable. - 400 promotion family, judged inside the write:
promotion_limit_exceeded|promotion_per_customer_limit|promotion_expired|promotion_code_used(a single-use code another order took). - 403
account_required; 409cart_locked(see the response above). The package's return handler asks again on it, three times two seconds apart, before it reports the refusal.
- 400 validation:
- SDK:
carts.completeCart(client, cartId)(module@cartbase/storefront/api/carts). - The order's page: the response carries
order.access_key, the key of the order's public page, and the browser goes to/order/{key}(orderConfirmedPath, substitutions{key},{number},{id},{country}). That page reads the order from the platform (orders.md, the read by key), so nothing is stashed in the browser on the way there, and the same address is in every order email. - Components: Buy button (orchestrated path), the order page
(
OrderCompletedTemplate). - Settings: checkout rules;
accounts_mode; the payment method fee (timing: a method's fee exists only while ITS live session does, it appears on the cart at prepare aspayment_method_fee_total, ridescart.total, and is carried onto the order viaorder_summaries.totals, where waybill COD amounts read it); gift-card tender (zero-remainder carts complete on the gift session alone).
# Complete the prepared method cart into a real order, no Stripe env needed.
ORDER_JSON=$(curl -sf -X POST "$BASE/api/store/carts/$CART_ID/complete" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}')
echo "$ORDER_JSON" | grep -q '"type":"order"'
ORDER_ID=$(echo "$ORDER_JSON" | grep -o '"id":"order_[^"]*"' | head -1 | cut -d'"' -f4)
test -n "$ORDER_ID"
# Idempotency: completing again returns the SAME order.
ORDER_ID2=$(curl -sf -X POST "$BASE/api/store/carts/$CART_ID/complete" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}' \
| grep -o '"id":"order_[^"]*"' | head -1 | cut -d'"' -f4)
test "$ORDER_ID" = "$ORDER_ID2"
# Post-completion contracts: mutations 409, sync/refresh report the reason.
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -X POST \
"$BASE/api/store/carts/$CART_ID/line-items" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"variant_id":"variant_01tst000000000000000003","quantity":1}')
test "$STATUS" = 409
curl -sf -X POST "$BASE/api/store/carts/$CART_ID/sync-payment-amount" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}' \
| grep -q '"reason":"cart-completed"'
curl -sf -X POST "$BASE/api/store/carts/$CART_ID/refresh-payment-if-terminal" \
-H "x-client-id: $CLIENT_ID" | grep -q '"reason":"cart-completed"'GET /api/store/carts/:id/stock: the lines the store cannot hold
The checkout's question when it opens a cart: which lines the store can no longer hold, each with the quantity wanted and the quantity left, planned line by line against live stock, a set through its parts, so a cart left days ago shows its sold-out line before the shopper types anything. Reads the same plan the prepare call refuses on and the order write takes its holds from; writes nothing.
- Auth: anon
x-client-id. - Response:
{ "ok": true, "shortages": [] }, orok: falsewith one entry per short line:{ line_item_id, variant_id, title, quantity, inventory_item_id, requested, available }(requestedandavailablein the stock record's units,quantitythe line's). - Errors: 404
cart_not_found.
curl -sf "$BASE/api/store/carts/$CART_ID/stock" -H "x-client-id: $CLIENT_ID" \
| grep -q '"ok":true'POST /api/store/checkout-errors: browser-side error reporting
The browser half of checkout error capture. The server logs every money-path
failure into the merchant's checkout error log on its own; failures that
happen only in the customer's browser, a Stripe.js confirm error, a 3DS
return that comes back not-succeeded, a place-order rejection, are reported
through this endpoint. useCheckoutOrchestration reports them by
default; you only call this yourself if you replaced the hook's logError
and still want the platform log.
Body (.strict()): error_type (≤64 chars), message (≤2000),
optional cart_id, optional context object (redacted values only, ids,
codes, flags; never card data, never addresses; oversized context is
stored as {truncated: true}). Answers 204 always on accepted input;
400 malformed; 429 past 60 reports/store/minute. Fire-and-forget: the
SDK's reportCheckoutError() swallows every failure, reporting an error
must never take a checkout down.
Modifying checkout: the laws
Checkout is locked space (LOCK_BOUNDARIES): critical-to-function code is closed; customize through props, slots and tokens, never by editing the package's files. What that means in practice:
- Fork the layout, compose the concerns, never reimplement the money
path.
useCheckoutOrchestrationis the composition of nine concern hooks, each its own import (components.md§ The checkout's concerns). Build your own screens on the composed hook, or compose your own from the pieces: the cart, the notes, the address, the delivery, the tender and the totals are open seams.useCheckoutBuyis the LOCKED one: session guard, amount sync, dead-PI recovery, the bank-challenge return, a completion that can be pressed again, one order per intent. A fork of it drops guards it cannot see; import it and use it, never rewrite it. - The server owns every amount. The client never sends an amount;
sessions charge
total − gift_card_totalcomputed server-side. Any checkout change that puts a number in a request body is wrong by construction. - Logging is not optional. Money failures must reach the merchant: the
hook's default sink does this. If you override
logError, either callreportCheckoutError()yourself or accept that browser failures vanish, and that is a defect, not a preference. - Debug output is opt-in.
useCheckoutOrchestration({ debug: true })turns on verbose[buy-click]console output for local work. It prints the full prepare payload (name, phone, email, address), so it must never ship enabled. - Test against the real wire. Every request/response shape on this page is executable against a store; a checkout change ships with its route driven end to end, error branches included.
Manual path: collections + sessions (step-by-step)
POST /api/store/payment-collections
- Purpose: ensure the cart's payment collection (ONE per cart, idempotent; the amount is refreshed to the CURRENT decorated total on every call).
- Auth: anon
x-client-id. - Request:
{cart_id}.Contract note (code wins over store-api.md): the contract's
provider_id/datafields are ignored, the provider is chosen when initiating the session. - Response:
201 {payment_collection}when created,200when the existing one was refreshed.{id, amount, currency_code, status:"not_paid", payment_sessions:[…]}. The moment a collection exists, applied gift-card tender is composed as an internalpp_giftcardsession. - Errors: 404
cart_not_found; 400validation_failed. - SDK:
checkout.createPaymentCollection(client, {cart_id}).
POST /api/store/payment-collections/:id/payment-sessions
Purpose: mint (or repair) the tender session, idempotent per tender. For Stripe the PaymentIntent is minted FIRST (idempotency key = session id) so a Stripe session row can never exist without its intent; amount drift syncs the PI in place; terminal PIs self-heal by rotation. Method sessions share ONE NULL-provider row per collection, switching methods updates its snapshot in place.
Auth: anon
x-client-id.Request:
{provider_id? XOR payment_method_id?, data?, save_payment_method?}, exactly one tender. Keys the server owns (payment_intent_id,client_secret,status,stripe_customer_id,setup_future_usage, and the method snapshotpayment_method_id/name/kind) are stripped fromdata, they cannot be forged from the client.save_payment_method: saves the card for future off-session renewal charges: the server resolves the CART'S customer (never a client-supplied id), ensures a Stripe Customer for them, and mints the PaymentIntent withsetup_future_usage: "off_session". Automatic for subscription carts: when the cart carries plan lines the server applies the mandate even without the flag (a subscription cannot renew without it, the server owns the decision). Requires a logged-in customer, a guest cart is a 400customer_required(subscribing needs an account), raised HERE, before any payment. Consent: the mandate moment, the storefront MUST render the saved-card consent text with the plan selection / next to the payment element (e.g. "Your card will be saved for future subscription charges"). Re-initiating an existing session with the flag (or after a plan line appears) upgrades the live intent in place (sameclient_secret). No card to save on method sessions (COD/manual subscriptions renew offline), the account gate still applies. Never set the flag on ordinary checkouts.setup_future_usage("off_session", optional), what the Payment Element was mounted with (deferred-intent Elements takesetupFutureUsage). The intent is minted to say the same, because Stripe refuses a confirmation whose intent and Element disagree ("The provided setup_future_usage (off_session) does not match the expected setup_future_usage (null)"). Absent = the form saves nothing itself: the intent still rides the cart's customer's Stripe Customer, guests included, and the confirmed payment method is kept on that Customer after the payment succeeds, so a change of the order can be charged on it later. A session minted with the flag while the form declares nothing is retired and minted again. The same field onprepare-checkout.card_setup_future_usage("on_session"or"off_session", optional), what the Payment Element was mounted with for cards alone (paymentMethodOptions: { card: { setup_future_usage } }). The intent says the same on the card's options, beside its hold, so Stripe keeps the card on the shopper's Stripe Customer at the confirmation and an order change can charge it later; Apple Pay and Google Pay are cards, and no other method is hidden or asked. Stripe shows its consent line under the card fields. A session whose keeping differs from what the form asks is retired and minted again. The same field onprepare-checkout.Which of the two is the platform's word, never the storefront's. The card entry of
GET /api/store/payment-providerscarriescard_setup_future_usage; the form mounts with that value and sends the same.@cartbase/storefrontdoes this by itself from 0.45.5: the value the form mounted with is held for as long as the page lives, and the Buy click repeats it. A storefront with its own Payment Element reads the entry and does the same. The two ways differ at the bank:on_session(what the entry says): the card is kept for use while the shopper is checking out. The bank checks the card only when the payment itself needs it. A later charge with nobody present can still be tried on the card; the bank refuses it more often, and a refused one stays a balance due that the customer pays from their payment link.off_session: the card is kept for charges with nobody present. The bank then verifies every card in full at the payment (a code, an approval in the bank's app), and a card the bank cannot verify cannot pay. Versions 0.45.3 and 0.45.4 of the package asked this way on every card payment; they are still served what they ask, so upgrade them.
Response:
201 {payment_session}when created,200when the existing one was returned/repaired:{id, provider_id, amount, currency_code, status:"pending", authorized_at:null, data}, for Stripe,datacarriespayment_intent_id+client_secret(mount Elements with it); withsave_payment_methodit also carriessetup_future_usage: "off_session"+stripe_customer_id. For a method,provider_idis null anddatacarries the snapshot (payment_method_id,payment_method_name,payment_method_kind). The sessionamountiscollection.amount − gift_card_total, the remainder.Errors: 404
payment_collection_not_found; 400invalid_provider(pp_giftcard, or an id the catalog doesn't know, the dead pp_ ids land here) |payment_provider_disabled|payment_provider_not_in_region|payment_method_not_in_region|stripe_not_configured|customer_required|validation_failed.SDK:
checkout.initiatePaymentSession(client, pcId, {provider_id?, payment_method_id?, save_payment_method?}).
POST /api/store/carts/:id/shipping-methods
- Purpose: set the cart's shipping method manually (single-method model: the previous method rows are replaced).
- Auth: anon
x-client-id. - Request:
{option_id, data?}(.strict()). - Response:
200 {cart}(decorated;shipping_totalnow non-zero). - Errors: 404
cart_not_found|shipping_option_not_found; 409cart_completed; 400shipping_price_missing|validation_failed. - SDK:
checkout.addShippingMethod(client, cartId, {option_id}).
# The whole manual path, executable: cart, method, collection, session, order.
CART2_JSON=$(curl -sf -X POST "$BASE/api/store/carts" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"email":"checkout-doc-manual-'"$RUN"'@example.test",
"items":[{"variant_id":"variant_01tst000000000000000002","quantity":1}],
"shipping_address":{"first_name":"Doc","last_name":"Manual",
"address_1":"Vitosha 2","city":"Sofia","postal_code":"1000",
"country_code":"bg","phone":"+359888123457"}}')
CART2_ID=$(echo "$CART2_JSON" | grep -o '"id":"cart_[^"]*"' | head -1 | cut -d'"' -f4)
curl -sf -X POST "$BASE/api/store/carts/$CART2_ID/shipping-methods" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"option_id":"'"$SO_ID"'"}' \
| grep -q '"shipping_option_id":"'"$SO_ID"'"'
# Fresh cart, no collection yet: sync reports why it cannot sync.
curl -sf -X POST "$BASE/api/store/carts/$CART2_ID/sync-payment-amount" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}' \
| grep -q '"reason":"no_payment_collection"'
PC2_JSON=$(curl -sf -X POST "$BASE/api/store/payment-collections" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"cart_id":"'"$CART2_ID"'"}')
echo "$PC2_JSON" | grep -q '"status":"not_paid"'
PC2_ID=$(echo "$PC2_JSON" | grep -o '"id":"pc_[^"]*"' | head -1 | cut -d'"' -f4)
SES_JSON=$(curl -sf -X POST \
"$BASE/api/store/payment-collections/$PC2_ID/payment-sessions" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"payment_method_id":"'"$PM_ID"'"}')
echo "$SES_JSON" | grep -q '"provider_id":null'
echo "$SES_JSON" | grep -q '"payment_method_name"'
echo "$SES_JSON" | grep -q '"status":"pending"'
# Error contract: the internal gift tender is not initiable.
GCS_RES=$(curl -s -X POST \
"$BASE/api/store/payment-collections/$PC2_ID/payment-sessions" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"provider_id":"pp_giftcard"}')
echo "$GCS_RES" | grep -q '"code":"invalid_provider"'
curl -sf -X POST "$BASE/api/store/carts/$CART2_ID/complete" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" -d '{}' \
| grep -q '"type":"order"'# save_payment_method on a GUEST cart is refused: subscribing needs an
# account (provider-independent: fires before any Stripe call).
CART3_JSON=$(curl -sf -X POST "$BASE/api/store/carts" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"email":"checkout-doc-guest-sub-'"$RUN"'@example.test",
"items":[{"variant_id":"variant_01tst000000000000000002","quantity":1}]}')
CART3_ID=$(echo "$CART3_JSON" | grep -o '"id":"cart_[^"]*"' | head -1 | cut -d'"' -f4)
PC3_JSON=$(curl -sf -X POST "$BASE/api/store/payment-collections" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"cart_id":"'"$CART3_ID"'"}')
PC3_ID=$(echo "$PC3_JSON" | grep -o '"id":"pc_[^"]*"' | head -1 | cut -d'"' -f4)
curl -s -X POST "$BASE/api/store/payment-collections/$PC3_ID/payment-sessions" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"payment_method_id":"'"$PM_ID"'","save_payment_method":true}' \
| grep -q '"code":"customer_required"'Stripe specifics (needs STRIPE credentials: not executable here)
# doc-noexec: requires the store's Stripe integration (admin-configured
# credentials).
PREP=$(curl -sf -X POST "$BASE/api/store/carts/$CART_ID/prepare-checkout" \
-H "x-client-id: $CLIENT_ID" -H "content-type: application/json" \
-d '{"shipping_address":{…},"shipping_method_id":"so_…","payment_provider":"pp_stripe"}')
# Answers {"cart_id":…,"payment_collection_id":"pc_…","client_secret":"pi_…_secret_…","provider_id":"pp_stripe"}
# Storefront: stripe.confirmPayment({clientSecret}), then POST …/complete.
# 3DS never-returned / redirect flows: payment_intent.amount_capturable_updated
# (a held card authorized) or payment_intent.succeeded (a method captured at
# confirmation) on the configured POST /api/webhooks/stripe endpoint completes
# the cart server-side; the order's write captures the hold.Sync/refresh behavior with Stripe follows the matrices above: in-place
paymentIntents.update keeps the secret stable; provider mismatch or a
terminal PI rotates (old PI voided best-effort); refreshPaymentIfTerminal
rotates only on succeeded/canceled/requires_capture/missing.
Admin-config-dependent contracts
checkout_method_hidden(400): requires an admin checkout rule.account_required(403): requiresaccounts_mode='required'on the store.- Payment method fee: any method may carry
fee_amount/fee_label(the COD method included); switching the method switches the fee, and the session the prepare call mints includes the fee.
Cleanup / accretion note
This page creates two carts and completes two method-tender orders on the shared dev tenant, the same inert accretion the checkout test suites produce (no store-facing delete exists for either; suites always create their own carts/orders and never re-read foreign ones).