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.

address feedback

Steven Tey1b911d48541a
diff --git a/apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts b/apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts
index 770b44d521..e0e1ca02a7 100644
--- a/apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts
+++ b/apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts
@@ -22,7 +22,7 @@ export const updatePartnerWithdrawalAmountAction = authPartnerActionClient
const { partner } = ctx;
const { minWithdrawalAmount } = parsedInput;
- await prisma.partner.update({
+ const updatedPartner = await prisma.partner.update({
where: {
id: partner.id,
},
@@ -33,10 +33,10 @@ export const updatePartnerWithdrawalAmountAction = authPartnerActionClient
waitUntil(
(async () => {
- if (partner.stripeConnectId && partner.payoutsEnabledAt) {
+ if (updatedPartner.stripeConnectId && updatedPartner.payoutsEnabledAt) {
const previouslyProcessedPayouts = await prisma.payout.findMany({
where: {
- partnerId: partner.id,
+ partnerId: updatedPartner.id,
status: "processed",
stripeTransferId: null,
},
@@ -44,7 +44,7 @@ export const updatePartnerWithdrawalAmountAction = authPartnerActionClient
if (previouslyProcessedPayouts.length > 0) {
await createStripeTransfer({
- partner,
+ partner: updatedPartner,
previouslyProcessedPayouts,
});
}
diff --git a/apps/web/lib/partners/create-stripe-transfer.ts b/apps/web/lib/partners/create-stripe-transfer.ts
index 044e22a708..a3623df4f5 100644
--- a/apps/web/lib/partners/create-stripe-transfer.ts
+++ b/apps/web/lib/partners/create-stripe-transfer.ts
@@ -16,6 +16,12 @@ export const createStripeTransfer = async ({
previouslyProcessedPayouts: Pick<Payout, "id" | "amount" | "invoiceId">[];
currentInvoicePayouts?: Pick<Payout, "id" | "amount" | "invoiceId">[];
}) => {
+ // this should never happen since we guard for it outside, but just in case
+ if (!partner.stripeConnectId) {
+ console.log(`Partner ${partner.id} has no stripeConnectId, skipping...`);
+ return;
+ }
+
let withdrawalFee = 0;
const allPayouts = [
@@ -23,6 +29,12 @@ export const createStripeTransfer = async ({
...(currentInvoicePayouts ?? []),
];
+ // this should never happen but just in case
+ if (allPayouts.length === 0) {
+ console.log(`No payouts found for partner ${partner.id}, skipping...`);
+ return;
+ }
+
// will be used for transfer_group and idempotencyKey
const finalPayoutInvoiceId = allPayouts[allPayouts.length - 1].invoiceId;
@@ -79,7 +91,7 @@ export const createStripeTransfer = async ({
// here, `transfer_group` technically only used to associate the transfer with the invoice
// (even though the transfer could technically include payouts from multiple invoices)
transfer_group: finalPayoutInvoiceId!,
- destination: partner.stripeConnectId!,
+ destination: partner.stripeConnectId,
description: `Dub Partners payout for ${allPayouts.map((p) => p.id).join(", ")}`,
},
{