Skip to content

Commit

Permalink
created addPaymentCardGBP function
Browse files Browse the repository at this point in the history
  • Loading branch information
waterim committed Sep 29, 2024
1 parent 2837a92 commit 612ab1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
27 changes: 18 additions & 9 deletions src/libs/actions/PaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 27 in src/libs/actions/PaymentMethods.ts

View workflow job for this annotation

GitHub Actions / ESLint check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 27 in src/libs/actions/PaymentMethods.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

All imports in the declaration are only used as types. Use `import type`
import type {FilterMethodPaymentType} from '@src/types/onyx/WalletTransfer';

type KYCWallRef = {
Expand Down Expand Up @@ -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, {
Expand All @@ -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
*/
Expand Down Expand Up @@ -555,4 +563,5 @@ export {
clearWalletTermsError,
setPaymentCardForm,
verifySetupIntent,
addPaymentCardGBP,
};
10 changes: 2 additions & 8 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 612ab1c

Please sign in to comment.