Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libs/PaymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ const isSecondaryActionAPaymentOption = (item: PopoverMenuItem): item is Payment
*/
function getActivePaymentType(paymentMethod: string | undefined, activeAdminPolicies: Policy[], latestBankItems: BankAccountMenuItem[] | undefined, policyID?: string | undefined) {
const isPaymentMethod = Object.values(CONST.PAYMENT_METHODS).includes(paymentMethod as ValueOf<typeof CONST.PAYMENT_METHODS>);
const shouldSelectPaymentMethod = isPaymentMethod || !isEmpty(latestBankItems);
// payment method is equal to policyID when user selects "Pay via workspace" option
const selectedPolicy = activeAdminPolicies.find((activePolicy) => activePolicy.id === policyID || activePolicy.id === paymentMethod);

Expand All @@ -242,6 +241,9 @@ function getActivePaymentType(paymentMethod: string | undefined, activeAdminPoli
break;
}

// When user explicitly selects "Pay Elsewhere" / "Mark as Paid", don't require payment method selection since payment happens outside of Expensify
const shouldSelectPaymentMethod = paymentMethod !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE && (isPaymentMethod || !isEmpty(latestBankItems));

return {
paymentType,
selectedPolicy,
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/PaymentUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ describe('PaymentUtils', () => {
expect(result.shouldSelectPaymentMethod).toBe(true);
});

it('should set shouldSelectPaymentMethod to false when paymentMethod is explicitly ELSEWHERE (Mark as Paid)', () => {
const result = getActivePaymentType(CONST.IOU.PAYMENT_TYPE.ELSEWHERE, [], [bankItem]);

expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.ELSEWHERE);
expect(result.shouldSelectPaymentMethod).toBe(false);
});

it('should find selectedPolicy by policyID', () => {
const result = getActivePaymentType(undefined, [randomPolicyA, randomPolicyB], undefined, randomPolicyA.id);

Expand Down
Loading