Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix stripePayoutTraceId type

Steven Tey302f91648528
diff --git a/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts b/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts
index afc9542a79..ade225e7c9 100644
--- a/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts
+++ b/apps/web/app/(ee)/api/stripe/connect/webhook/payout-paid.ts
@@ -23,14 +23,13 @@ export async function payoutPaid(event: Stripe.Event) {
const stripePayout = event.data.object as Stripe.Payout;
+ const stripePayoutTraceId = stripePayout.trace_id?.value ?? null;
+
const updatedPayouts = await prisma.payout.updateMany({
where: {
status: "sent",
stripePayoutId: stripePayout.id,
- stripePayoutTraceId:
- typeof stripePayout.trace_id === "string"
- ? stripePayout.trace_id
- : null,
+ stripePayoutTraceId,
},
data: {
status: "completed",
@@ -48,10 +47,7 @@ export async function payoutPaid(event: Stripe.Event) {
amount: stripePayout.amount,
currency: stripePayout.currency,
arrivalDate: stripePayout.arrival_date,
- traceId:
- typeof stripePayout.trace_id === "string"
- ? stripePayout.trace_id
- : null,
+ traceId: stripePayoutTraceId,
},
}),
});
diff --git a/apps/web/scripts/stripe/backfill-trace-id.ts b/apps/web/scripts/stripe/backfill-trace-id.ts
new file mode 100644
index 0000000000..f9023e4440
--- /dev/null
+++ b/apps/web/scripts/stripe/backfill-trace-id.ts
@@ -0,0 +1,43 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import { stripeConnectClient } from "./connect-client";
+
+async function main() {
+ const payouts = await prisma.payout.findMany({
+ where: {
+ stripePayoutId: {
+ not: null,
+ },
+ stripePayoutTraceId: null,
+ },
+ include: {
+ partner: {
+ select: {
+ stripeConnectId: true,
+ },
+ },
+ },
+ take: 20,
+ });
+
+ await Promise.all(
+ payouts.map(async (payout) => {
+ try {
+ const stripePayout = await stripeConnectClient.payouts.retrieve(
+ payout.stripePayoutId!,
+ {
+ stripeAccount: payout.partner.stripeConnectId!,
+ },
+ );
+ const { status, trace_id } = stripePayout;
+ console.log(
+ `${payout.id} - ${status} - ${JSON.stringify(trace_id, null, 2)}`,
+ );
+ } catch (error) {
+ console.error(error.message);
+ }
+ }),
+ );
+}
+
+main();