← All guidesCodex for Backend Engineering · Future with Shivank
Hands-on guide

23. Stripe Checkout

Start Part 7: ask Codex for winner checkout through the mock Stripe service, answer two rounds of grilling questions, confirm the two slices and let Codex build and test Slice 1. By the end, the auction winner can pay.

Part 7 · start≈ 45–60 min hands-onGrill with docs · 2 rounds

What you'll do

Before you start

📘 Concept: Stripe Checkout, and why we use a mock

Stripe is a payment company. With Stripe Checkout, your server never touches a card number. Instead, the server asks Stripe to create a Checkout Session: “this customer owes $107 for this item”. Stripe returns a link to a payment page that Stripe hosts. The buyer is sent to that page, types the card there, and is redirected back to your site. Afterwards Stripe tells your server “session paid” through a webhook, a message sent to your server (explained properly in step 5). That is the real flow. Our mock Stripe service copies it exactly: Auction House creates a session on it, the winner pays on its hosted card page (port 7107), and it sends a signed checkout.session.completed webhook back to our API. Why a mock? Because it runs on your Mac with no account, no internet, no test-mode keys and no risk, and it is deliberately imperfect, so you learn what can go wrong with payments without any money moving.

⚙ Codex settings for this guide
Project / folderworkshop
ModelGPT-5.6 Sol
ReasoningMedium
ApprovalsApprove for me
AlsoNew chat on Local (not a worktree), branch master
1

Reset stripe-service to its starting version

Your workshop already has a stripe-service/ folder, because it came with the course repo. But that copy is the finished version: its problems were fixed during Part 7 and tracing was added in Part 8. Part 7 is exactly where we find and fix those problems, so we swap in the version the mock started as. Paste this block into the Terminal app. Line by line:

  • cd ~/codex-course/workshop: into the workshop folder.
  • rm -rf stripe-service deletes the finished copy. -r means “the whole folder, recursively”, -f means “don't ask”.
  • git -C ../reference archive 457ddbe stripe-service | tar -x is the interesting one. git -C ../reference runs Git inside the reference folder without leaving your current folder. archive 457ddbe stripe-service packs up only the stripe-service folder as it looked at commit 457ddbe, the point in the reference history where the mock was first added. The | pipes that package into tar -x, which unpacks it right here, in your workshop. Result: the original mock, inside your workshop, with no other files touched.
  • ls stripe-service shows what arrived, so you can confirm.
  • git add -A && git commit -m "…" saves this swap as a commit, so the change is on record.
❯Run in TerminalTerminal app · workshop folder
cd ~/codex-course/workshop
rm -rf stripe-service
git -C ../reference archive 457ddbe stripe-service | tar -x
ls stripe-service
git add -A && git commit -m "Mock Stripe service: starting version"
✓ You should see

package.json src tsconfig.json, with no package-lock.json yet (that missing lockfile is one of the things Codex will point out), then a commit summary.

💡 Tip

Skipping this step is fine too. Codex then simply reports fewer problems with the mock in step 3, because most of them are already fixed in the finished copy. I prefer you do the reset, so you see Codex catch real issues in a dependency.

2

Send the Part 7 prompt in a new chat

I usually send this prompt while the Drizzle goal from guide 22 is still running in its own chat; the two don't interfere because the goal lives in a worktree. In Codex, click New chat, project workshop. Look at the chips above the message box: this time keep Local (not a worktree), branch master. Part 7 should be built in your real workshop folder. Paste and send.

The prompt has two lines, and both matter. “work out of folder 7, copy from folder 6” is our course convention: each part starts as a copy of the previous part and adds one capability, so Part 7 begins as Part 6 plus checkout. “please grill me with docs” calls the grill-with-docs skill you installed in guide 5: Codex asks you design questions in rounds, with a recommendation for each, and writes every decision into GRILL.md before any code is written.

⚙ Codex settings
Project / folderworkshop
ModelGPT-5.6 Sol
ReasoningMedium
ApprovalsApprove for me
AlsoLocal · master
✦Paste into Codexnew chat · Local
work out of folder 7, copy from folder 6

I want to implement winner checkout using the mock Stripe service inside of this repo. please grill me with docs
✓ You should see

After about 40 seconds Codex sums up its audit of the repo, something like: “part-7-winner-checkout is empty… Part 6 provides authoritative auction closes and winner identity. I'll document our decisions in Part 7's GRILL.md, then copy Part 6 only after the grilling design tree is settled and you confirm the vertical slices.” Notice the order it promises: decide first, copy and build later.

Then Round 1 — Product and integration boundaries: about 9 questions (❓ Q1 … Q9), each with a ➡️ recommendation, ending with “Please answer Q1–Q9. Short answers like “all recommendations” plus exceptions are perfect.” The chat gets a name in the sidebar such as Define winner checkout flow; I refer to it by that name below.

⚠ Heads up

Two grilling rounds plus building Slice 1 is one of the heavier runs in the course. Keep an eye on platform.openai.com → Usage. If you want to save, switch the model to Terra for the two answer rounds and back to Sol before step 8, where the building happens.

3

Answer round 1

Read each of Codex's questions and match it to the list below. Your questions may be worded, ordered or numbered differently, so match by topic, not by number. These are my choices and why:

  • Q1 Mock Stripe boundary: a separate service, and it already exists. Codex should use stripe-service/ at the repo root and review it for problems. We do not want it to invent a second mock.
  • Q2 Checkout interaction: like Stripe Checkout. The server creates a session, the browser goes to a hosted payment page. The card form never lives in our app.
  • Q3 Charge amount: exactly the winning bid, in USD. No shipping or tax. The server decides the amount; the browser is never trusted with it.
  • Q4 Eligibility: only the winning bidder, and only after the auction has closed.
  • Q5 Demo identity: keep the demo user switcher we have had since Part 1. No real login system.
  • Q6 Entry points: a checkout button in the winner's outcome popup and a “Complete purchase” panel on the closed auction page, so a winner who dismissed the popup can still pay.
  • Q7 Payment outcomes: success, card decline and cancel on the mock page. 4242 4242 4242 4242 succeeds, 4000 0000 0000 0002 declines. These are the standard test card numbers real Stripe uses in test mode, which is why the mock uses them too.
  • Q8 Who sees payment state: the winner sees Payment required / Processing / Paid; the seller sees only Awaiting payment / Paid; everyone else sees nothing.
  • Q9 Fulfillment: nothing. No shipping, payouts, email or notifications. Just taking payments. Scope control: one capability per part.

“take recommend” means “use your recommendation”. I type it once, copy it, and paste it on each line. Spend your typing only on the exceptions.

✦My answers (round 1), adjust the numbers to match your questionsDefine winner checkout flow chat
1. we already have the stripe service for you, just copied it into the root, directory stripe-service/, please look at it and tell me if there's any issue
2. take recommend
3. take recommend
4. take recommend
5. take recommend
6. take recommend
7. take recommend, use the 4242 number for success and the other typical number for failure
8. take recommend
9. nope, none of that, just taking payments
✓ You should see

Codex says “Round 1 is settled”, then inspects stripe-service/. You may see a helper task named something like Inspect stripe start working; that is Codex spinning off a small side job to read the mock while the main chat continues. It then lists problems in the mock, similar to: a completed session can be paid again, session creation is unauthenticated, the page shows the decline card but not that 4242 4242 4242 4242 succeeds, no lockfile. And it says clearly: “No files have been changed yet.” Read that list; each item is a real payment bug class.

Then Round 2 — Integrity and recovery with about 10 more questions (Q10–Q19). These are the harder ones: what happens when things go wrong.

💡 Tip

Why this matters: round 1 decided what we build (boundaries, who, how much). Round 2 decides how it stays correct under failure. Real payment bugs almost always come from the second category, and this is where grilling earns its cost.

4

Only if your Drizzle goal is waiting: approve it

Switch to the Pull GitHub issue 2 chat from guide 22. If its bar says Goal stalled, it is because Codex asked permission to create the branch issue-1-drizzle-refactor and has been waiting for you. Send the message below there. It does two things: it answers the question (“approved”) and it restates the finish line (“don't stop until you issue a PR”), so the goal does not stall again at the next small decision. Skip this step if you cleared that goal in guide 22 or if it never asked.

✦Paste into CodexPull GitHub issue 2 chat
approved, GO! don't stop until you issue a PR
✓ You should see

Something like: “Approved. I'm creating issue-1-drizzle-refactor from master, then I'll refactor every Part 6 service and its tests to Drizzle… and open the PR before stopping.” The bar changes back to Pursuing goal and shows Step 1 / 5. It keeps running in the background while you return to Part 7. Guide 24 picks this goal up again.

💡 Tip

If the bar still says Goal stalled after you send, click its resume (play) icon. A stalled goal sometimes needs that nudge even after you have answered.

5

Answer round 2

Back in the Define winner checkout flow chat. Round 2 is about integrity: making sure a purchase can never be paid twice, never marked paid without proof, and never gets stuck. Read the two concept boxes below before you answer; they explain the vocabulary in Q13 and Q14. These are my choices:

  • Q10 Mock service hardening: I did not understand what this question was really asking, so I asked “what do you mean?”. Codex explains in the next step. It is fine to do this during grilling.
  • Q11 Mock persistence: keep checkout sessions in memory inside the mock. Auction House, our app, keeps the durable purchase record in PostgreSQL. The provider can forget; we must not.
  • Q12 Purchase creation: create the purchase row when the winner first clicks checkout. One purchase per auction, enforced by the database.
  • Q13 Payment authority: only a signed checkout.session.completed webhook marks a purchase paid. The redirect URL the browser comes back on is not proof; anyone can type a URL.
  • Q14 Webhook replay safety: record each provider event once, and allow only one pending → paid transition per purchase.
  • Q15 Purchase states: just pending and paid. No refunds, no failed state; a declined card simply leaves it pending.
  • Q16 Checkout retries: if the winner clicks checkout again, reuse the open session instead of creating a new one. Also disable the button on click, so a double-click cannot fire two requests.
  • Q17 Return experience: after paying, go back to the auction page and reload the real purchase state from our server.
  • Q18 Service access: no API keys between our API and the mock. Keep it simple; this is a local mock.
  • Q19 Repository operation: keep stripe-service/ at the repo root, add its lockfile, and let Part 7's npm start start the mock along with the API and the web app.
📘 Concept: webhook

Normally our server makes requests and waits for answers. A webhook turns that around: another system calls our server when something happens on their side. The payment provider finishes a payment and sends an HTTP request to a URL we gave it, say POST /webhooks/stripe, with a JSON body describing the event (checkout.session.completed, which session, how much). Because anyone on the internet could send a request to that URL, the provider signs each webhook with a secret that only it and we know, and our server checks the signature before believing anything. That is why Q13 says only a signed webhook may mark a purchase paid.

📘 Concept: replay safety (idempotency)

Webhooks are delivered at least once, not exactly once. If our server is slow to answer, the provider sends the same event again. If we processed “session paid” twice, we might record two payments or two emails. A replay-safe, or idempotent, handler produces the same result no matter how many times it receives the same event. The usual recipe is exactly what Q14 asks for: store each event's unique id in a table, ignore an id you have seen before, and make the status change itself a guarded update (“set paid only if currently pending”). You met the same idea with RabbitMQ consumers in guide 21; payments are where it matters most.

✦My answers (round 2), adjust the numbers to match your questionsDefine winner checkout flow chat
10. what do you mean?
11. take recommend
12. yep take recommend
13. take recommend
14. take recommend
15. take recommend
16. take recommend, but also just disable the button on click lol
17. take recommend
18. no API keys, not necessary, KISS (keep it stupid simple)
19. take recommend
✓ You should see

Codex explains the question you asked about, similar to: “Q10 is about whether I'm allowed to modify stripe-service/, not just integrate with it. Right now it permits this broken sequence: …”, listing a sequence such as “pay a session, then pay the same session again”, and it ends with “Should I make those minimal corrections to stripe-service/ as part of Part 7?”

6

Allow the minimal mock fixes

Codex has asked whether it may fix the mock itself, rather than only working around its bugs. The answer is yes, but minimal: fix what blocks a correct checkout, do not rewrite the service. Send this if Codex asked about fixing stripe-service/.

✦Paste into CodexDefine winner checkout flow chat
minimal corrections are fine :)
✓ You should see

Something like: “The grilling session is complete and documented in GRILL.md. Proposed delivery:

  1. Winner completes a replay-safe hosted checkout, including minimal mock Stripe corrections, decline/cancel flows, signed webhook confirmation, and authoritative paid state.
  2. Seller payment visibility and recovery from mock Stripe restarts or webhook interruptions.

…Please confirm these two slices, and I'll copy Part 6 into Part 7 and begin Slice 1.” A file card shows Edited GRILL.md +165 -0: 165 lines of decisions, and still zero lines of application code. That is the point of grilling first.

💡 Tip

If you picked the recommendation for Q10 instead of asking “what do you mean?”, Codex goes straight to this summary. Skip this step.

7

Ask for the diagram

The workshop rules in AGENTS.md ask Codex for a Mermaid diagram after every grilling session. Mermaid is a way of writing a diagram as plain text (boxes and arrows described in a few lines) which Codex and GitHub then draw as a picture. If you don't see one in the chat, ask for it. Keep the wording casual; it works.

✦Paste into CodexDefine winner checkout flow chat
where my mermaid
✓ You should see

Codex points out that the diagram is already in GRILL.md and shows it in the chat. Click it to zoom. It looks similar to: 🌐 React/Vite Web App (winning bidder) → ⚡ Fastify API (winner authorization + webhooks) → 🐘 PostgreSQL (closes, purchases, webhook events); the API creating a session in 💳 Mock Stripe (hosted Checkout Session); the winner paying there (“4242 success, 4000 decline or cancel”); Mock Stripe sending a signed checkout.session.completed back to the API; and a second 🌐 web app (seller) reading “awaiting or paid”. Trace the arrows once with your finger: that is the whole of Part 7 on one screen, and it matches the concept box at the top of this guide.

8

Confirm the slices and let Slice 1 build

One word approves the two slices. Codex then copies Part 6 into part-7-winner-checkout and builds Slice 1 only. This takes a while, about 10 minutes in my run, and it is the step where the tokens are spent. Make sure the model is back on Sol if you switched earlier.

📘 Concept: vertical slice

A vertical slice is a piece of work that cuts through every layer of the app at once (database, API, web page, tests) to deliver one complete, usable behaviour. Slice 1 here is “the winner can pay”: a purchases table, a checkout endpoint, a webhook endpoint, a button in the UI, and a browser test. The opposite approach, building all the database work first and all the UI last, leaves you with nothing testable for a long time. Slices give you something you can click on at the end of each one, which is also exactly what an agent needs: a clear finish line.

✦Paste into CodexDefine winner checkout flow chat
proceed!
✓ You should see

Something like: “Slices confirmed. I'm starting Slice 1 only: copy the Part 6 application into Part 7 while preserving the new GRILL.md, isolate its runtime configuration, then implement and verify the winner's complete hosted-checkout flow.” A counter shows Step 1 / 6 and climbs to Step 5 / 6 · 23 files changed +852 -26 (your numbers will differ). “Isolate its runtime configuration” means Part 7 gets its own ports and database name, so it can run next to Part 6 without clashing.

Near the end it runs the browser test npx playwright test tests/winner-checkout.spec.ts --project=edge: npx runs the Playwright test runner, on that one test file, in the Edge browser. The test walks through decline with the 4000 card, cancel and retry, then a successful payment with 4242. You may see an Edge window flash open and closed.

💡 Tip

If Codex asks to approve npm install, Docker or Playwright commands, approve them. They are all part of setting up and testing Part 7.

9

Watch the bidding-war browsers

After the checkout test, Codex re-runs the older browser workflows from Part 6 to check that nothing it copied has broken. Edge or Chrome windows open on their own. You don't need to do anything; just watch, and resist the urge to click inside them.

📘 Concept: headed end-to-end test

An end-to-end test drives the real app the way a user would: open the page, click, type, read what appears. Playwright is the tool that does the driving. Headed means the browser windows are visible on your screen, as opposed to headless, where the same test runs invisibly and faster. We run the bidding war headed because watching four users fight over one auction is the fastest way to understand concurrency, and because you will need the windows open to pay in the next guide.

✓ You should see

Four browser windows in a 2×2 grid on a URL like http://localhost:5107/items/bidding-war-gpu-… (Codex picks the port; in my run it was 5107, following the pattern of 510N for Part N): the seller (Avery Chen) and three bidders (Maya Thompson, Theo Brooks, Priya Shah). A countdown runs, bids climb from $101 to around $106, and stale bids are rejected with messages like “Bid not placed — another bidder moved the minimum…”. That rejection is the row locking from guide 14 still doing its job in Part 7.

10

Complain if there's no popup or checkout

In my run the four windows closed as soon as the auction ended, without showing the winner's outcome popup or a checkout page. Slice 1 claims “the winner can pay”, and I had not seen a winner pay, so I told Codex right away, while it was still working. Casual wording is fine; what matters is that you report what you saw, not what you assume. Send this if the same happens to you.

✦Paste into CodexDefine winner checkout flow chat
bidding wars came up, but no noty? no checkout page??????
✓ You should see

Your message appears and Codex starts looking into it, with an activity line similar to “Diagnosing checkout route delay”. This guide ends here. Guide 24 continues in this same chat: you will run the bidding war with the browsers left open and pay for the item yourself with the 4242 card.

💡 Tip

If your run did show the winner popup and a checkout page, skip this message and let Codex finish Slice 1 on its own.

Why this matters: a passing test is a claim. Seeing the feature work with your own eyes is the check. In guide 24 you will see what happens when an agent's claim and reality disagree.

Stuck or got a very different result?

Catch up to the finished Part 7 from the reference copy. The reference folder is the end state of the whole part (both slices done, including the seller's payment view), and this also restores the finished stripe-service/. Then run it; Codex isn't needed. Line by line: the first line deletes your Part 7 and mock, copies both from the reference, and commits. The second line moves into Part 7, installs its packages (npm install) and starts the database, API, web app and mock together (npm start). Open the URL that npm start prints (http://localhost:5107 in my run).

❯Run in TerminalTerminal app
cd ~/codex-course/workshop && rm -rf part-7-winner-checkout stripe-service && cp -R ../reference/part-7-winner-checkout ../reference/stripe-service ./ && git add -A && git commit -m "Catch up: part 7 from reference"
cd part-7-winner-checkout && npm install && npm start

Grilling went a very different way? That is normal; the questions depend on what Codex finds. Keep answering by topic using my choices as your guide. The decisions that must not change: server owns the amount, only a signed webhook proves payment, duplicates must be safe, two slices.

Key takeaways