Skip to content

Commit

Permalink
use policyID as a key for preferred payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
getusha committed Feb 23, 2025
1 parent 1e7607d commit 4edefdb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function KYCWall({
const {reportID} = moveIOUToExistingPolicy(policy, iouReport) ?? {};
if (reportID) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID));
savePreferredPaymentMethod(iouReport?.reportID ?? '', policy.id, 'Iou');
savePreferredPaymentMethod(iouReport?.policyID ?? '', policy.id, 'Iou');
}

Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policy.id));
Expand Down
5 changes: 2 additions & 3 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ function SettlementButton({
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});
const policyEmployeeAccountIDs = policyID ? getPolicyEmployeeAccountIDs(policyID) : [];
const reportBelongsToWorkspace = policyID ? doesReportBelongToWorkspace(chatReport, policyEmployeeAccountIDs, policyID) : false;
const policyIDKey = reportBelongsToWorkspace ? policyID : CONST.POLICY.ID_FAKE;
const lastPaymentMethodSelector = policyIDKey === CONST.POLICY.ID_FAKE && iouReport?.reportID ? iouReport?.reportID : policyIDKey;
const policyIDKey = reportBelongsToWorkspace ? policyID : iouReport?.policyID ?? CONST.POLICY.ID_FAKE;
const [lastPaymentMethod, lastPaymentMethodResult] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {
selector: (paymentMethod) => getLastPolicyPaymentMethod(lastPaymentMethodSelector, paymentMethod, iouReport?.type as keyof LastPaymentMethodType),
selector: (paymentMethod) => getLastPolicyPaymentMethod(policyIDKey, paymentMethod, iouReport?.type as keyof LastPaymentMethodType),
});

const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
Expand Down
12 changes: 9 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8850,7 +8850,7 @@ function completePaymentOnboarding(paymentSelected: ValueOf<typeof CONST.PAYMENT
true,
);
}
function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.Report, iouReport: OnyxEntry<OnyxTypes.Report>, full = true, usedPolicyID?: string) {
function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.Report, iouReport: OnyxEntry<OnyxTypes.Report>, full = true, paymentPolicyID?: string) {
if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
return;
Expand All @@ -8870,8 +8870,14 @@ function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.R
API.write(apiCommand, params, {optimisticData, successData, failureData});
notifyNewAction(Navigation.getTopmostReportId() ?? iouReport?.reportID, userAccountID);

if (usedPolicyID && iouReport?.reportID) {
savePreferredPaymentMethod(iouReport?.reportID, usedPolicyID, 'lastUsed');
// Save the payment method used for the report
// If the report is from a workspace, we use the policyID
// Otherwise, we use the policyID from the iouReport
// Otherwise, we use the paymentSelected
if (iouReport && iouReport?.policyID) {
const usedPaymentOption = paymentPolicyID ?? paymentSelected;
const reportType = iouReport?.type ?? 'lastUsed';
savePreferredPaymentMethod(iouReport?.policyID, usedPaymentOption, reportType as ValueOf<typeof CONST.LAST_PAYMENT_METHOD>);
}
}

Expand Down

0 comments on commit 4edefdb

Please sign in to comment.