Skip to content

Add fake payment API#14

Open
S1M0N38 wants to merge 1 commit into
tscircuit:mainfrom
S1M0N38:codex/fake-payment-api
Open

Add fake payment API#14
S1M0N38 wants to merge 1 commit into
tscircuit:mainfrom
S1M0N38:codex/fake-payment-api

Conversation

@S1M0N38
Copy link
Copy Markdown

@S1M0N38 S1M0N38 commented May 11, 2026

Adds a focused fake payment lifecycle API for issue #1.

What changed:

  • Added persistent in-memory payment records to the existing zod/zustand database.
  • Added /payments/send, /payments/list, /payments/get, /payments/complete, and /payments/cancel routes.
  • Added idempotency-key reuse on send so retrying the same payment request does not create duplicates.
  • Added lifecycle tests covering create/list/get/complete, idempotent retries, filtering, and cancellation.

Verification:

  • bun test
  • ./node_modules/.bin/biome check lib/db/schema.ts lib/db/db-client.ts routes/payments/send.ts routes/payments/list.ts routes/payments/get.ts routes/payments/complete.ts routes/payments/cancel.ts tests/routes/payments/lifecycle.test.ts
  • bunx tsc --noEmit
  • bun run build

/claim #1

Copilot AI review requested due to automatic review settings May 11, 2026 19:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a fake “payment lifecycle” API backed by the existing in-memory zustand DB, enabling clients/tests to create payments, query them, and transition them through completion/cancellation.

Changes:

  • Introduces a Payment model + payments collection in the in-memory DB (with a dedicated paymentIdCounter).
  • Adds payment lifecycle endpoints: send, list (with filters), get, complete, cancel.
  • Adds lifecycle tests covering creation, idempotent retry behavior, filtering, completion, and cancellation.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lib/db/schema.ts Adds Payment/PaymentStatus schemas and persists payments in the database schema.
lib/db/db-client.ts Implements payment CRUD-ish helpers (sendPayment, listPayments, getPayment, updatePaymentStatus).
routes/payments/send.ts Adds POST endpoint to create/reuse a payment (idempotency key).
routes/payments/list.ts Adds GET endpoint to list payments with optional query param filters.
routes/payments/get.ts Adds GET endpoint to retrieve a payment by payment_id.
routes/payments/complete.ts Adds POST endpoint to mark a payment completed.
routes/payments/cancel.ts Adds POST endpoint to mark a payment cancelled.
tests/routes/payments/lifecycle.test.ts Adds end-to-end tests for payment lifecycle and idempotency behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread routes/payments/send.ts
Comment on lines +22 to +35
const existingPayment = body.idempotency_key
? ctx.db.payments.find(
(payment) => payment.idempotency_key === body.idempotency_key,
)
: undefined

const payment = ctx.db.sendPayment({
...body,
currency: body.currency ?? "USD",
})

return ctx.json({
payment,
reused: Boolean(existingPayment),
Comment thread routes/payments/list.ts
Comment on lines +13 to +14
const parsedStatus = status ? paymentStatusSchema.parse(status) : undefined

Comment thread lib/db/db-client.ts
Comment on lines +108 to +109
completed_at: status === "completed" ? now : payment.completed_at,
cancelled_at: status === "cancelled" ? now : payment.cancelled_at,
Comment thread lib/db/db-client.ts
Comment on lines +1 to +12
import { hoist } from "zustand-hoist"
import { combine } from "zustand/middleware"
import { immer } from "zustand/middleware/immer"
import { hoist, type HoistedStoreApi } from "zustand-hoist"
import { createStore } from "zustand/vanilla"

import { databaseSchema, type DatabaseSchema, type Thing } from "./schema.ts"
import { combine } from "zustand/middleware"
import {
type DatabaseSchema,
type Payment,
type PaymentStatus,
type Thing,
databaseSchema,
} from "./schema.ts"
Comment on lines +16 to +20
expect(sendData.reused).toBe(false)
expect(sendData.payment).toMatchObject({
payment_id: "0",
recipient: "octocat",
amount: 10,
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.

2 participants