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 workspace payout method

Kiran Ke9d294bb62dc
diff --git a/apps/web/app/api/stripe/webhook/payment-method-attached.ts b/apps/web/app/api/stripe/webhook/payment-method-attached.ts
new file mode 100644
index 0000000000..581fddb969
--- /dev/null
+++ b/apps/web/app/api/stripe/webhook/payment-method-attached.ts
@@ -0,0 +1,19 @@
+import { prisma } from "@dub/prisma";
+import Stripe from "stripe";
+
+export async function paymentMethodAttached(event: Stripe.Event) {
+ const { id, customer, type } = event.data.object as Stripe.PaymentMethod;
+
+ if (type !== "us_bank_account") {
+ return;
+ }
+
+ await prisma.project.update({
+ where: {
+ stripeId: customer as string,
+ },
+ data: {
+ payoutMethodId: id,
+ },
+ });
+}
diff --git a/apps/web/app/api/stripe/webhook/route.ts b/apps/web/app/api/stripe/webhook/route.ts
index 17e44d2bb0..4146cad676 100644
--- a/apps/web/app/api/stripe/webhook/route.ts
+++ b/apps/web/app/api/stripe/webhook/route.ts
@@ -8,10 +8,12 @@ import { checkoutSessionCompleted } from "./checkout-session-completed";
import { customerSubscriptionDeleted } from "./customer-subscription-deleted";
import { customerSubscriptionUpdated } from "./customer-subscription-updated";
import { invoicePaymentFailed } from "./invoice-payment-failed";
+import { paymentMethodAttached } from "./payment-method-attached";
const relevantEvents = new Set([
"account.updated",
"charge.succeeded",
+ "payment_method.attached",
"checkout.session.completed",
"customer.subscription.updated",
"customer.subscription.deleted",
@@ -48,6 +50,9 @@ export const POST = async (req: Request) => {
case "charge.succeeded":
await chargeSucceeded(event);
break;
+ case "payment_method.attached":
+ await paymentMethodAttached(event);
+ break;
case "checkout.session.completed":
await checkoutSessionCompleted(event);
break;