From 81c2e43a1a14487f0ecc79ae8d5ad84a4ba86e53 Mon Sep 17 00:00:00 2001 From: Test User Date: Sun, 19 Apr 2026 01:55:32 +0000 Subject: [PATCH] fix(gro-609): fix two bugs found by CTO review 1. Refund stats now sum actual refund amounts from refunds table instead of incorrectly summing tip_cents from invoices table. 2. Stripe payment_intents.retrieve now expands payment_method so card.last4 is correctly available instead of null. Co-Authored-By: Paperclip --- apps/api/src/routes/invoices.ts | 6 +++--- apps/api/src/services/payment.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/api/src/routes/invoices.ts b/apps/api/src/routes/invoices.ts index 0d2565a..4d83402 100644 --- a/apps/api/src/routes/invoices.ts +++ b/apps/api/src/routes/invoices.ts @@ -495,9 +495,9 @@ invoicesRouter.get("/stats/summary", async (c) => { .where(eq(invoices.status, "pending")); const [refundsResult] = await db - .select({ total: sql`coalesce(sum(tip_cents), 0)` }) - .from(invoices) - .where(and(eq(invoices.status, "paid"), sql`${invoices.paidAt} >= ${startOfMonth}`)); + .select({ total: sql`coalesce(sum(amount_cents), 0)` }) + .from(refunds) + .where(sql`${refunds.createdAt} >= ${startOfMonth}`); const methodBreakdown = await db .select({ diff --git a/apps/api/src/services/payment.ts b/apps/api/src/services/payment.ts index cad0894..eb97597 100644 --- a/apps/api/src/services/payment.ts +++ b/apps/api/src/services/payment.ts @@ -169,7 +169,7 @@ export async function getPaymentIntentDetails( const stripe = getStripeClient(); if (!stripe) return null; - const pi = await stripe.paymentIntents.retrieve(paymentIntentId); + const pi = await stripe.paymentIntents.retrieve(paymentIntentId, { expand: ["payment_method"] }); const cardLast4 = pi.payment_method ? (pi.payment_method as Stripe.PaymentMethod).card?.last4 ?? null : null;