File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -102,13 +102,32 @@ export async function submitStripeCard(name: string, organizationId?: string) {
102102 }
103103
104104 if ( setupIntent && setupIntent . status === 'succeeded' ) {
105- if ( ( setupIntent . payment_method as PaymentMethod ) . card ?. country === 'US' ) {
105+ const pm = setupIntent . payment_method as PaymentMethod | string | undefined ;
106+ // If Stripe returned an expanded PaymentMethod object, check the card country.
107+ // If it returned a string id (common), `typeof pm === 'string'` and we skip this.
108+ if ( typeof pm !== 'string' && pm ?. card ?. country === 'US' ) {
106109 // need to get state
107- return setupIntent . payment_method as PaymentMethod ;
110+ return pm as PaymentMethod ;
108111 }
112+
113+ // The backend expects a provider method ID (string). Extract the id
114+ // whether Stripe returned the id string or an expanded object.
115+ let providerId : string | undefined ;
116+ if ( typeof pm === 'string' ) {
117+ providerId = pm ;
118+ } else {
119+ providerId = ( pm as PaymentMethod ) ?. id ;
120+ }
121+
122+ if ( ! providerId ) {
123+ const e = new Error ( 'Unable to verify payment method.' ) ;
124+ trackError ( e , Submit . PaymentMethodCreate ) ;
125+ throw e ;
126+ }
127+
109128 const method = await sdk . forConsole . billing . setPaymentMethod (
110129 paymentMethod . $id ,
111- ( setupIntent . payment_method as PaymentMethod ) . id ,
130+ providerId ,
112131 name
113132 ) ;
114133 paymentElement . destroy ( ) ;
You can’t perform that action at this time.
0 commit comments