@@ -70,7 +70,7 @@ export function PaymentMethodManagement({
7070 setError ( null ) ;
7171 setHasPaymentMethod (
7272 ! ! event . value . payment_method ||
73- ( event . value . type === 'link' && defaultPaymentMethod ?. type === 'link' )
73+ ( event . value . type === 'link' && defaultPaymentMethod ?. type === 'link' )
7474 ) ;
7575
7676 if ( event . value . type !== 'card' ) {
@@ -181,25 +181,21 @@ export function PaymentMethodManagement({
181181 throw confirmationTokenError ;
182182 }
183183
184- let response ;
185- try {
186- response = await updateStripePaymentDetails (
187- uid ?? '' ,
188- confirmationToken . id
189- ) ;
190- } catch ( error ) {
191- const errorReason = getManagePaymentMethodErrorFtlInfo ( error . message ) ;
184+ const { ok, result, errorMessage } = await updateStripePaymentDetails (
185+ uid ?? '' ,
186+ confirmationToken . id
187+ ) ;
188+ if ( ! ok || ! result ) {
189+ const errorReason = getManagePaymentMethodErrorFtlInfo ( errorMessage ) ;
192190 setError (
193191 l10n . getString ( errorReason . messageFtl , { } , errorReason . message )
194192 ) ;
195- return ;
196- }
197-
198- if ( response . status === 'requires_action' && response . clientSecret ) {
199- await handleNextAction ( response . clientSecret ) ;
193+ } else {
194+ if ( result . status === 'requires_action' && result . clientSecret ) {
195+ await handleNextAction ( result . clientSecret ) ;
196+ }
197+ router . refresh ( ) ;
200198 }
201-
202- router . refresh ( ) ;
203199 } catch ( error ) {
204200 console . error ( error ) ;
205201 setError ( error . message || 'An unexpected error occurred.' ) ;
@@ -265,30 +261,30 @@ export function PaymentMethodManagement({
265261 </ Form . Field >
266262 { ( isInputNewCardDetails ||
267263 ( isNonCardSelected && ! hasPaymentMethod ) ) && (
268- < div className = "flex flex-row justify-center pt-4" >
269- < Form . Submit asChild >
270- < BaseButton
271- className = "h-10 mt-10 w-full"
272- type = "submit"
273- variant = { ButtonVariant . Primary }
274- aria-disabled = { ! stripe || ! isComplete || isLoading }
275- disabled = { ! stripe || ! isComplete || isLoading }
276- >
277- { isLoading ? (
278- < Image
279- src = { spinnerWhiteImage }
280- alt = ""
281- className = "absolute animate-spin h-8 w-8"
282- />
283- ) : (
284- < Localized id = "payment-method-management-save-method" >
285- Save payment method
286- </ Localized >
287- ) }
288- </ BaseButton >
289- </ Form . Submit >
290- </ div >
291- ) }
264+ < div className = "flex flex-row justify-center pt-4" >
265+ < Form . Submit asChild >
266+ < BaseButton
267+ className = "h-10 mt-10 w-full"
268+ type = "submit"
269+ variant = { ButtonVariant . Primary }
270+ aria-disabled = { ! stripe || ! isComplete || isLoading }
271+ disabled = { ! stripe || ! isComplete || isLoading }
272+ >
273+ { isLoading ? (
274+ < Image
275+ src = { spinnerWhiteImage }
276+ alt = ""
277+ className = "absolute animate-spin h-8 w-8"
278+ />
279+ ) : (
280+ < Localized id = "payment-method-management-save-method" >
281+ Save payment method
282+ </ Localized >
283+ ) }
284+ </ BaseButton >
285+ </ Form . Submit >
286+ </ div >
287+ ) }
292288 { isNonDefaultCardSelected && ! isInputNewCardDetails && (
293289 < div className = "flex flex-row justify-center pt-4" >
294290 < Form . Submit asChild >
0 commit comments