diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index bac3739af810..198cb30494ca 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -24,6 +24,7 @@ import type {BankAccountList, FundList} from '@src/types/onyx'; import type {AccountData} from '@src/types/onyx/Fund'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type PaymentMethod from '@src/types/onyx/PaymentMethod'; +import {OnyxData} from '@src/types/onyx/Request'; import type {FilterMethodPaymentType} from '@src/types/onyx/WalletTransfer'; type KYCWallRef = { @@ -254,15 +255,7 @@ function addSubscriptionPaymentCard(cardData: { ]; if (currency === CONST.PAYMENT_CARD_CURRENCY.GBP) { - // eslint-disable-next-line rulesdir/no-api-side-effects-method - API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.ADD_PAYMENT_CARD_GBP, parameters, {optimisticData, successData, failureData}).then((response) => { - if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) { - return; - } - - // We are using this onyx key to open Modal and preview iframe. Potentially we can save the whole object which come from side effect - Onyx.set(ONYXKEYS.VERIFY_3DS_SUBSCRIPTION, (response as {authenticationLink: string}).authenticationLink); - }); + addPaymentCardGBP(parameters, {optimisticData, successData, failureData}); } else { // eslint-disable-next-line rulesdir/no-multiple-api-calls API.write(WRITE_COMMANDS.ADD_PAYMENT_CARD, parameters, { @@ -273,6 +266,21 @@ function addSubscriptionPaymentCard(cardData: { } } +/** + * Calls the API to add a new GBP card. + * Updates verify3dsSubscription Onyx key with a new authentication link for 3DS. + */ +function addPaymentCardGBP(params: AddPaymentCardParams, onyxData: OnyxData = {}) { + // eslint-disable-next-line rulesdir/no-api-side-effects-method + API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.ADD_PAYMENT_CARD_GBP, params, onyxData).then((response) => { + if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) { + return; + } + // We are using this onyx key to open Modal and preview iframe. Potentially we can save the whole object which come from side effect + Onyx.set(ONYXKEYS.VERIFY_3DS_SUBSCRIPTION, (response as {authenticationLink: string}).authenticationLink); + }); +} + /** * Resets the values for the add payment card form back to their initial states */ @@ -555,4 +563,5 @@ export { clearWalletTermsError, setPaymentCardForm, verifySetupIntent, + addPaymentCardGBP, }; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 8494e10fb660..32b1407aeb15 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -74,6 +74,7 @@ import * as ReportConnection from '@libs/ReportConnection'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import type {PolicySelector} from '@pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover'; +import * as PaymentMethods from '@userActions/PaymentMethods'; import * as PersistedRequests from '@userActions/PersistedRequests'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -849,14 +850,7 @@ function addBillingCardAndRequestPolicyOwnerChange( currency, isP2PDebitCard: false, }; - // eslint-disable-next-line rulesdir/no-api-side-effects-method - API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.ADD_PAYMENT_CARD_GBP, params).then((response) => { - if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) { - return; - } - // We are using this onyx key to open Modal and preview iframe. Potentially we can save the whole object which come from side effect - Onyx.set(ONYXKEYS.VERIFY_3DS_SUBSCRIPTION, (response as {authenticationLink: string}).authenticationLink); - }); + PaymentMethods.addPaymentCardGBP(params); } else { const params: AddBillingCardAndRequestWorkspaceOwnerChangeParams = { policyID,