Skip to content

Add a Stripe settlement report (deposits + terminal payments), for payout reconciliation - #5

Open
JustSamuel wants to merge 1 commit into
developfrom
feat/terminal-payment-report
Open

Add a Stripe settlement report (deposits + terminal payments), for payout reconciliation#5
JustSamuel wants to merge 1 commit into
developfrom
feat/terminal-payment-report

Conversation

@JustSamuel

Copy link
Copy Markdown
Collaborator

Ported from GEWIS/sudosos-backend#1016.

No changes needed during the port beyond the directory prefix (backend/) -- patch applied cleanly via git am, and backend:build/backend:lint both pass.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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#getStripeSettlementReport to aggregate settled deposits and paid terminal payments over a date range.
  • Add a StripeSettlementReport model + HTML/PDF plumbing and expose it via new GET /stripe/report and GET /stripe/report/pdf endpoints (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.

Comment on lines +188 to +192
* @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
@github-actions

Copy link
Copy Markdown

SudoSOS Coverage Report

Commit: 1b01652
Base: develop@587e808

Type Base This PR
Total Statements Coverage  93.09%  93.06% (-0.03%)
Total Branches Coverage  87.92%  87.9% (-0.02%)
Total Functions Coverage  93.83%  93.87% (+0.04%)
Total Lines Coverage  93.09%  93.06% (-0.03%)
Details (changed files)
FileStatementsBranchesFunctionsLines

The full per-file breakdown is omitted to stay under GitHub's 65,536-character comment limit. Download the coverage artifact from this workflow run for the complete report, or view it on Coveralls.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 31795818630

Coverage decreased (-0.02%) to 92.183%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 20 uncovered changes across 1 file (187 of 207 lines covered, 90.34%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
backend/src/controller/stripe-controller.ts 80 60 75.0%
Total (6 files) 207 187 90.34%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 24529
Covered Lines: 22829
Line Coverage: 93.07%
Relevant Branches: 5085
Covered Branches: 4470
Branch Coverage: 87.91%
Branches in Coverage %: Yes
Coverage Strength: 818.58 hits per line

💛 - Coveralls

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants