File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
apps/web/app/api/stripe/webhook Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -8,10 +8,12 @@ import { checkoutSessionCompleted } from "./checkout-session-completed";
88import { customerSubscriptionDeleted } from "./customer-subscription-deleted" ;
99import { customerSubscriptionUpdated } from "./customer-subscription-updated" ;
1010import { invoicePaymentFailed } from "./invoice-payment-failed" ;
11+ import { paymentMethodAttached } from "./payment-method-attached" ;
1112
1213const 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 ;
You can’t perform that action at this time.
0 commit comments