The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix withdrawal cron
Steven Tey48e71fefad4e
diff --git a/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts b/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.tsindex 208380db14..6dade3f723 100644--- a/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts+++ b/apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts@@ -32,21 +32,13 @@ export async function GET(req: Request) {const currentAvailableBalance = stripeBalanceData.available[0].amount;const currentPendingBalance = stripeBalanceData.pending[0].amount;-- // if the pending balance is negative, add it to the available balance- // this only happens when we have a connected account transfer that hasn't fully settled yet- // x-slack-ref: https://dub.slack.com/archives/C074P7LMV9C/p1750185638973479- const currentNetBalance =- currentPendingBalance < 0- ? currentAvailableBalance + currentPendingBalance- : currentAvailableBalance;+ const currentNetBalance = currentAvailableBalance + currentPendingBalance;console.log({currentAvailableBalance,currentPendingBalance,currentNetBalance,toBeSentPayouts,- stripeBalanceData,});let reservedBalance = 50000; // keep at least $500 in the account@@ -55,7 +47,7 @@ export async function GET(req: Request) {if (totalToBeSentPayouts) {// add the total payouts that are still to be sent to connected accounts// to the reserved balance (to make sure we have enough balance- // to pay out partners when chargeSucceeded webhook is triggered)+ // to pay out partners when charge.succeeded webhook is triggered)reservedBalance += totalToBeSentPayouts;}diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsxindex 8970ec6d66..4140a53dc4 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx@@ -309,7 +309,14 @@ function BasicInfoForm({<CountryComboboxvalue={field.value || ""}onChange={field.onChange}- disabledTooltip="Your country cannot be changed once set. If you need to update your country, please contact support."+ error={errors.country ? true : false}+ disabledTooltip={+ disabled+ ? "You don't have permission to update this field"+ : completedPayoutsCount > 0+ ? "Since you've already received payouts on Dub, you cannot change your country. If you need to update your country, please contact support."+ : undefined+ }/>)}/>diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsxindex 3249dde402..ff5149379b 100644--- a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx@@ -180,8 +180,8 @@ export function OnboardingForm({{...field}error={errors.country ? true : false}disabledTooltip={- partner?.country- ? "Your country cannot be changed once set. If you need to update your country, please contact support."+ partner?.payoutsEnabledAt+ ? "Since you've already received payouts, you cannot change your country. Contact support if you need to update your country.": undefined}/>diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.tsindex d81d789bfd..0e07f1beb7 100644--- a/apps/web/lib/actions/partners/update-partner-profile.ts+++ b/apps/web/lib/actions/partners/update-partner-profile.ts@@ -68,12 +68,6 @@ export const updatePartnerProfileAction = authPartnerActionClientdiscoverable,} = parsedInput;- if (country !== undefined && country !== partner.country) {- throw new Error(- "Your country cannot be changed once set. If you need to update your country, please contact support.",- );- }-if (profileType === "company" &&(companyName === undefined ? !partner.companyName : !companyName)@@ -263,6 +257,10 @@ const deleteStripeAccountIfRequired = async ({partner: Partner;input: z.infer<typeof updatePartnerProfileSchema>;}) => {+ const countryChanged =+ input.country !== undefined &&+ partner.country?.toLowerCase() !== input.country?.toLowerCase();+const profileTypeChanged =input.profileType !== undefined &&partner.profileType.toLowerCase() !== input.profileType.toLowerCase();@@ -278,20 +276,20 @@ const deleteStripeAccountIfRequired = async ({return;}- // Partner is not able to update their profile type or company name+ // Partner is not able to update their country, profile type, or company name// if they have already have a Stripe Express account + any sent / completed payoutsconst completedPayoutsCount = await prisma.payout.count({where: {partnerId: partner.id,status: {- in: ["sent", "completed"],+ in: ["processing", "processed", "sent", "completed"],},},});if (completedPayoutsCount > 0) {throw new Error(- "Since you've already received payouts on Dub, you cannot change your profile type. Please contact support to update your profile type.",+ "Since you've already received payouts on Dub, you cannot change your country or profile type. Please contact support to update those fields.",);}