Skip to content

Add guarded fake payment lifecycle API#24

Open
AmanKishore wants to merge 2 commits into
tscircuit:mainfrom
AmanKishore:add-guarded-fake-payments
Open

Add guarded fake payment lifecycle API#24
AmanKishore wants to merge 2 commits into
tscircuit:mainfrom
AmanKishore:add-guarded-fake-payments

Conversation

@AmanKishore
Copy link
Copy Markdown

@AmanKishore AmanKishore commented May 12, 2026

Summary

  • add fake payment records to the in-memory zod/zustand database
  • add send/list/get/complete/cancel payment routes
  • support retry-safe idempotency_key handling for sends
  • guard completed/canceled payments as terminal states with 409 responses
  • preserve the default middleware DB across production requests and cover it with a regression test
  • document the payment endpoints in the README

/claim #1

Tests

  • bun test tests/routes/payments-default-middleware.test.ts tests/routes/payments.test.ts
  • bun test
  • bun run build
  • bunx tsc --noEmit
  • bunx biome check README.md lib/db/schema.ts lib/db/db-client.ts lib/middleware/with-db.ts lib/payments/route-schemas.ts routes/payments tests/routes/payments.test.ts tests/routes/payments-default-middleware.test.ts
  • git diff --check

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 797d4aa220

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread routes/payments/list.ts
})((req, ctx) => {
return ctx.json({
ok: true,
payments: ctx.db.listPayments(req.query),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the payment store across requests

When these endpoints run through the normal withRouteSpec middleware stack, withDb creates a fresh createDatabase() whenever the request context has no db, so this list call reads a new empty store rather than the payments created by earlier /payments/send requests. The payment tests inject a shared db in tests/fixtures/start-server.ts, which masks this production path; as a result /payments/list, /payments/get, /payments/complete, and /payments/cancel cannot observe prior sends unless the server is run with the test-only middleware.

Useful? React with 👍 / 👎.

@AmanKishore
Copy link
Copy Markdown
Author

Addressed the automated review finding in ff51836: withDb now uses a process-level default store when no test db is injected, and tests/routes/payments-default-middleware.test.ts exercises the normal middleware path across separate requests.

Additional verification after the fix:

  • bun test tests/routes/payments-default-middleware.test.ts tests/routes/payments.test.ts
  • bun test
  • bun run build
  • bunx tsc --noEmit
  • bunx biome check README.md lib/db/schema.ts lib/db/db-client.ts lib/middleware/with-db.ts lib/payments/route-schemas.ts routes/payments tests/routes/payments.test.ts tests/routes/payments-default-middleware.test.ts
  • git diff --check

@AmanKishore
Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant