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.

Update retry-failed-paypal-payouts.ts

Kiran Kade910c62574
diff --git a/apps/web/lib/actions/partners/retry-failed-paypal-payouts.ts b/apps/web/lib/actions/partners/retry-failed-paypal-payouts.ts
index 0a66f5c7cf..b764f0cbfd 100644
--- a/apps/web/lib/actions/partners/retry-failed-paypal-payouts.ts
+++ b/apps/web/lib/actions/partners/retry-failed-paypal-payouts.ts
@@ -1,6 +1,7 @@
"use server";
import { createPayPalBatchPayout } from "@/lib/paypal/create-batch-payout";
+import { ratelimit } from "@/lib/upstash";
import { prisma } from "@dub/prisma";
import { authPartnerActionClient } from "../safe-action";
@@ -19,6 +20,16 @@ export const retryFailedPaypalPayoutsAction = authPartnerActionClient.action(
throw new Error("Connect your PayPal account to enable payouts.");
}
+ const { success } = await ratelimit(5, "24 h").limit(
+ `retry-failed-paypal-payouts:${partner.id}`,
+ );
+
+ if (!success) {
+ throw new Error(
+ "You've reached the maximum number of retry attempts for the past 24 hours. Please wait and try again later.",
+ );
+ }
+
const failedPayouts = await prisma.payout.findMany({
where: {
partnerId: partner.id,