The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix "charge.refunded"
Kiran K0052c244b9b2
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/charge-refunded.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/charge-refunded.tsindex 22db2253c7..4616feacb5 100644--- a/apps/web/app/(ee)/api/stripe/integration/webhook/charge-refunded.ts+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/charge-refunded.ts@@ -1,3 +1,4 @@+import { stripeAppClient } from "@/lib/stripe";import { prisma } from "@dub/prisma";import type Stripe from "stripe";@@ -6,7 +7,26 @@ export async function chargeRefunded(event: Stripe.Event) {const charge = event.data.object as Stripe.Charge;const stripeAccountId = event.account as string;- if (!charge.invoice) {+ const stripe = stripeAppClient({+ livemode: event.livemode,+ });++ const invoicePayments = await stripe.invoicePayments.list(+ {+ payment: {+ payment_intent: charge.payment_intent as string,+ type: "payment_intent",+ },+ },+ {+ stripeAccount: stripeAccountId,+ },+ );++ const invoicePayment =+ invoicePayments.data.length > 0 ? invoicePayments.data[0] : null;++ if (!invoicePayment || !invoicePayment.invoice) {return `Charge ${charge.id} has no invoice, skipping...`;}@@ -32,7 +52,7 @@ export async function chargeRefunded(event: Stripe.Event) {where: {programId_invoiceId: {programId: workspace.programs[0].id,- invoiceId: charge.invoice as string,+ invoiceId: invoicePayment.invoice as string,},},select: {@@ -44,7 +64,7 @@ export async function chargeRefunded(event: Stripe.Event) {});if (!commission) {- return `Commission not found for invoice ${charge.invoice}`;+ return `Commission not found for invoice ${invoicePayment.invoice}`;}if (commission.status === "paid") {