Add fake payment API#14
Open
S1M0N38 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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
Paymentmodel +paymentscollection in the in-memory DB (with a dedicatedpaymentIdCounter). - 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 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 on lines
+13
to
+14
| const parsedStatus = status ? paymentStatusSchema.parse(status) : undefined | ||
|
|
Comment on lines
+108
to
+109
| completed_at: status === "completed" ? now : payment.completed_at, | ||
| cancelled_at: status === "cancelled" ? now : payment.cancelled_at, |
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a focused fake payment lifecycle API for issue #1.
What changed:
/payments/send,/payments/list,/payments/get,/payments/complete, and/payments/cancelroutes.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.tsbunx tsc --noEmitbun run build/claim #1