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 <noreply@paperclip.ing>
This commit is contained in:
@@ -495,9 +495,9 @@ invoicesRouter.get("/stats/summary", async (c) => {
|
|||||||
.where(eq(invoices.status, "pending"));
|
.where(eq(invoices.status, "pending"));
|
||||||
|
|
||||||
const [refundsResult] = await db
|
const [refundsResult] = await db
|
||||||
.select({ total: sql<number>`coalesce(sum(tip_cents), 0)` })
|
.select({ total: sql<number>`coalesce(sum(amount_cents), 0)` })
|
||||||
.from(invoices)
|
.from(refunds)
|
||||||
.where(and(eq(invoices.status, "paid"), sql`${invoices.paidAt} >= ${startOfMonth}`));
|
.where(sql`${refunds.createdAt} >= ${startOfMonth}`);
|
||||||
|
|
||||||
const methodBreakdown = await db
|
const methodBreakdown = await db
|
||||||
.select({
|
.select({
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ export async function getPaymentIntentDetails(
|
|||||||
const stripe = getStripeClient();
|
const stripe = getStripeClient();
|
||||||
if (!stripe) return null;
|
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
|
const cardLast4 = pi.payment_method
|
||||||
? (pi.payment_method as Stripe.PaymentMethod).card?.last4 ?? null
|
? (pi.payment_method as Stripe.PaymentMethod).card?.last4 ?? null
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
Reference in New Issue
Block a user