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.

pass crypto wallet payout method id

Pedro Ladeira188a3d6ae331
diff --git a/apps/web/lib/partners/create-stablecoin-payout.ts b/apps/web/lib/partners/create-stablecoin-payout.ts
index 73d6352881..a8d7512321 100644
--- a/apps/web/lib/partners/create-stablecoin-payout.ts
+++ b/apps/web/lib/partners/create-stablecoin-payout.ts
@@ -26,6 +26,7 @@ import { markPayoutsAsProcessed } from "../payouts/mark-payouts-as-processed";
import { createStripeOutboundPayment } from "../stripe/create-stripe-outbound-payment";
import { fundFinancialAccount } from "../stripe/fund-financial-account";
import { getStripeRecipientAccount } from "../stripe/get-stripe-recipient-account";
+import { getStripeRecipientPayoutMethod } from "../stripe/get-stripe-recipient-payout-method";
interface CreateStablecoinPayoutParams {
partnerId: string;
@@ -226,6 +227,32 @@ export const createStablecoinPayout = async ({
}
}
+ const stripePayoutMethod = await getStripeRecipientPayoutMethod(
+ partner.stripeRecipientId,
+ );
+
+ if (!stripePayoutMethod?.id) {
+ await prisma.partner.update({
+ where: {
+ id: partner.id,
+ },
+ data: {
+ payoutsEnabledAt: null,
+ },
+ });
+
+ await markPayoutsAsProcessed(currentInvoicePayouts);
+
+ const message = `Stripe recipient account for partner ${partner.email} does not have an active crypto wallet payout method.`;
+
+ if (forceWithdrawal) {
+ throw new Error(message);
+ } else {
+ console.warn(message);
+ return;
+ }
+ }
+
const allPayoutsProgramNames = [
...new Set(allPayouts.map((p) => p.program.name)),
];
@@ -245,6 +272,7 @@ export const createStablecoinPayout = async ({
const outboundPayment = await createStripeOutboundPayment({
stripeRecipientId: partner.stripeRecipientId,
+ payoutMethodId: stripePayoutMethod.id,
amount: totalTransferableAmount,
description: `Dub Partners payout (${allPayoutsProgramNames.join(", ")})`,
idempotencyKey,
diff --git a/apps/web/lib/stripe/create-stripe-outbound-payment.ts b/apps/web/lib/stripe/create-stripe-outbound-payment.ts
index 98f3cfc0d4..c108dd01b7 100644
--- a/apps/web/lib/stripe/create-stripe-outbound-payment.ts
+++ b/apps/web/lib/stripe/create-stripe-outbound-payment.ts
@@ -3,6 +3,7 @@ import { STRIPE_API_VERSION, stripeV2Fetch } from "./stripe-v2-client";
export interface CreateStripeOutboundPaymentParams {
stripeRecipientId: string;
+ payoutMethodId: string;
amount: number;
description: string;
idempotencyKey: string;
@@ -10,6 +11,7 @@ export interface CreateStripeOutboundPaymentParams {
export async function createStripeOutboundPayment({
stripeRecipientId,
+ payoutMethodId,
amount,
description,
idempotencyKey,
@@ -36,6 +38,7 @@ export async function createStripeOutboundPayment({
to: {
recipient: stripeRecipientId,
currency: "usdc",
+ payout_method: payoutMethodId,
},
amount: {
value: amount,
diff --git a/apps/web/lib/stripe/get-stripe-recipient-payout-method.ts b/apps/web/lib/stripe/get-stripe-recipient-payout-method.ts
index cb3b335627..9e7d99940a 100644
--- a/apps/web/lib/stripe/get-stripe-recipient-payout-method.ts
+++ b/apps/web/lib/stripe/get-stripe-recipient-payout-method.ts
@@ -21,5 +21,9 @@ export async function getStripeRecipientPayoutMethod(
throw new Error(error.message);
}
- return data.data?.find((m) => m.type === "crypto_wallet") ?? null;
+ return (
+ data.data?.find(
+ (m) => m.type === "crypto_wallet" && !m.crypto_wallet?.archived,
+ ) ?? null
+ );
}