File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed
packages/apps/job-launcher/server/src/modules/payment Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -131,19 +131,27 @@ export class PaymentService {
131131 this . logger . log ( ErrorPayment . SetupNotFound , PaymentService . name ) ;
132132 throw new NotFoundError ( ErrorPayment . SetupNotFound ) ;
133133 }
134- if ( data . defaultCard || ! user . stripeCustomerId ) {
134+
135+ let defaultPaymentMethod : string | null = null ;
136+ if ( ! user . stripeCustomerId ) {
137+ // Assign the Stripe customer ID to the user if it does not exist yet.
138+ user . stripeCustomerId = setup . customer as string ;
139+ await this . userRepository . updateOne ( user ) ;
140+ } else {
141+ // Check if the user already has a default payment method.
142+ defaultPaymentMethod = await this . getDefaultPaymentMethod (
143+ user . stripeCustomerId ,
144+ ) ;
145+ }
146+
147+ if ( data . defaultCard || ! defaultPaymentMethod ) {
135148 // Update Stripe customer settings to use this payment method by default.
136- await this . stripe . customers . update ( < string > setup . customer , {
149+ await this . stripe . customers . update ( user . stripeCustomerId , {
137150 invoice_settings : {
138151 default_payment_method : < string > setup . payment_method ,
139152 } ,
140153 } ) ;
141154 }
142- if ( ! user . stripeCustomerId ) {
143- // Assign the Stripe customer ID to the user if it does not exist yet.
144- user . stripeCustomerId = setup . customer as string ;
145- await this . userRepository . updateOne ( user ) ;
146- }
147155
148156 return true ;
149157 }
You can’t perform that action at this time.
0 commit comments