@@ -224,6 +224,7 @@ function addSubscriptionPaymentCard(
224224 currency : ValueOf < typeof CONST . PAYMENT_CARD_CURRENCY > ;
225225 } ,
226226 fundList : OnyxEntry < FundList > ,
227+ source ?: string ,
227228) {
228229 const { cardNumber, cardYear, cardMonth, cardCVV, addressName, addressZip, currency} = cardData ;
229230
@@ -264,7 +265,7 @@ function addSubscriptionPaymentCard(
264265 ] ;
265266
266267 if ( CONST . SCA_CURRENCIES . has ( currency ) ) {
267- addPaymentCardSCA ( parameters , { optimisticData, successData, failureData} ) ;
268+ addPaymentCardSCA ( parameters , { optimisticData, successData, failureData} , source ) ;
268269 } else {
269270 API . write ( WRITE_COMMANDS . ADD_PAYMENT_CARD , parameters , {
270271 optimisticData,
@@ -279,11 +280,25 @@ function addSubscriptionPaymentCard(
279280 }
280281}
281282
283+ /**
284+ * Records which screen initiated a 3DS verification request, so only that screen's mounted
285+ * useNavigateToCardAuthenticationOnLink hook reacts to the resulting link by navigating. Callers pass their own
286+ * `route.name`; passing nothing (e.g. the card-authentication screen re-verifying its own iframe in place) leaves
287+ * the existing source untouched, so a stray re-verify never clobbers the screen that originally opened the flow.
288+ */
289+ function setVerify3dsSubscriptionSource ( source ?: string ) {
290+ if ( ! source ) {
291+ return ;
292+ }
293+ Onyx . merge ( ONYXKEYS . VERIFY_3DS_SUBSCRIPTION_SOURCE , source ) ;
294+ }
295+
282296/**
283297 * Calls the API to add a new SCA (GBP or EUR) card.
284298 * Updates verify3dsSubscription Onyx key with a new authentication link for 3DS.
285299 */
286- function addPaymentCardSCA ( params : AddPaymentCardParams , onyxData : OnyxData < typeof ONYXKEYS . FORMS . ADD_PAYMENT_CARD_FORM > = { } ) {
300+ function addPaymentCardSCA ( params : AddPaymentCardParams , onyxData : OnyxData < typeof ONYXKEYS . FORMS . ADD_PAYMENT_CARD_FORM > = { } , source ?: string ) {
301+ setVerify3dsSubscriptionSource ( source ) ;
287302 API . write ( WRITE_COMMANDS . ADD_PAYMENT_CARD_SCA , params , onyxData ) ;
288303}
289304
@@ -307,20 +322,35 @@ function clearPaymentCardFormErrorAndSubmit() {
307322 } ) ;
308323}
309324
310- /**
311- * Clear 3ds flow - when verification will be finished
312- *
313- */
314- function clearPaymentCard3dsVerification ( ) {
315- Onyx . set ( ONYXKEYS . VERIFY_3DS_SUBSCRIPTION , '' ) ;
316- }
317-
318325/**
319326 * Properly updates the nvp_privateStripeCustomerID onyx data for 3DS payment
320327 *
321328 */
322- function verifySetupIntent ( accountID : number , isVerifying = true ) {
323- API . write ( WRITE_COMMANDS . VERIFY_SETUP_INTENT , { accountID, isVerifying} ) ;
329+ function verifySetupIntent ( accountID : number , isVerifying = true , source ?: string ) {
330+ setVerify3dsSubscriptionSource ( source ) ;
331+ const optimisticData : Array < OnyxUpdate < typeof ONYXKEYS . SUBSCRIPTION_VERIFY_SETUP_INTENT_PENDING > > = [
332+ {
333+ onyxMethod : Onyx . METHOD . MERGE ,
334+ key : ONYXKEYS . SUBSCRIPTION_VERIFY_SETUP_INTENT_PENDING ,
335+ value : true ,
336+ } ,
337+ ] ;
338+ const successData : Array < OnyxUpdate < typeof ONYXKEYS . SUBSCRIPTION_VERIFY_SETUP_INTENT_PENDING > > = [
339+ {
340+ onyxMethod : Onyx . METHOD . MERGE ,
341+ key : ONYXKEYS . SUBSCRIPTION_VERIFY_SETUP_INTENT_PENDING ,
342+ value : false ,
343+ } ,
344+ ] ;
345+ const failureData : Array < OnyxUpdate < typeof ONYXKEYS . SUBSCRIPTION_VERIFY_SETUP_INTENT_PENDING > > = [
346+ {
347+ onyxMethod : Onyx . METHOD . MERGE ,
348+ key : ONYXKEYS . SUBSCRIPTION_VERIFY_SETUP_INTENT_PENDING ,
349+ value : false ,
350+ } ,
351+ ] ;
352+
353+ API . write ( WRITE_COMMANDS . VERIFY_SETUP_INTENT , { accountID, isVerifying} , { optimisticData, successData, failureData} ) ;
324354}
325355
326356/**
@@ -618,9 +648,9 @@ export {
618648 clearAddPaymentMethodError ,
619649 clearWalletError ,
620650 setPaymentMethodCurrency ,
621- clearPaymentCard3dsVerification ,
622651 clearWalletTermsError ,
623652 verifySetupIntent ,
624653 addPaymentCardSCA ,
654+ setVerify3dsSubscriptionSource ,
625655 setInvoicingTransferBankAccount ,
626656} ;
0 commit comments