diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index a83314234ea9..7a770dcf0533 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -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)); diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 8f1f8546e245..9f3a3d249db4 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -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); diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index d5889f3304ce..f412fd2b721d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8850,7 +8850,7 @@ function completePaymentOnboarding(paymentSelected: ValueOf, full = true, usedPolicyID?: string) { +function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.Report, iouReport: OnyxEntry, full = true, paymentPolicyID?: string) { if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID)); return; @@ -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); } }