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;