Add a Stripe settlement report (deposits + terminal payments), for payout reconciliation - #5
Add a Stripe settlement report (deposits + terminal payments), for payout reconciliation#5JustSamuel wants to merge 1 commit into
Conversation
Treasurers need a way to cross-reference SudoSOS against Stripe's payouts. A Stripe payout batches every captured charge on the account regardless of how it was taken, so a report scoped to only one payment method would always undercount against the real payout. GET /stripe/report and /report/pdf sum both StripeDeposit (online top-ups) and TerminalPayment (card-present) records for a date range, mirroring the existing fine report: an UnstoredPdfAble report entity, its own PdfService and html template. The report has two limits, both documented in the response type and the PDF text. It reports gross amounts, since that's all SudoSOS stores -- Stripe deducts its own processing fees before paying out, and reconciling those fees is a separate problem this doesn't attempt to solve. It also excludes payments settled through a shareable payment link (PaymentRequest): those move through the same Stripe account but never create a StripeDeposit record, so a GEWIS that uses that feature will still see this report undercount against a real payout. Super admin had zero permissions on StripeDeposit before this (only AuthorizedBuyer could create one). This adds a get-only grant, since reading deposits is required to build the report and admins had no way to do it otherwise. Writing tests for this surfaced two unrelated bugs, both of which blocked writing a working test at all: - DepositSeeder#init hardcoded a fixed stripeId, which collides with a unique constraint the second time init() runs in the same test. - The exclude-by-state test needed to mark a deposit as unsettled by clearing its transfer. TypeORM's .save() treats an explicit undefined as "leave this column alone" rather than clearing it, so the update goes through .update() with an explicit null instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Stripe “settlement report” feature to the backend to help treasurers reconcile Stripe payouts against what has “settled” into SudoSOS (Stripe deposits + paid terminal payments), including both a JSON API response and a generated PDF/TeX export.
Changes:
- Add
StripeService#getStripeSettlementReportto aggregate settled deposits and paid terminal payments over a date range. - Add a
StripeSettlementReportmodel + HTML/PDF plumbing and expose it via newGET /stripe/reportandGET /stripe/report/pdfendpoints (RBAC-gated). - Extend/adjust seeders and add unit tests covering aggregation, filtering, and endpoint behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| backend/test/unit/service/terminal-payment-service.ts | Minor formatting-only change (trailing newline). |
| backend/test/unit/service/stripe-service.ts | Adds DB-backed unit tests for the settlement report aggregation logic. |
| backend/test/unit/controller/stripe-controller.ts | Adds controller tests for the new settlement report JSON and PDF endpoints (incl. RBAC/validation). |
| backend/test/seed/ledger/terminal-payment-seeder.ts | Ensures seeded terminal payments are real TerminalPayment instances (prototype methods available). |
| backend/test/seed/ledger/deposit-seeder.ts | Makes seeded Stripe payment intent IDs unique per call to avoid unique-key collisions in tests. |
| backend/src/service/terminal-payment-service.ts | Minor formatting-only change (trailing newline). |
| backend/src/service/stripe-service.ts | Implements getStripeSettlementReport with SQL aggregation for deposits + terminal payments. |
| backend/src/service/pdf/stripe-settlement-report-pdf-service.ts | New PDF service to render the settlement report via HTML-to-PDF pipeline. |
| backend/src/rbac/default-roles.ts | Grants admins get-only access to StripeDeposit to authorize the combined report. |
| backend/src/html/stripe-settlement-report.html.ts | New HTML template for the settlement report PDF export. |
| backend/src/entity/report/stripe-settlement-report.ts | New report model with response mapping and PDF-able behavior. |
| backend/src/controller/stripe-controller.ts | Adds /stripe/report and /stripe/report/pdf endpoints + combined-permission policy check. |
| backend/src/controller/response/stripe-response.ts | Adds Swagger typedefs/interfaces for the new settlement report response shape. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * @security JWT | ||
| * @param {string} fromDate.query.required - The start date of the report, inclusive | ||
| * @param {string} toDate.query.required - The end date of the report, exclusive | ||
| * @param {string} fileType.query - enum:PDF,TEX - The file type of the report, defaults to PDF | ||
| * @returns {string} 200 - The requested report - application/pdf |
SudoSOS Coverage ReportCommit: 1b01652 Details (changed files)
The full per-file breakdown is omitted to stay under GitHub's 65,536-character comment limit. Download the |
Coverage Report for CI Build 31795818630Coverage decreased (-0.02%) to 92.183%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
Ported from GEWIS/sudosos-backend#1016.
No changes needed during the port beyond the directory prefix (
backend/) -- patch applied cleanly viagit am, andbackend:build/backend:lintboth pass.