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.

Send external payout webhooks from staging and sandbox (#4676)

Pedro Ladeira4b96e8ebc4a2
diff --git a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts
index 1f4f17e237..84c263e9cf 100644
--- a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts
@@ -142,7 +142,7 @@ export const POST = withCron(async ({ rawBody }) => {
]
: []),
- ...(isProductionWorkspace ? [queueExternalPayouts(invoice)] : []),
+ queueExternalPayouts(invoice),
// For non-production workspaces, mock the payout completion
...(!isProductionWorkspace
diff --git a/apps/web/lib/sandbox/mock-payout-completion.ts b/apps/web/lib/sandbox/mock-payout-completion.ts
index 1ae4e3b9e4..94e0b9219f 100644
--- a/apps/web/lib/sandbox/mock-payout-completion.ts
+++ b/apps/web/lib/sandbox/mock-payout-completion.ts
@@ -17,7 +17,8 @@ interface MockPayoutCompletionParams {
workspace: Pick<Project, "id" | "environment">;
}
-// Mark the all payouts and commissions in the invoice as paid
+// Mark internal payouts and their commissions as paid. External payouts stay
+// processing until the webhook callback. The invoice is marked completed either way.
export async function mockPayoutCompletion({
invoice,
workspace,
@@ -30,6 +31,7 @@ export async function mockPayoutCompletion({
where: {
invoiceId: invoice.id,
status: PayoutStatus.processing,
+ mode: "internal",
},
orderBy: {
id: "asc",
@@ -52,12 +54,42 @@ export async function mockPayoutCompletion({
},
});
- if (payouts.length === 0) {
+ const payoutIds = payouts.map((p) => p.id);
+
+ await prisma.$transaction([
+ prisma.invoice.update({
+ where: {
+ id: invoice.id,
+ },
+ data: {
+ status: InvoiceStatus.completed,
+ paidAt: new Date(),
+ },
+ }),
+ ...(payoutIds.length > 0
+ ? [
+ prisma.payout.updateMany({
+ where: {
+ id: {
+ in: payoutIds,
+ },
+ },
+ data: {
+ status: PayoutStatus.completed,
+ paidAt: new Date(),
+ },
+ }),
+ ]
+ : []),
+ ]);
+
+ if (payoutIds.length === 0) {
+ console.log(
+ `[mockPayoutCompletion] No internal payouts found for invoice ${invoice.id}, skipping commission updates...`,
+ );
return;
}
- const payoutIds = payouts.map((p) => p.id);
-
const commissions = await prisma.commission.findMany({
where: {
payoutId: {
@@ -73,30 +105,6 @@ export async function mockPayoutCompletion({
},
});
- await prisma.$transaction([
- prisma.payout.updateMany({
- where: {
- id: {
- in: payoutIds,
- },
- },
- data: {
- status: PayoutStatus.completed,
- paidAt: new Date(),
- },
- }),
-
- prisma.invoice.update({
- where: {
- id: invoice.id,
- },
- data: {
- status: InvoiceStatus.completed,
- paidAt: new Date(),
- },
- }),
- ]);
-
const commissionIds = commissions.map((c) => c.id);
let totalUpdatedCommissions = 0;