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.

Add small withdrawal fee constant, implement manual payout schedule in connected accounts, and create scripts for manual payouts and updating payout schedules

Kiran Kd4d3701ad59f
diff --git a/apps/web/lib/partners/constants.ts b/apps/web/lib/partners/constants.ts
index 855f53864e..1ee751750e 100644
--- a/apps/web/lib/partners/constants.ts
+++ b/apps/web/lib/partners/constants.ts
@@ -6,6 +6,7 @@ export const REFERRALS_EMBED_EARNINGS_LIMIT = 8;
export const CUSTOMER_PAGE_EVENTS_LIMIT = 8;
export const PAYOUT_FAILURE_FEE_CENTS = 1000; // 10 USD
export const FOREX_MARKUP_RATE = 0.005; // 0.5%
+export const SMALL_WITHDRAWAL_FEE_CENTS = 200; // $2 fee for withdrawals under $100
// Direct debit payment types for Partner payout
export const DIRECT_DEBIT_PAYMENT_TYPES_INFO: {
diff --git a/apps/web/lib/stripe/create-connected-account.ts b/apps/web/lib/stripe/create-connected-account.ts
index 0999116793..7729ceb766 100644
--- a/apps/web/lib/stripe/create-connected-account.ts
+++ b/apps/web/lib/stripe/create-connected-account.ts
@@ -48,6 +48,13 @@ export const createConnectedAccount = async ({
...(country !== "US" && {
tos_acceptance: { service_agreement: "recipient" },
}),
+ settings: {
+ payouts: {
+ schedule: {
+ interval: "manual",
+ },
+ },
+ },
});
} catch (error) {
throw new Error(error.message);
diff --git a/apps/web/scripts/stripe/manual-payouts.ts b/apps/web/scripts/stripe/manual-payouts.ts
new file mode 100644
index 0000000000..ac275dc1be
--- /dev/null
+++ b/apps/web/scripts/stripe/manual-payouts.ts
@@ -0,0 +1,55 @@
+import "dotenv-flow/config";
+import { stripe } from "@/lib/stripe";
+
+// Just for testing purposes
+async function main() {
+ const connectedAccount = "acct_...";
+
+ // 1. Do a transfer
+ const transfer = await stripe.transfers.create({
+ amount: 1000,
+ currency: "usd",
+ destination: connectedAccount,
+ });
+
+ console.log("Transfer created", {
+ id: transfer.id,
+ amount: transfer.amount,
+ currency: transfer.currency,
+ destination: transfer.destination,
+ });
+
+ // 2. Check the balance
+ const balance = await stripe.balance.retrieve({
+ stripeAccount: connectedAccount,
+ });
+
+ console.log("Balance", balance.available);
+
+ // 3. Create payout
+ const payout = await stripe.payouts.create(
+ {
+ amount: balance.available[0].amount,
+ currency: "usd",
+ },
+ {
+ stripeAccount: connectedAccount,
+ },
+ );
+
+ console.log("Payout created", {
+ id: payout.id,
+ amount: payout.amount,
+ currency: payout.currency,
+ destination: payout.destination,
+ });
+
+ // 4. Check the balance after the payout
+ const balance2 = await stripe.balance.retrieve({
+ stripeAccount: connectedAccount,
+ });
+
+ console.log("Balance", balance2.available);
+}
+
+main();
diff --git a/apps/web/scripts/stripe/update-stripe-payouts-schedule.ts b/apps/web/scripts/stripe/update-stripe-payouts-schedule.ts
new file mode 100644
index 0000000000..844f920776
--- /dev/null
+++ b/apps/web/scripts/stripe/update-stripe-payouts-schedule.ts
@@ -0,0 +1,44 @@
+import "dotenv-flow/config";
+import { stripe } from "@/lib/stripe";
+import { prisma } from "@dub/prisma";
+
+async function main() {
+ const limit = 1;
+ const offset = 0;
+
+ const partners = await prisma.partner.findMany({
+ where: {
+ stripeConnectId: {
+ not: null,
+ },
+ },
+ take: limit,
+ skip: offset,
+ orderBy: {
+ createdAt: "asc",
+ },
+ });
+
+ if (partners.length === 0) {
+ console.log("No partners found.");
+ return;
+ }
+
+ for (const partner of partners) {
+ try {
+ await stripe.accounts.update(partner.stripeConnectId!, {
+ settings: {
+ payouts: {
+ schedule: {
+ interval: "manual",
+ },
+ },
+ },
+ });
+ } catch (error) {
+ console.error(error);
+ }
+ }
+}
+
+main();