Skip to content

Commit 1066e70

Browse files
authored
Merge pull request #1800 from dubinc/update-payment-method
Update workspace payout method
2 parents b0f4257 + e9d294b commit 1066e70

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { prisma } from "@dub/prisma";
2+
import Stripe from "stripe";
3+
4+
export async function paymentMethodAttached(event: Stripe.Event) {
5+
const { id, customer, type } = event.data.object as Stripe.PaymentMethod;
6+
7+
if (type !== "us_bank_account") {
8+
return;
9+
}
10+
11+
await prisma.project.update({
12+
where: {
13+
stripeId: customer as string,
14+
},
15+
data: {
16+
payoutMethodId: id,
17+
},
18+
});
19+
}

apps/web/app/api/stripe/webhook/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { checkoutSessionCompleted } from "./checkout-session-completed";
88
import { customerSubscriptionDeleted } from "./customer-subscription-deleted";
99
import { customerSubscriptionUpdated } from "./customer-subscription-updated";
1010
import { invoicePaymentFailed } from "./invoice-payment-failed";
11+
import { paymentMethodAttached } from "./payment-method-attached";
1112

1213
const relevantEvents = new Set([
1314
"account.updated",
1415
"charge.succeeded",
16+
"payment_method.attached",
1517
"checkout.session.completed",
1618
"customer.subscription.updated",
1719
"customer.subscription.deleted",
@@ -48,6 +50,9 @@ export const POST = async (req: Request) => {
4850
case "charge.succeeded":
4951
await chargeSucceeded(event);
5052
break;
53+
case "payment_method.attached":
54+
await paymentMethodAttached(event);
55+
break;
5156
case "checkout.session.completed":
5257
await checkoutSessionCompleted(event);
5358
break;

0 commit comments

Comments
 (0)