Requirement EPIC
- Epic
- MVP1 · E6 · Payment
- Goal
- a reliable, secure one-time payment per document.
- Stories in this module
- 5
PAYMENT-V1-E6-01 Checkout session
Size MPayment; composed by the DocFlow app
- AC1"Pay $5.00" creates a Stripe Checkout session in test mode with
metadata.order_id, and success/cancel URLs back to the app. - AC2An
orders row is created with status pending. Clicking twice reuses the open session instead of creating a duplicate order. - AC3A banner says "Test mode — use card 4242 4242 4242 4242, any future date, any CVC".
PAYMENT-V1-E6-02 Webhook
Size MPayment
- AC1
POST /api/payment/v1/webhooks/stripe verifies the Stripe signature and rejects invalid ones with 400. - AC2On
checkout.session.completed, the order becomes paid, and order.paid is audited. - AC3The handler is idempotent: an event ID already processed returns 200 without changing anything again.
- AC4Also handles
checkout.session.expired (order becomes expired) and async payment failure (order becomes failed).
PAYMENT-V1-E6-03 Payment page and states
Size SPayment (UI component), used by the DocFlow app
- AC1
/documents/{id}/pay shows an order summary: document name, number of fields, price. - AC2Cancel returns here with "Payment cancelled — you haven't been charged" and a retry button.
- AC3A document that's already paid skips straight to success (E7).
PAYMENT-V1-E6-04 Refunds
Size SPayment; DocFlow reacts to the event; Delivery sends the emailPending
Decided on PR #67: refunds are not in the first version of Payment; this story adds them.
As the owner, I want to refund a paid order in full, so a demo user who was charged by mistake (in test mode) can be put right, and the platform shows how a refund flows through every service.
- AC1An admin can refund a paid order in full from the admin page, with a reason. A person always does this: it is session only and never available to API keys or agents.
- AC2Payment creates the refund in Stripe with the order's ID as the idempotency key, so a repeated request never refunds twice. The order becomes
refunded when Stripe's webhook confirms it (charge.refunded), not when the request is sent. - AC3Payment announces
payment.order.refunded to the app that created the order (routed by reference, decision on #13). In DocFlow, the document's downloads lock again and its status shows "Refunded"; the reviewed data stays. - AC4The person who paid is emailed through Delivery that the refund was made, with the amount; Stripe's own refund receipt still applies.
- AC5A refund is audited (
order.refunded) with the admin, the reason and the amount. Partial refunds are not in this version. - AC6Refunding an order that is not paid answers
409 not_paid; refunding it again answers 409 already_refunded.
PAYMENT-V1-E6-05 Spike: Stripe Billing APIs
Size SPayment (spike)
As the owner, I want to know how Stripe Billing would carry a paid plan beyond the free quota, before Monetization (01SCALE-V1-E0-28) and the quota (EXTRACTION-V1-E3-09) commit to one, so pricing is built on what Stripe supports (Nikhil, PR #189).
- AC1A timeboxed spike (3 days at most), in Stripe test mode, tries the Billing pieces a paid plan would need: Products and Prices, Subscriptions, usage-based (metered) billing with meter events, the Customer Portal, and the webhooks they send.
- AC2It states how each fits the Payment service's contract (Checkout today,
PAYMENT-V1-E6-01 and PAYMENT-V1-E6-02), what would change in Payment's API and tables, and the fees. - AC3The result is a decision record in
docs/services/shared/v1/DECISIONS.md with a recommendation for MVP1 and MVP2 (saved payment methods are MVP2). No keys are committed.
All Payment V1 epics and stories on GitHub →