@@ -157,14 +157,50 @@ const PlanForm = ({
157157
158158 // If user already submitted payment, don't ask for payment information again
159159 if ( user . stripeCustomerPaymentMethodId ) {
160- await updateSubscription ( {
161- stripeCustomerId : user . stripeCustomerId ,
162- stripeCustomerPaymentMethodId : user . stripeCustomerPaymentMethodId ,
163- stripeCustomerSubscriptionId : user . stripeCustomerSubscriptionId ,
164- stripeProductId,
165- } ) ;
166- setStatus ( "succeeded" ) ;
167- setOpen ( false ) ;
160+ try {
161+ const result : any = await updateSubscription ( {
162+ stripeCustomerId : user . stripeCustomerId ,
163+ stripeCustomerPaymentMethodId : user . stripeCustomerPaymentMethodId ,
164+ stripeCustomerSubscriptionId : user . stripeCustomerSubscriptionId ,
165+ stripeProductId,
166+ } ) ;
167+
168+ if ( result ?. error || result ?. errors ) {
169+ console . error ( result . error || result . errors ) ;
170+ setStatus ( "error" ) ;
171+ openSnackbar ( "Payment failed. Please update your payment method." ) ;
172+ return ;
173+ }
174+
175+ const pendingSetupIntent = result ?. pending_setup_intent ;
176+ if ( pendingSetupIntent ?. status === "requires_action" ) {
177+ const confirmResult = await stripe . confirmCardSetup (
178+ pendingSetupIntent . client_secret ,
179+ {
180+ payment_method : user . stripeCustomerPaymentMethodId ,
181+ } ,
182+ ) ;
183+ if ( confirmResult . error ) {
184+ console . error ( confirmResult . error ) ;
185+ setStatus ( "error" ) ;
186+ openSnackbar ( "Payment verification failed." ) ;
187+ return ;
188+ }
189+ }
190+
191+ if ( result ?. status === "past_due" || result ?. status === "unpaid" ) {
192+ setStatus ( "error" ) ;
193+ openSnackbar ( "Payment failed. Please update your payment method." ) ;
194+ return ;
195+ }
196+
197+ setStatus ( "succeeded" ) ;
198+ setOpen ( false ) ;
199+ } catch ( error ) {
200+ console . error ( error ) ;
201+ setStatus ( "error" ) ;
202+ openSnackbar ( "An error occurred. Please try again." ) ;
203+ }
168204 } else {
169205 const cardElement = elements ! . getElement ( CardElement ) ;
170206 createPaymentMethod ( {
0 commit comments