Build a Two-Location Online Shop
A ceramics studio sells the same pieces from its workshop and its town shop and keeps overselling its limited drops and refunding by hand. You will build the replacement shop and prove it with a simulated trading day with failures injected.
The brief
The client
I run a small ceramics studio. We make mugs, bowls and vases in the workshop and sell them online and in a shop in town, about 60 online orders a day. The big pieces sit in the workshop and the small ones in the shop's back room, and we ship from both. When we released 30 glazed vases, 47 people paid for one in 25 minutes, because the site looked at the stock when the page opened and trusted it from then on. I wrote to 17 customers and refunded them by hand, and two were refunded twice because my partner and I both did it the same afternoon. An order that ships in two parcels has also been charged twice. I need a shop where the last vase sells once, where a piece held for a customer who walks away goes back on the shelf by itself, and where I can open an order and see exactly what happened to the stock and the money.
The problem
The shop keeps one stock number per product and checks it when a page loads. Two customers can pay for the last vase, and the second is found out only when someone goes to pack it. Stock sits in two places, but the shop sees one total, so the owner decides by hand which place ships which line, and an order for three pieces from both places is a note on paper.
Payment is taken at order time, so every cancellation and every short pick becomes a manual refund. The payment provider keeps a fee on each refund, so every avoidable cancellation after capture costs money. The product list on the shop front is rebuilt overnight, so a sell-out reaches the page up to a day late. Returns arrive with a note and no link to the order line, so refunds are typed in, and a typed refund can be sent twice.
The client's name and figures are invented for this brief; the rules and the failures are ones that real businesses of this kind work with.
The spec
Requirements
- Let the owner publish, change the price of and withdraw products, and show the shopper each product as in stock or out of stock, filtered by part of the name.
- Hold stock for a shopper at checkout, at named locations, for 15 minutes, and never sell the same unit twice, even when 100 buyers ask for the last one at the same moment.
- Let the studio receive stock, correct a count after a shelf check and move stock between the workshop and the shop, with moved units unsellable until received.
- Take payment by card through a payment provider that answers late, repeats itself and speaks out of order, and never hold stock or money past its deadline.
- Split an order across the two locations, ship each part as its own parcel, show the order as partly shipped, and charge the card once.
- Cope with a line the packer cannot find by moving it to the other location or cancelling and refunding it.
- Let a shopper or the owner cancel an order, or one line of it, before it is picked, with the stock released and the line's value returned.
- Let a shopper return items until 14 days after the last parcel of the order is delivered, inspect them, restock or write them off, and refund only the returned lines with their share of shipping and discount, once.
- Show an order's history from placement to refund in one view, ordered by when each thing happened, so the owner can tell a customer what happened to their stock and money.
- Lose nothing and double nothing when the shop is killed between saving something and the work that follows, and erase a customer's personal fields on request.
Deliverables
- Your repository starts the shop, the fake payment provider, the carrier stand-in and the simulated shoppers, packer and carrier with one command.
- A README that takes a reviewer from a fresh clone to an order that shipped in two parcels, with its history on screen, in 15 minutes, and lists the command for each test.
- A test suite covering each Phase's failure tests: the 100-buyer race, the scrambled provider messages, the carrier reports that arrive late or twice, the kills, and the trading day.
- A way to run the studio's day faster than real time, and to make the payment provider answer late, repeat itself, speak out of order, time out after accepting a request or fail, and the carrier report late or twice.
- A hold-rules note: every hold the shop makes, how long it lasts and what ends it.
- A one-page note for the carrier: how to report a parcel shipped or delivered, and what the shop answers to a report it refuses.
- An owner's guide of one page: how to read an order's history from placement to refund, and what to do when a refund fails.
- The results of the simulated trading day from the final Phase, committed to your repository.
Out of scope
- Search by attribute or free text. The product list filters by part of the name, because a search feature is a second system to keep right.
- Reallocating held stock when a count drops, safety stock and an offline location. A count correction that would go below what is held is refused.
- 3-D Secure and extra card authentication. The fake provider approves or declines.
- Handling card numbers. The provider gives the shop a reference for a card, and no card number is ever stored.
- VAT, credit notes and invoices. Tax rules are national, so every price is the amount the shopper pays, in euro cents.
- Real carrier integration. A stand-in reports parcels shipped and delivered.
- Promotions, accounts and emails. An order carries the discount and shipping amounts it is given, and the order view tells the shopper what happened.
- Disputes and chargebacks. A refund ends when the provider settles it.
- Deleting records after their retention period. Dutch law makes the studio keep its business records for 7 years (Belastingdienst), so erasure removes personal fields and keeps order, payment and refund records, identified by ID, for that period. Deleting them once the 7 years have passed is outside this brief.
- Backorders. A line nobody can pick is cancelled and refunded.
- Deployment. Everything runs locally with one command.
- Payment methods other than cards, such as iDEAL. The studio takes cards only, because the card is authorised at checkout and charged when the first parcel leaves, and iDEAL takes the money at once.
Architectural constraints
- Amounts are whole euro cents, and a share of shipping or discount follows one stated rounding rule and adds up exactly to the original amount.
- A unit is never sold twice. Every unit that ships was received, and no count the shopper or the owner sees is below 0.
- Every stock number the owner sees can be explained line by line from the changes behind it, and no change is edited afterwards. A shelf check that finds 28 where the shop said 30 adds a line of minus 2 with a reason.
- Every hold has an end. Stock held for a basket lasts 15 minutes until the order is confirmed. A confirmed hold ends by shipment, by cancellation or when the card authorisation runs out. A card authorisation lasts 7 days. Whatever nothing else resolves still ends at its deadline. The 14-day return window ends 14 calendar days after the last parcel of the order is delivered, holds nothing and is checked when a return is requested.
- Money is never captured before the first parcel of an order ships, and never captured twice.
- Money is never refunded beyond what was captured, whatever the shop is asked to refund.
- An order keeps the price it was started at. A later price change never reprices it.
- No card number is ever stored, logged or shown.
- A message that claims to come from the payment provider but is not signed correctly changes nothing.
- A fact reported from outside, such as a parcel shipped or a payment authorised, counts at the time it happened and not at the time it arrived. The order history is ordered by those times.
- Times the owner and shoppers see are in Europe/Amsterdam.
- On request, a customer's name, email and delivery address are erased or replaced with a pseudonym everywhere the shop keeps them, while orders, payments and refunds stay, identified by ID.
Prerequisites
You have built one application with a database, on any stack. You do not need to know how a ceramics studio sells from two places, or how stock holds, card authorisation or refunds work; the first Phase explains the business and the words the brief uses, each Checkpoint says what goes wrong and what it costs the studio, and the design is yours. You need to be able to send many requests to your running shop at the same moment, because the race tests do that. The beginner project Build a Two-Room Stock and Order Book covers the same domain at a smaller size and is not required.
Free to start. An account is what keeps track of the checkpoints you finish.
Publish products and count stock
Produces the rules of one order written down by hand, a catalogue with a price history, stock counts at two locations that can always be explained, and a product list shoppers can trust to be roughly current. Leaves holding stock for a buyer for the next Phase: nothing can be reserved yet.
Acceptance criteria
You write a decision table of hold rules in your repository, in a place you choose, for an order split across two places. It has three parts.
The first part is the order the table is about, in numbered steps, from the shopper opening checkout to a refund after a return. The order is 3 pieces, one vase from the workshop and two mugs from the shop, so it ships in two parcels. Each step names who acts (shopper, owner, packer, carrier, payment provider) and the fact that gets recorded, with the time that fact happened.
The second part is a table of every hold in the shop. The rows are the stock held for a basket (15 minutes), the stock held for a confirmed order, the card authorisation (7 days) and units in transit between the locations. The columns are what is held, when it starts, what ends it, and what ends it if nothing else does. The confirmed order's row names its three endings: a shipment, a cancellation and the authorisation running out. The 14-day return window appears below the table with the sentence that it holds nothing and is checked when a return is requested.
In the third part you decide six failures, one row each, and say for each which hold is still live and what ends it: the shopper closes the tab after the stock is held; the payment provider never reports back; the authorisation arrives 20 minutes after the stock was held; the payment provider answers with a server error three times in a row; the packer cannot find the lid of a mug after the order was placed; the shop is killed after saving a placed order and before any work that follows it has started. The last walk ends with a sentence saying what the shop does on restart so that nothing is lost and nothing happens twice.
Architectural guidance
A hold that has no end stays live after the customer has gone, so a vase sits held for someone who closed the tab and the shop shows it as sold out. Writing the table before any code shows you a hold you cannot explain in writing, which is cheaper to find now than in a customer's refund. The third part matters most because it lists the failures the final trading day injects.
Acceptance criteria
The owner manages products through whatever you offer at this point, and sees each product with its variants, their prices and a price history. The shop can be loaded with three products of one variant each: Glazed vase at 4,800 cents, Mug at 1,800 cents and Bowl at 2,600 cents. A second, larger load gives it 400 products with 900 variants in total, so the shop has a realistic list for later Phases. Prices are whole numbers of euro cents.
Publishing a product with two variants shows both, each with its product name, variant name and price. Kill the shop halfway through a publish and restart it: no half-published product is left behind.
Changing the Glazed vase price to 5,200 cents at 10:00:00 on the clock the simulator controls makes the owner's view answer 4,800 for 09:59:59 and 5,200 for 10:00:00. After a second change the history shows three entries, and none of the earlier entries was edited. Setting the price to the value it already has adds no entry.
A price of 0, a negative price or a price with a fraction of a cent is refused and nothing changes.
Withdrawing a variant takes it off sale. Asking for its current price is refused with a clear message, its history stays visible, and withdrawing it a second time changes nothing.
Architectural guidance
An order has to keep the price the shopper saw even after the owner changes it, so the shop must be able to say what any price was at any past moment. Money is whole cents because a share of a discount or a refund that carries a fraction of a cent ends as an amount the provider will not accept. A withdrawn product keeps its history because an old order still refers to it.
Acceptance criteria
The studio has two locations, WORKSHOP and SHOP. For each location and variant the owner sees the count and a history of stock changes that explains it. Each history line shows a signed quantity, a kind (receipt, shelf check, sent to the other location, received from the other location, shipped or returned to the shelf), a reason, a reference and the time. A check you provide (a command or a page) adds up the history of every variant and prints zero differences from the counts shown.
The studio receives 30 Glazed vases at WORKSHOP. The history gains a line of plus 30 and the count is 30. Receiving a quantity of 0 or less is refused.
A shelf check counts 28. The history gains one line of minus 2 with a shelf-count reason, the count is 28, and the earlier plus 30 line is unchanged. Counting 28 again adds no line. A counted quantity below 0 is refused.
Sending 5 vases from WORKSHOP to SHOP takes 5 off WORKSHOP at once and adds nothing at SHOP. While the transfer is in transit the count at WORKSHOP is 23, the count at SHOP is 0 and the sellable total across both is 23. Receiving the transfer adds 5 at SHOP. Receiving the same transfer a second time adds nothing and says it was already received, and so does a second receipt at the same moment from another person. A transfer of more than the source holds is refused.
After each step the sellable total across both locations reads 30, 28, 23 and 28 in turn. The explanation check prints zero differences after every step and after the 400-product seed.
Architectural guidance
A number that can be overwritten cannot answer "what happened to the two missing vases, and when", and the owner needs that answer to settle a count with a partner or a customer. Units in transit that the shop counts nowhere are what stop it selling five vases that are in a van. A transfer received twice, once by each of two people who both saw it arrive, would otherwise put ten vases on a shelf that holds five.
Acceptance criteria
Shoppers see a list with one row per variant: the name, the price in cents, and in stock or out of stock. A filter matches a part of the name without regard to case.
Publish the Glazed vase and receive 30 at WORKSHOP. Within 1 minute the list shows the vase at 4,800 cents and in stock. Filtering for "vase" returns it and filtering for "mug" does not. Move the count to 0 through a shelf check and the list shows out of stock within 1 minute. Change the price and the list shows the new price within 1 minute. Withdraw the vase and it disappears from the list within 1 minute.
Make the same change twice in a row, such as the same price change sent twice, and the list shows one row for the variant. Stop the shop and start it again with the 900 seeded variants: the list shows the same rows as before.
Sell out the vase and kill the shop right after the vase's count reaches 0. After the restart the list shows the vase out of stock within 1 minute.
The list is never the answer to whether a sale can go ahead. Phase 2 checks this by asking for the last unit while the list still says in stock.
Architectural guidance
A list can lag a little, which is why it is a hint for the shopper and never the answer to "can this order be placed". If the shop dies right after a sell-out and the list never hears of it, the page keeps showing a gone vase until someone notices.
Architectural walkthrough
How a ceramics studio sells from two places
The client is a small ceramics studio. It makes mugs, bowls and vases in its workshop and sells them online and from a shop in town, about 60 online orders a day. Big pieces sit in the workshop and small ones in the shop's back room, and the studio ships from both. An order can need pieces from both places, and then it ships as two parcels.
A shopper picks pieces and the shop holds them for 15 minutes while the shopper pays. The shop takes cards only. At checkout the card is authorised, which sets the money aside without taking it, and the money is captured when the first parcel leaves. An authorisation lapses after 7 days if nobody captures it. The payment provider keeps a fee on each refund, so a cancellation after capture costs the studio money.
When a piece is missing from the shelf, the studio either picks it from the other place or cancels the line and refunds it. A shopper can return items until 14 days after the last parcel is delivered. The studio inspects them and puts them back on sale or writes them off. The studio also moves stock between the workshop and the shop, counts the shelves now and then and corrects the count. It keeps its business records for 7 years, which Dutch law requires.
The words this brief uses:
Location: a place that holds stock, here the workshop or the shop.
Hold: stock kept for a shopper at checkout for 15 minutes.
Authorisation: the card issuer's promise to pay, which sets the money aside.
Capture: taking the authorised money. It happens when the first parcel ships.
Partly shipped: an order of which some parcels have gone and some have not.
Transfer: moving stock between the workshop and the shop. Moved units cannot be sold until received.
Shelf check: counting the stock by hand and correcting the shop's number.
Restock and write-off: putting a returned piece back on sale, or recording that it is lost.
Refund: sending money back to the card for the returned or cancelled lines.
Why the holds and the stock come first
The old shop held one stock number per product and overwrote it. A shelf check that found 28 vases where the shop said 30 replaced one number with another, and nothing recorded that two vases had gone missing or when. The studio could not settle a count with a partner or answer a customer who asked where an item went.
Before any code, this Phase has you work one order through by hand, because a hold you cannot explain in writing is a hold that stays live after the customer has gone: 15 minutes of a vase, 7 days of a card balance, five vases in a van between the workshop and the shop. Each of them needs an end, and the owner needs to know which one is still live at any moment.
Stock has a second problem. Units sent between the workshop and the shop are in neither place while they travel, and if the shop counts them anywhere in between it sells five vases that nobody can pick. A transfer received twice, by two people at the same moment, must still add five units and not ten.
The product list on the shop front is only a hint. The old shop rebuilt it overnight, so a sell-out reached the page up to a day late and shoppers paid for pieces that were gone. A list that lags by a minute is acceptable. A list that never hears about a sell-out because the shop died at the wrong moment is not, and a sale never goes ahead or is refused because of what the list says.
Reserve stock with a deadline
Produces held stock for a basket taken from the right location, a 15-minute deadline that gives units back by itself, and a concurrent test that proves a unit sells once. Leaves payment and orders for later: a hold here has no order behind it.
Acceptance criteria
The shop can hold a basket for an order reference. The request takes the reference and a list of lines (variant and quantity), through whatever you offer at this point. The answer gives, for each line, the location or locations it comes from and the quantity at each, and an end time exactly 15 minutes after the time of the request on the simulator's clock. Holding stock lowers the sellable count at each location and leaves the count of what is physically there, and its history, alone. Each case below starts from this seed: WORKSHOP holds 6 Glazed vases and no mugs, SHOP holds 2 vases and 10 mugs.
A basket of 1 vase and 2 mugs: SHOP can cover the whole basket and WORKSHOP cannot, so both lines come from SHOP.
A basket of 4 vases and 3 mugs: neither location covers it. Each line comes from the location holding more of its variant, so 4 vases come from WORKSHOP (6 against 2) and 3 mugs from SHOP.
A basket of 7 vases: neither location holds 7, WORKSHOP holds more, so 6 come from WORKSHOP and 1 from SHOP.
A basket of 1 vase: both locations can cover it, and WORKSHOP holds more of the basket's variants, so it comes from WORKSHOP. With both locations holding 3 vases the tie goes to WORKSHOP.
A basket of 9 vases and 1 mug is refused because the two locations hold 8 vases together. Nothing is held: the sellable counts are unchanged at both locations and the 10 mugs are still sellable.
After the basket of 1 vase and 2 mugs, the sellable total for the vase is 7 and for the mug 8, and the product list from Phase 1 shows that within 1 minute. Asking twice with the same order reference returns the same hold and holds once, and so do two identical requests sent at the same moment. A quantity of 0, a negative quantity and an unknown variant are refused.
Ask for the last unit of a variant while the product list still shows it in stock because the list has not caught up. The request is refused when no unit is left.
After the basket of 4 vases and 3 mugs, a shelf check at WORKSHOP that counts 3 vases is refused with a clear message and changes nothing, because 4 are held there. Counting 4 is accepted. The explanation check from Phase 1 prints zero differences after every case, and the held quantities shown equal the sum of the live holds.
Architectural guidance
A buyer who is told yes on counts that someone else has already used up ends with a refund and an apology, and the owner decides by hand which place ships which line. A basket held in part keeps units that no order will ever use. A shelf count below the held quantity promises a vase that a recount just said is gone.
Acceptance criteria
A hold is held, confirmed, released, expired or shipped, and the owner can see which. Whoever made a hold can confirm it, and can release it. Stock held for a shopper who walks away is sellable again within 1 minute of the deadline, with nobody asking.
Take a hold made at 10:00:00 for 2 vases. At 10:14:59 it is still held. At 10:15:00 it is expired, the 2 vases are sellable again and the product list shows that within 1 minute. Running the clock past 10:15:00 again changes nothing.
Confirm the hold at 10:14:00. At 10:16:00 it is still confirmed and the units are still held. Confirming a hold at 10:15:00 or later is refused as expired, even when nothing has yet given the units back, and the units are free or become free within the minute. Confirming an expired or released hold is refused.
Releasing a held hold frees its units and shows it as released. Releasing it a second time changes nothing.
Make three holds expire at the same moment and kill the shop while it is giving back the second. After the restart all three are expired and their units are sellable, and no unit is counted free twice: the sellable count never exceeds what is on the shelf. No hold shows its units freed and its state still held. The explanation check from Phase 1 prints zero differences after each step.
Architectural guidance
Most holds end with an order, but a shopper who closes the tab sends nothing, so something has to give those units back on its own. A shop that dies halfway through giving units back can leave a hold that shows as held while its units are already free, or count the same units free twice and sell a vase that is not there. A confirmation that arrives at the deadline but before the units are given back must still be refused, or an order confirms units that are about to be freed.
Acceptance criteria
A test suite named for the race sends requests to the running shop as it would run for the studio, with each of the 100 buyers asking at the same moment so the requests overlap in time. A test that sends requests one at a time cannot fail and does not count. The README says what the test needs to run.
Seed 10 Glazed vases: 6 at WORKSHOP and 4 at SHOP. One hundred buyers each ask to hold 1 vase at the same moment. Exactly 10 holds succeed and 90 are refused as out of stock. The held quantity is 6 at WORKSHOP and 4 at SHOP, the sellable total is 0, the product list shows the vase out of stock within 1 minute, and the explanation check from Phase 1 prints zero differences.
Seed 10 vases as above and 100 mugs at SHOP. One hundred buyers each ask to hold a basket of 2 vases and 1 mug. Exactly 5 succeed. The other 95 are refused whole, and the held quantity of mugs is exactly 5, so no refused basket kept a mug.
Seed 200 vases at SHOP. Fifty buyers each send the same hold request for 1 vase twice at the same moment, with the same order reference both times. Each reference ends with exactly one hold, and the held quantity is exactly 50.
Across all runs, every answer is a success or the out-of-stock refusal. No request fails with a server error, times out or tells the buyer to try again.
The test can fail. Run it against a deliberately careless copy of your shop that lets two buyers see the same last unit: it reports more than 10 successful holds in at least one of several runs.
Architectural guidance
A shop that is right when requests arrive one at a time is the old shop's bug in a new place. Two buyers who both see 1 left and both pay take the same vase, and the second one finds out when the packer opens the shelf. Baskets of several pieces add a second failure: two shoppers who each hold part of what the other needs can leave both waiting, and each sees an error where "sold out" should be.
Architectural walkthrough
When the studio released 30 vases, the site read the stock when the page opened and trusted it afterwards, so 47 people paid. This Phase settles that decision at the moment of asking: the shop grants a unit, and a unit it grants is held for 15 minutes and then given back.
Two buyers who both see "1 left" and both pay take the same vase. The failure does not show with one buyer at a time, so the only test that means anything sends many buyers at the same moment to the running shop. The failure gets worse with baskets of several pieces. A basket needs a vase from one location and mugs from the other, and two baskets that each take part of what the other needs can leave both shoppers waiting, with an error where "sold out" should be.
The location rule makes it harder than one counter. The studio wants a basket to ship from one place when one place can cover it, and from the place holding more of each piece when neither can. A basket sent to a location because of counts that another buyer changed a moment earlier ships from a shelf that no longer has the piece.
The deadline is the second problem. Most holds end with an order, but a shopper who closes the tab sends nothing. Without something that gives those units back on its own, a closed tab holds a vase until someone notices. A shop that dies halfway through giving units back must not leave a hold that shows as released while its units are still counted as held, or the other way round.
Take payment
Produces a fake payment provider that misbehaves on demand, and payments that hold card money for at most 7 days and stay true when the provider repeats itself or speaks out of turn. Leaves capture and refund for later Phases: money is only held here, never taken.
Acceptance criteria
You build a fake payment provider that behaves like the real one in the ways listed here. How you build it, how the shop talks to it and what its requests look like are yours. The one command that starts the shop also starts the fake.
The fake keeps its own record of every authorisation, capture and refund. A test can read that record, and wiping the shop's data leaves it unchanged. It accepts only the reference the provider gives for a card, and it refuses a 16-digit card number, so the shop never holds one. It knows a card that gets approved, a card that gets declined and a card on which it fails with a server error.
Every request carries the shop's own reference, such as an order id, and the provider repeats that reference in every message it sends about the request. The provider can tell a retry of a request from a new request.
Asking for an authorisation of 4,800 cents on the approved card for reference order-1 is answered with "accepted, pending" and an authorisation id. The answer does not say whether the card was approved. Within 1 second a message reaches the shop: the authorisation succeeded, with a unique message id, the time the fact happened on the provider's own clock, the reference and the amount. The message is signed with HMAC-SHA256 over its raw body and a secret the shop and the fake share, and the signature travels with the message. The declined card ends in a message that the authorisation failed because the card was declined. The error card is answered with a server error and creates no authorisation. When the shop does not answer a message with success, the provider sends the same message again, up to 3 more times, after gaps that grow on the provider's clock: 1 second, then 10 seconds, then 100 seconds. A real provider keeps retrying on a schedule that runs for up to 3 days, so the fake compresses that schedule to 111 seconds, and a test reaches each retry by advancing the provider's clock.
A retry of the authorisation request returns the first answer, and the provider's record still holds one authorisation and one message. The same request retried with 5,200 cents is refused as a conflict.
Capture and release follow the same rules. Capturing 4,800 is accepted and later reported as captured. Capturing 4,801 is refused as more than was authorised. A second capture is refused as already captured. Releasing an uncaptured authorisation reports it released, and releasing a captured one is refused. The provider lapses an authorisation after 7 x 24 hours on its own clock: a capture at 167 hours 59 minutes 59 seconds is accepted and one at 168 hours is refused as expired.
A refund of 1,800 cents on a captured 4,800 is accepted as pending. No message arrives for the first 9 seconds of provider time. At 10 seconds one message reports the refund settled, with a refund id and the amount, and it carries no fee field although the provider keeps a fee on every refund. A further refund of 3,100 is refused as more than was captured, because 1,800 + 3,100 is more than 4,800, and a refund of 3,000 is accepted.
The provider has its own clock, and a test advances it without sleeping. A test can switch on each of these: change the refund delay (10 seconds by default); accept the next request, process it and never answer it; send every message twice with the same id; hold every message for a number of seconds of provider time; and hold messages until 3 are waiting and send them in reverse order of creation. With "accept and never answer" on, send a refund that the shop gives up on after 5 seconds: the provider's record holds one refund, pending. Send it again as a retry and the first refund comes back and the record still holds one. Send it again as a new request and the record holds two, which is the double refund the studio suffered.
Architectural guidance
The provider's first answer says only that it received the request, and the outcome comes later, so the shop has to live with an answer it cannot act on yet. A stand-in that answers at once and in order can never show the failures that cost the studio money: a refund sent again after a timeout goes out twice, and a message held for 20 seconds arrives after a newer one. Phases 3 to 5 are tested against the behaviours in this Checkpoint, so a stand-in that cannot do them leaves those tests with nothing to find.
Acceptance criteria
Through whatever you offer at this point, the shop can ask for a hold of an amount on a card for an order reference. It answers "waiting for the provider" at once, without waiting for the outcome. The payment shows as authorised only when the provider's message says so. Asking twice for one order reference gives one payment and one authorisation at the provider, and so do two identical requests at the same moment. An amount of 0 or less, or something that is not a card reference from the provider, is refused and nothing is sent.
Ask for 4,800 on the approved card, and let the provider send its message with the time 2 Nov 2026, 09:00 UTC. The payment is authorised, and its authorisation time is that time. The declined card ends with the payment declined, with the reason that the card was declined. The error card, which makes the provider answer with a server error, ends with the payment failed at once, with a reason that says the provider failed.
Switch on "accept and never answer". The shop gets no answer within 5 seconds, the payment stays "waiting for the provider", and a retry leaves one authorisation at the provider. The outcome then arrives by message. This is the unknown outcome the shop has to live with.
Kill the shop right after the authorisation request has left it. After the restart the provider holds one authorisation for the order, and the payment ends authorised once the message arrives.
Releasing an authorised payment gives the held money back and the provider's record shows it released. Releasing a payment that is still waiting for the provider records the wish, and when the authorisation then succeeds, the shop releases it at once and the provider's record ends with it released. Releasing twice, or releasing a failed or declined payment, sends nothing.
An authorisation that nobody has captured or released lapses at 7 x 24 hours without anyone asking. A payment authorised at 2 Nov 2026, 09:00 UTC is still authorised at 9 Nov 2026, 08:59:59 UTC. At 9 Nov 2026, 09:00 UTC it shows lapsed within 5 minutes. Checking again changes nothing. A released, failed or declined payment never lapses.
Architectural guidance
A shop that dies right after sending a request can send it again after the restart, and the card is held twice. The 7-day limit is a hold that ends by itself, so the shop has to notice it even when no message comes.
Acceptance criteria
The shop checks the signature over the raw body of every provider message. A wrong or missing signature is refused and nothing is stored or changed. A message with no time of its own is refused and changes nothing. Otherwise the shop answers the provider with success within 1 second, even when its own work is slow, and then acts on the message. A message whose reference matches no payment changes nothing, shows up for the operator as having no order, and is answered with success so the provider stops repeating it.
An operator can read a record of every provider message the shop received: the message id, the type, the time on the message, when it arrived, what the shop did with it (acted on it, set it aside, or found no order for it) and, for one set aside, why.
A payment moves forward only. The allowed paths are waiting for the provider to authorised to captured, waiting or authorised to released, and waiting to failed or declined. This Checkpoint handles the messages for authorised, failed, released and captured. Refund messages are shown to the operator and wait for Phase 5. A message that would move a payment backwards or sideways is set aside, with the reason that the payment is already past that state, and changes nothing about it. A later fact implies the earlier steps: when a released or captured message reaches a payment still waiting for the provider, the payment moves straight to the later state and shows one authorisation. The payment shows the time of each fact from the message that proves it (authorised, captured, released), and a set-aside authorised message still supplies the authorisation time when the payment has none. A payment whose authorisation time is not yet known does not lapse.
Deliver an authorised message three times. The operator sees one entry for it, and the payment is authorised and shows one authorisation. For a fresh payment, deliver a released message (time 10:00:09) and then an authorised message (time 10:00:05). The payment is released, the authorisation time is 10:00:05, the release time is 10:00:09, it shows one authorisation, and the authorised message is shown as set aside. Delivering the same two in the other order gives the same state, the same times and the same authorisation count. A captured message that arrives before any authorised message leaves the payment captured, with one authorisation. Two copies of one message that reach the shop at the same moment count once.
Kill the shop while it is acting on a message, then restart it. The message counts once: the payment and what the operator sees match a run with no kill.
Architectural guidance
A provider repeats a message when the shop answers slowly or not at all, so the same fact arrives more than once, and it sends a fact late when its own backlog grows. If the shop is slow to answer, the repeats multiply and make it slower. A late "authorised" message that pulls a released payment back to authorised lets an order take stock for money the shop has already given back. Without a signature check, anyone who guesses the shop's address can mark an order paid.
Acceptance criteria
A test suite named for the property sends provider messages to the running shop with the shop doing its normal work, and checks only the payments the shop shows.
First, an exhaustive check on one payment. The facts are "authorised" (time 10:00:05) and "released" (time 10:00:09), each sent twice with the same message id, which makes 4 messages. Every distinct ordering of those 4 messages, 6 in all, is delivered. In every ordering the payment ends released, the authorisation time is 10:00:05, the release time is 10:00:09, the payment shows one authorisation and the operator sees 2 entries. The same check runs for "authorised" (10:00:05) and "captured" (10:30:00) with each sent 3 times, which is 20 orderings, and every one ends captured with one authorisation. A payment with the "failed" message sent twice ends failed.
Second, a seeded shuffle. A generator creates many payments, gives each one of the sequences above, adds extra copies of every message, shuffles the whole stream with a seed printed at the start of the run and delivers it. Every payment's final state, its times and its number of authorisations equal what in-order delivery of the same facts gives. A failing run prints the seed and the order so the failure replays.
Third, end to end with the fake provider. Switch on duplicate messages (1 extra copy), a hold of 20 seconds of provider time and reordering. Ask for a batch of authorisations, most on the approved card and some on the declined card, then release some of the approved ones. Advance the provider's clock until it has sent everything. Each payment's state matches the provider's own record. Every approved payment shows one authorisation, released ones included, and every declined payment shows one failure. The operator sees one entry for each distinct message id the provider sent. No entry is left unhandled, and every entry set aside has a reason.
The suite can fail. Run it against a deliberately careless copy of the shop that trusts the order messages arrive in and treats every copy as new: the exhaustive check fails for it on at least one ordering, and the report names that ordering.
Architectural guidance
A suite that delivers messages in the order they were created passes a shop that is wrong about order, and the bug first shows when the provider is slow on a busy day. The property worth testing is that whatever order and however many copies arrive, the payment ends where in-order delivery would have left it. Printing the seed is what lets you replay a shuffle that fails.
Architectural walkthrough
The old shop charged the card when the customer ordered, so every cancellation became a manual refund and every refund cost the studio a provider fee. This Phase puts the order the other way round: ask the provider to hold the money, take it later, and show a payment that stays true when the provider repeats itself or speaks out of turn.
The provider's first answer only says it received your request. The outcome comes later, as a message the provider sends to your shop when something finishes. So the shop has to act correctly when it asks twice, when it hears twice, and when it hears in the wrong order. A request that timed out may still have succeeded, and treating the timeout as a failure leaves money held on a card that no order knows about.
Three words recur. An authorisation is the provider's promise to keep an amount on the customer's card for you, for at most 7 days. A release gives that promise back before you take the money. A lapse is the promise running out because nobody took the money in time. All three are holds with an end, like the stock hold in Phase 2.
A stand-in that always answers at once and in order cannot show any of this, so the first Checkpoint has you build one that can be late, repeat itself, reorder its messages and stay silent. The rest of the build is tested against it.
A payment must only move forward, and it must show when each fact happened on the provider's clock. Without that, a late "authorised" message pulls a released payment back to authorised, and the next Phase takes stock for money the shop has already given back.
Place and ship an order
Produces a priced order that gives back stock and card on any failure, one parcel per location, and a single capture at the first shipment. Leaves cancellation, returns and refunds for the next Phase: an order can be placed and shipped here, and nothing takes it back.
Acceptance criteria
A shopper places an order that is waiting for payment by giving the order and the approved or declined card. The shop holds the stock for the order's lines, asks the provider for a hold of the order total, and when the authorisation succeeds confirms the stock and shows the order as placed. An order ends placed or cancelled, and a cancelled order shows its cause in plain words: card declined, out of stock, hold expired or authorisation ran out. Placing the same order twice at the same moment holds the stock once and asks the provider for one authorisation.
The order view lists the history of an order: one row per thing that happened, with a short description and the time it happened, shown in Europe/Amsterdam. A fact that reaches the shop late but happened earlier appears above the facts that followed it. Every case below leaves rows for the stock hold, the payment request, the outcome and the final state.
A happy order on the approved card is placed with its stock confirmed, and its total is 10,600 for the basket in the first Checkpoint of this Phase. On the declined card the order is cancelled with the card-declined cause, the stock hold is released, the sellable counts are back to what they were, and the order is never shown as placed. A basket the stock refuses is cancelled with the out-of-stock cause, and the provider's record shows 0 authorisations for it.
A shopper closes the tab: the stock is held at 10:00:00 and the card is authorised, but the shopper never completes. At 10:15:00 the hold has expired and the order is cancelled with the hold-expired cause. The authorisation is released, or, if it is still waiting for the provider, marked to be released.
The authorisation arrives after the stock hold expired. With the provider set to hold its success message until 10:20:00, the order was already cancelled at 10:15:00, and the shop releases the authorisation the moment the message lands. The provider's record shows it released. In a second variant, nothing has yet given the units back at 10:15:00 when the authorisation succeeds. The order still ends cancelled with the hold-expired cause, with the stock free and the authorisation released. When both of those happen to one order at the same moment, the order is cancelled once, the stock is released once and the authorisation is released once.
A placed order whose authorisation runs out at 7 x 24 hours before any parcel ships is cancelled with the authorisation-ran-out cause, and its confirmed stock hold is released.
Kill the shop at two points on two different orders, restart it, move the clock to 15 minutes after the stock hold and let the shop run. Killed after the stock hold was made: the hold has expired and the order is cancelled. Killed after the authorisation request was sent: the order is cancelled and the provider's record shows the authorisation released. After each kill, no stock hold lasts past 15 minutes and the provider shows no authorisation live for that order beyond its release or its lapse.
Architectural guidance
Stock and money are two holds on two different things, so a failure at any step has to give back both. The authorisation that arrives after the stock hold expired is the case that breaks a shop that gives back only the stock: the shopper's card stays held for 7 days for a vase they never got. Two different failures can reach the same order, such as the expiry and a refused confirmation, and a shopper who is cancelled twice may be refunded twice. A report that reaches the shop late describes something that happened before the facts that followed it, so the history has to read in the order things happened.
Acceptance criteria
A placed order is split into parcels, one for each location it ships from. The basket of one Glazed vase from WORKSHOP, two Mugs from SHOP and one Bowl from SHOP gives two parcels: one for WORKSHOP with the vase, and one for SHOP with the mugs and the bowl. An order whose pieces all come from one location gives one parcel. A basket of 7 vases held as 6 at WORKSHOP and 1 at SHOP gives two parcels, and the one line appears in both with quantities 6 and 1. An order that goes through a restart, or is placed twice at the same moment, still gets its parcels once.
Kill the shop after an order is placed and before its parcels exist. After the restart the order has its parcels, once.
You build a carrier stand-in. The shop hands it each new parcel. The stand-in reports a parcel as shipped 2 hours after the handoff and as delivered 24 hours after it, each report carrying the parcel and the carrier's own time of the fact. A report with no time is refused. A report for an unknown parcel is refused. A fact repeated for the same parcel is accepted and changes nothing more. The stand-in has its own clock, and a test advances it. A test can switch on two behaviours: hold every report for a number of hours of stand-in time after the fact happened, and send every report twice.
The time recorded for a shipped or delivered fact is the carrier's time, not the time the report arrived. With reports held for 3 hours, a delivered fact that happened at 3 Nov 2026, 10:00 UTC and arrives at 13:00:00Z is recorded at 10:00:00Z in the order's history.
When a parcel ships, its units leave the shelf: the count of what is on the shelf and the held quantity both fall by the parcel's quantity at the parcel's location, and the sellable count does not change. Shipping the same parcel twice, including two reports that arrive at the same moment, takes the units off once. The explanation check from Phase 1 prints zero differences. A hold ends as shipped when all its lines have shipped.
The order shows as partly shipped after the first parcel ships and as shipped after the second. Each line gets a delivery time from its parcel's delivered fact, and the order shows as delivered once every parcel has both facts. A delivered fact that arrives before the shipped fact for the same parcel is kept, and when the shipped fact arrives the stock and the order state end the same as in the normal order. Every shipped and delivered fact appears in the order history at its own time.
Architectural guidance
A parcel is the unit a carrier picks up and reports on, and two locations are two physical shelves, so one parcel per location follows. The delivery fact of the order's last parcel sets the end of the 14-day return window in Phase 5, and a fact uploaded late must not move it. Shipping takes units off the shelf and out of the held quantity in the same step, so the shop never shows a shipped unit as both held and gone.
Acceptance criteria
When the first parcel of an order ships, the shop takes the held money. It captures the authorised amount minus the amount given back so far, which is 0 until Phase 5. The provider's first answer only acknowledges the request, and the outcome arrives as a message. When that message is applied, the order shows the captured amount and a history row at the message's time.
The basket from the first Checkpoint of this Phase was authorised for 10,600. The WORKSHOP parcel ships at 2 Nov 2026, 09:00 UTC, and the provider's record then shows one capture request of 10,600. The SHOP parcel ships at 12:00:00Z and the provider's record still shows one capture request. The order shows a captured amount of 10,600 once.
A repeat of the first shipped report creates no second request. Two copies of the first shipped report that arrive at the same moment lead to one request at the provider. With the provider set to accept the capture request and never answer, the shop's retry leaves one capture of 10,600 in the provider's record. A repeated "captured" message changes nothing.
Kill the shop right after the capture request has left it. After the restart the provider's record holds one capture of 10,600.
The shop refuses to capture a payment that is not authorised. For a payment that is released, lapsed, declined or failed, nothing is sent to the provider, and the order history gets a row saying the capture was refused and showing the payment's state.
Architectural guidance
The studio promised card holders a charge only for goods that left the building, and a charge per parcel is how the old shop took the money twice. A repeated shipped report, a retry after a timeout, two copies of a report handled at the same moment and a restart after a crash can each send a capture, and each one charges the customer. The amount charged can fall below the authorised amount once cancellations exist, which they do in the next Phase.
Architectural walkthrough
The old shop charged the card for an order that shipped in two parcels once per parcel, and the owner found out when the customer wrote in. This Phase sells a basket correctly: price it once, hold the stock and the money, ship from each location, and take the money exactly once.
A placed order holds two things, stock and money, and whichever step fails must give back both. The case that finds the gap is an authorisation that reaches the shop after the stock hold has already expired. If only the stock is given back, the shopper's card stays held for 7 days for a vase they never got. Two different failures can also reach the same order at once, such as the expiry and a refused confirmation, and the shopper must not end up with two cancellations or two releases of the same hold.
The order's price is fixed when checkout starts, and the shipping and the discount are split across lines at that moment. A later refund for one line has to give back that line's part of both. Shares recomputed later from changed prices give a different answer from the one the order was priced with.
The money is taken once, when the first parcel ships. The carrier is a partner whose reports can arrive hours late and twice, and a delivery report keeps the time the parcel was delivered, not the time the upload arrived. If the shop dies after placing an order and before the parcels exist, the shopper has paid for an order that nobody packs.
The order view starts here. It must show what happened to a customer's stock and money in the order it happened, even when a late report describes something that happened before the facts that followed it.
Cancel, return and prove the whole
Produces short-pick handling, line and order cancellation, returns with inspection, refunds that cannot exceed what was captured, and a simulated trading day with failures injected. Leaves nothing for later: this Phase closes the build.
Acceptance criteria
The packer is a simulator command (the name is yours). It reports a piece not found with the order, the line, the location, the quantity and the packer's own time. A report with no time, a quantity of 0 or less, a location the line is not held at, or a quantity above what remains of the line at that location is refused and changes nothing. A report for a line whose parcel has already shipped is refused.
An accepted report has one outcome. The missing piece is taken off the count at the location where it was not found, with a history line of minus the quantity and a short-pick reason. If the other location's sellable count covers the whole short quantity, the shop holds that quantity there and moves the piece to that location's parcel. Otherwise the quantity is marked unavailable and nothing moves. The move is all or nothing: a short quantity of 2 with 1 available elsewhere makes 2 unavailable. The same piece is never both moved and marked unavailable.
Take the order with one vase from WORKSHOP, two mugs and a bowl from SHOP. The vase is not found at WORKSHOP and SHOP holds 2 sellable vases. The count at WORKSHOP falls by 1 with a short-pick line, 1 vase is held at SHOP, and the vase sellable total goes down by 1. The SHOP parcel now holds the mugs, the bowl and the vase, and the WORKSHOP parcel, left with no lines, disappears and is never handed to the carrier. If the SHOP parcel has already shipped, the relocated vase goes in a new parcel.
Take the same order where the packer cannot find one of the two mugs at SHOP and WORKSHOP holds 0 mugs. The count at SHOP falls by 1 with a short-pick line, and the order shows 1 of the 2 mugs as unavailable, with a history row. The cancellation and refund of that mug happen in the next Checkpoint.
Reporting the same short pick twice, including twice at the same moment, takes one piece off the count. Kill the shop right after the missing piece comes off the count: after the restart the piece is moved or marked unavailable, once. The explanation check from Phase 1 prints zero differences after each case.
Architectural guidance
A missing piece means the count was wrong and a customer is short a piece, and the studio must decide once what happens to it. If the decision is made twice, the line can be moved and cancelled at the same time, and the customer ends with a piece in a parcel and a refund for it. A count that is overwritten hides how many pieces went missing and why. A line split across two parcels with a quantity the shopper never ordered cannot be packed.
Acceptance criteria
A shopper or the owner can cancel a quantity of a line, with a cause (the shopper asked, the owner asked, or the stock was unavailable), while the parcel holding that line has not shipped. A cancel for a shipped line is refused and changes nothing. Cancelling every line of an order that has shipped nothing is a whole-order cancel. Cancelling more than the quantity that remains on a line is refused. The cancelled units become sellable again, and the hold stays confirmed while lines remain and ends when none do. The unavailable mug from the previous Checkpoint is cancelled this way with the out-of-stock cause.
The give-back for a line uses its value from checkout. Cancelling k units of a line of q units with value v, after c units of that line were already cancelled or returned, gives back floor(v x (c + k) / q) minus floor(v x c / q). The two mugs have a value of 3,469, so cancelling one mug gives back 1,734, and cancelling the other later gives back 1,735, which makes 3,469 in total.
What happens to the money depends on where it is. Take an order authorised for 10,600 and not captured. A whole-order cancel releases the authorisation, and the provider's record shows it released. A line cancel of one mug (1,734) sends nothing to the provider, the order shows 1,734 given back, and when the first parcel ships the capture is 10,600 minus 1,734, which is 8,866. The provider's record shows a capture of 8,866.
Take the same order after the first parcel shipped and 10,600 was captured. A line cancel of the Bowl in the unshipped parcel (value 2,506) sends a refund request for 2,506. The provider accepts it as pending, and 10 seconds of provider time later the refund is reported settled. Before that, the order history shows the refund as requested, and after it a row at the message's time shows it settled. A message that the refund failed puts a row in the history with the amount and the reason.
The refund is capped. The shop never refunds more than the captured amount minus what it has already refunded. Make the shop ask for 9,000 after the 2,506 refund, by whatever route your tests use for an oversized request: it refunds 8,094, the remaining 10,600 minus 2,506, shows the refund as capped, and a further request refunds 0 and sends nothing. The provider never has to refuse a refund as too large.
Cancelling the same line twice, including twice at the same moment, creates one refund. Switch on "accept and never answer" for the refund request: the shop's retry leaves one refund in the provider's record. Kill the shop right after a cancel is accepted and before the refund request reaches the provider: after the restart there is one refund. Two cancels of one mug each are two cancels with two refunds, 1,734 and 1,735.
A cancelled quantity is removed from the unshipped parcel, and a parcel left with no lines disappears. An order cancelled by the 7-day lapse or the expired hold in Phase 4 loses its parcels the same way. Cancelling the last unshipped line of a partly shipped order leaves the order shipped.
Architectural guidance
What a cancel means for the money depends on whether the money has been taken yet. A refund sized from the order total instead of the captured amount is how a shop returns more than it received. A timeout after the provider accepted a refund, a cancel pressed twice by two people and a restart after a crash can each send the refund again, and the provider keeps a fee on every one. Two separate cancels of one line are two refunds, so telling a repeat from a second cancel matters. Rounding the give-back so the pieces of one line add up to its value keeps the last piece from being a cent short.
Acceptance criteria
A return request takes an order, a line and a quantity. The shop reads what was delivered, when, and how much of the line is already cancelled or returned. An accepted request shows as "return requested", with a row in the order history. No stock moves and no money moves at this point.
The window is 14 calendar days in Europe/Amsterdam, counted from the day of the delivery fact's own time of the last parcel of the order, and it is the same for every line of the order. If the last parcel is delivered at any time on day D, every line can be returned through 23:59:59 on day D + 14. A parcel with every line cancelled does not count as a parcel of the order. While a parcel of the order is still undelivered, the delivered lines can be returned. A single-parcel order delivered at 2 Nov 2026, 22:30 UTC is 23:30 on 2 Nov 2026 in Amsterdam, so a request at 16 Nov 2026, 22:59:59 UTC is accepted and one at 16 Nov 2026, 23:00 UTC is refused because the window has closed. A single-parcel order delivered at 2 Nov 2026, 23:30 UTC is 00:30 on 3 Nov 2026 in Amsterdam, so the window runs through 17 Nov 2026, 22:59:59 UTC. A delivery fact that uploaded on 5 Nov 2026 with a time of 2 Nov 2026 counts from 2 Nov 2026.
An order with two parcels has its first parcel delivered on Tue 3 Nov 2026, 10:00 Amsterdam time and its second on Fri 6 Nov 2026, 15:00, with the second fact uploaded on 9 Nov 2026. Every line's window runs through 20 Nov 2026, 23:59:59 Amsterdam time (22:59:59 UTC). A request for a line of the first parcel at 20 Nov 2026, 22:59:59 UTC is accepted, 17 days after that parcel arrived. At 20 Nov 2026, 23:00 UTC, which is 00:00 on 21 Nov 2026 in Amsterdam, it is refused, and so is a request for a line of the second parcel.
A request is refused, and changes nothing, when the line was not delivered, when the quantity is 0 or less, when the quantity is more than what was delivered and has not been cancelled or returned, or when the line is cancelled. For the line of two mugs, a return of 1 is accepted, a return of 2 after that is refused, and a return of 1 after that is accepted. Two requests for the last returnable mug at the same moment: exactly one is accepted.
The window is checked only when the request is made. A request accepted on day D + 14 can be inspected on day D + 20, and the inspection is not refused for the date.
Architectural guidance
The window runs from the day the last parcel of the order was delivered. Counted from each parcel's own delivery, the window of the first parcel's lines closes days before the shopper has seen the whole order, which is shorter than the 14 days the studio promised. A carrier that uploads late must not shorten the shopper's window or lengthen it. Counting calendar days in the shop's time zone means a parcel delivered at 23:30 on 2 Nov 2026 has the same last day as one delivered at 09:00 on 2 Nov 2026, which is what the studio promised. A late inspection is the studio's delay and not the shopper's, so the window is a check at request time and nothing that expires later. Two people asking for the last returnable mug at once must not both succeed, or the refund is for a mug that does not exist.
Acceptance criteria
An inspector records, for a return that is waiting for inspection, a condition of resellable or damaged for the whole quantity of the request, and a restock location. A resellable return needs a restock location of WORKSHOP or SHOP, chosen by the inspector, and anything else is refused. Inspecting a return that is not waiting for inspection is refused, so one return is inspected once.
A resellable return of 1 Glazed vase to SHOP adds a history line of plus 1 at SHOP with the return as its reference. The vase sellable total goes up by 1, the product list shows that within 1 minute, and the explanation check from Phase 1 prints zero differences. A damaged return of 1 Mug adds no history line at all, the sellable total does not change, and the inspection shows the quantity as written off.
Either condition leaves the return inspected with the amount to give back. The amount follows the cumulative rule from the cancel Checkpoint, counting units already cancelled or returned. Returning 1 of the 2 mugs gives 1,734, and returning the second gives 1,735. A damaged return gives back the same amount as a resellable one. The order shows the returned quantity on the line and a history row with the condition. The order view shows the return from request to inspection in time order.
Two inspectors inspecting the same return at the same moment restock it once. Kill the shop right after the piece reaches the shelf count: after the restart the piece is restocked once and the return is inspected once.
Architectural guidance
A returned piece can come back to either shelf, and only the person holding it knows which. A damaged piece never enters the count, so a write-off leaves the count untouched and the history unchanged. Inspecting twice, or restocking again after a crash, shows a vase on the shelf that was never there, and the shop sells it.
Acceptance criteria
An inspected return sends one refund for its amount, capped at the captured amount minus what has already been refunded. It sends one refund per return, not one per unit. Take an order captured at 10,600 where 1 of the 2 mugs came back. The provider's record holds one refund of 1,734, and 10 seconds of provider time after the request the refund is reported settled. The order history gets a row that says the refund was settled by the provider. The returned second mug later adds a refund of 1,735, and the two refunds add up to the mugs' value of 3,469.
Processing the same inspection result twice, including twice at the same moment and again after a restart, leaves one refund. With "accept and never answer" on for the refund request, the shop's retry leaves one refund of 1,734 in the provider's record.
The cap holds across cancels and returns. For the order captured at 10,600, cancel the Bowl after capture (2,506), return the vase (4,625) and return both mugs (3,469). The refunds total 10,600. Make the shop ask for 99,999 after that, by whatever route your tests use: it refunds 0, shows the refund as capped, and sends nothing to the provider. No order has refunds above its captured amount at any step, and the owner can see each refund with its amount and state.
A message that a refund failed puts a row in the order history with the amount and the reason. Nothing retries it by itself.
The owner's guide is one page in your repository. It says how to read an order's history from placement to refund, and it says what to do when a refund fails: the amount was not returned, the history shows the reason, the owner contacts the provider about that refund, and the shop does not retry by itself. It also says that a settled refund appears on the customer's card 5 to 10 business days later, and that the provider keeps a fee on each refund, which is why a return sends one refund and not one per unit.
Architectural guidance
A return must refund exactly once, and a repeat can come from a duplicated report, a retry after a timeout or a restart after a crash. Two separate returns of one order are two refunds, so a second return must not be taken for a repeat of the first. The cap is the last line of defence, because it holds even when the amount asked for is one the order could never produce.
Acceptance criteria
One command (the name is yours) takes a seed and runs the whole shop against the fake provider, the carrier stand-in and the packer command, with the clock moved by the simulator. It starts at 08:00 Europe/Amsterdam on 2 Nov 2026, trades until 20:00, then moves on in steps of no more than 1 minute until 20:00 on 10 Nov 2026, so the 7-day lapse falls inside the run. It writes a results file to your repository. Two runs with the same seed produce the same file, byte for byte.
The day plays 60 ordinary orders between 08:00 and 20:00, with 10 of them in the hour from 12:00 to 13:00, and 25% of them (15) abandoned at the payment step. At 10:00 a limited drop of 30 Glazed vases (split across the two locations) is released, and 47 buyers each try to buy 1 within 25 minutes, many of them at overlapping moments. The failures injected are these. Some ordinary orders use the declined card. The provider answers with a server error to authorisation requests from 12:30 to 12:40. Every provider message is duplicated once, a third of them are delayed 20 minutes, and messages are reordered. Some refund requests time out after the provider accepted them. Every delivered fact uploads 3 hours late and is repeated once. The packer short-picks several lines, some where the other location holds enough and some where it does not. Shoppers cancel whole orders, lines before capture and lines after capture. Returns are requested and inspected, some resellable and some damaged, and a request for an undelivered line and a request above the returnable quantity are refused. The shop is killed three times, after a stock hold, after an authorisation request and after an order was saved as placed, each on a different order. At 14:00 an erasure request arrives for a customer whose orders are all delivered or cancelled.
The run ends with these checks, each printed in the results file with a count and a pass or fail, and the command exits non-zero on any failure.
Stock: exactly 30 holds of the drop vase succeeded and 17 buyers were refused. No variant was shipped more units than were received, and no sellable count is below 0. The explanation check from Phase 1 prints zero differences at the end of every simulated hour and at the close.
Holds: no stock hold is still held with an end time at or before the clock. The provider's record shows no authorisation still authorised for an order that is cancelled, and none past 168 hours. Every order that was placed has all its parcels, including the one whose shop was killed after it was saved as placed.
Money: for every order, captured is at most authorised and refunded is at most captured. The provider's record, the payment amounts the shop shows and the order histories agree on every authorisation, capture and refund amount. Each refund appears once at the provider. Each refund that timed out exists once. No customer was refunded twice for one cause.
History: every order's history is in the order things happened, and its captured and refunded amounts equal the sums of its history rows.
Erasure: after the request, the customer's name, email and address are replaced with a pseudonym, and a search of everything the shop stores, including logs and exports, for the old email finds nothing. The customer's orders, payments and refunds remain, identified by ID, and each order's history still adds up.
The checks can fail. Break your shop on purpose in three ways, one at a time, and show each run failing on the check named. A shop that sells a unit twice when buyers collide fails the Stock check. A shop that sends a timed-out refund again as a new request fails the Money check. A shop that leaves the card held after the stock hold expired fails the Holds check.
The README takes a reviewer from a fresh clone to an order that shipped in two parcels, with its history on screen, in 15 minutes, and lists the command for each test. You keep the results file from the last run in your repository.
Architectural guidance
Tests of single features pass while the whole fails, because the defects that cost the studio money sit between features: a card still held after a provider outage, a refund sized from the order total, a placed order that never got its parcels because the shop died at the wrong moment. The day injects each of those failures at a known time and then checks the facts that must hold afterwards, so a defect points at the check it breaks. A clean run means something only when each check has been seen to fail.
Architectural walkthrough
The studio refunded 17 customers by hand and two of them twice. This Phase takes money back out of the shop, and the rule it turns on is that money out is capped by money in. A refund can never exceed what was captured, and the shop has to hold to that even when it is asked for more.
Cancelling an order or a line means different things depending on where the money is. Before capture, a whole-order cancel gives the held money back, and a cancelled line makes the later capture smaller. After capture, a cancel is a refund, and the provider settles a refund 10 seconds later, or fails it. The shopper and the owner see one action: cancel.
A refund must happen exactly once. A timeout after the provider accepted the request, a duplicate message, a shop that dies right after saving the cancel, and two people cancelling the same line at the same moment can each send the money twice. The provider also keeps a fee on every refund, so every avoidable second refund costs the studio twice.
When a packer cannot find a piece, the shop has to decide what happens to it once. If the shop decides twice, the line is moved to the other location and cancelled at the same time.
The last Checkpoint tests everything at once. Tests of single features pass while a card stays held after a provider outage, and the simulated day is where that shows. If the cap is missing, the day finds a refund sized from the order total when only one line came back.
Architectural walkthrough
The last vase sold 47 times
The old shop checked the stock when a page opened and trusted that answer until the customer paid. The page that said "in stock" and the moment the money was taken were never one decision, which is how 47 people paid for 30 vases in 25 minutes. The new shop has to refuse the 31st buyer at the moment they ask, whatever the product list on screen still says. Test this with many buyers at once. A shop that is right for one buyer at a time can still sell the same vase twice.
Every hold ends
Stock held for a shopper lasts 15 minutes. A card authorisation, the provider's promise to keep the money on the card for you, lasts 7 days. A shopper who closes the tab, a payment that never reports back and a step that failed halfway must each end with the units on the shelf and the card released.
Stock and money are two holds on two different things, and the shop has to give back both whichever step fails. The case that tests this is the authorisation that arrives after the stock hold has already expired. If the shop gives back only the stock, the shopper's card stays held for 7 days for a vase they never got.
Messages arrive late, twice and out of order
The payment provider and the carrier are outside the shop. The provider repeats a message when the shop answers slowly, sends one late when its own backlog grows, and can deliver two in the wrong order. A "released" message followed by a late "authorised" one must not bring the payment back to life. The carrier uploads a delivery report hours after the parcel arrived, and the time of the order's last parcel delivery starts the shopper's 14-day return window.
Dying in the middle
A shop process can die between saving an order and starting the work that follows. A placed order then never gets its parcels, or a refund is recorded and never sent. The opposite failure is worse for the studio: after a restart the same work runs a second time and a customer is refunded twice, which is what happened to two of the 17 customers.
Money out is capped by money in
A refund sized from the order total when only one line came back takes more money out than came in. A refund sent again after a timeout takes it out twice. The shop must know what was captured and refuse to give back more, whatever it is asked.
Where it shows if you cut a corner
The 100-buyer test in Phase 2 sells an eleventh unit if two buyers can both see the last one as available. The money test in Phase 5 finds a refund sized from the order total when a line was only partly returned. The final trading day finds a card still held after a provider outage, or a placed order with no parcels after a kill. Each test finds the defect before the next limited drop does.
Related Links
- Belastingdienst, keeping your business recordsbacks the 7 years order, payment and refund records stay after an erasure.
- Your Europe: returning goods and the 14-day withdrawal periodbacks the 14-day return window.
- Consumer Rights Directive 2011/83/EU, Article 9backs starting the return window when the last parcel of the order is delivered.
- Stripe: place a hold on a payment methodbacks the 7-day card authorisation that the shop must release.
- Online payment statistics for the Netherlands 2026secondary source for iDEAL taking the money at once, which is why the shop takes cards only.
- Stripe: refundsbacks refunding no more than was captured and the fee the provider keeps on a refund.