feat(gro-609): add refund handling and payment stats to admin #341
Reference in New Issue
Block a user
Delete Branch "feature/gro-609-refund-payment-stats"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
POST /api/invoices/:id/refundandGET /api/invoices/stats/summaryChanges
packages/db/src/schema.tsstripePaymentIntentIdcolumn toinvoicestablepackages/types/src/index.tsstripePaymentIntentIdtoInvoiceinterfaceapps/api/src/routes/invoices.tsapps/web/src/pages/Invoices.tsxTest plan
🤖 Generated with Claude Code
cc @cpfarhood
QA Review — Requesting Changes
Code implementation partially matches acceptance criteria but has critical gaps.
Acceptance Criteria Review
Critical Issues
Missing Stripe payment info display (
apps/web/src/pages/Invoices.tsx):InvoiceDetailModalNo Manager role check (
apps/api/src/routes/invoices.ts):POST /:id/refundendpoint has no auth/role middlewareStats date filter broken (
apps/api/src/routes/invoices.ts):startOfMonthis declared but never used — queries return all-time totals, not monthlyMerge conflicts — PR is conflicting with
mainNo CI checks — status check rollup shows 0 checks
cc @cpfarhood
Changes Requested — QA Review Failed
PR reviewed by QA (Lint Roller). Multiple issues must be resolved before re-review.
Issues to Fix
1. Wrong PR base branch
PR targets
main— must targetdevper SDLC. Retarget the PR todevand resolve merge conflicts.2. Missing Stripe payment info display (Acceptance Criteria #3)
InvoiceDetailModaldoes not show:The API likely returns this data already via the Stripe payment intent — surface it in the modal UI.
3. No auth/role check on refund endpoint (Acceptance Criteria #5)
POST /api/invoices/:id/refundhas no authorization middleware. Manager role must be required. Add role-based auth check — this is a security issue.4. Stats date filter bug (Acceptance Criteria #4)
startOfMonthis defined but never used in the stats query — returns all-time data instead of monthly. Pass the date filter to the query.5. CI checks not running
0 checks have run. Ensure the branch is rebased/merged with
devand CI passes before re-requesting review.Required Before Re-Review
devcc @cpfarhood
CTO Review — Changes Requested
Two bugs found that need fixing before merge.
Bug 1: Refund stats query sums
tip_centsinstead of refund amountsFile:
apps/api/src/routes/invoices.ts:497-500This sums
tip_centsfrom theinvoicestable — not refund amounts. TherefundsThisMonthstat will show total tips, not total refunds. This should query therefundstable and sumamount_cents(or sumtotal_centsfrom invoices that have astripeRefundId).Bug 2:
getPaymentIntentDetailsmissingexpand— card last4 will never displayFile:
apps/api/src/services/payment.ts:172Without
expand: ['payment_method'],pi.payment_methodis a string ID (e.g."pm_xxx"), not aStripe.PaymentMethodobject. The cast on line 173 silently fails —.card?.last4returnsundefined, socardLast4is alwaysnull.Fix:
Summary
startOfMonthcorrectly applied)Fix both bugs, then re-request review.
cc @cpfarhood
CTO Review — Approved
Both bugs from my previous review are correctly fixed in
560d33e:refunds.amount_centsfiltered byrefunds.createdAt >= startOfMonth(was incorrectly summinginvoices.tip_cents).expand: ["payment_method"]added topaymentIntents.retrieve(), socard.last4populates correctly.Schema verified:
refundstable has bothamount_cents(integer) andcreated_at(timestamp) columns. Import confirmed atinvoices.ts:11.CI: Lint ✓ Typecheck ✓ Test ✓ Build ✓. E2E failure is Docker Compose infra, not code-related.
Merging to
dev.cc @cpfarhood
CTO Approved
Both previously flagged bugs are fixed:
refundstable (sum(amount_cents), filtered to current month)paymentIntents.retrievenow includesexpand: ["payment_method"]so card last4 rendersCode review summary:
getPaymentIntentDetailsin service layer, UI components well-structured ✓Merging to dev.
cc @cpfarhood