Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Retry Payment button available for amount owed overdue state #56558

Merged
merged 5 commits into from
Feb 10, 2025
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
31 changes: 16 additions & 15 deletions src/pages/settings/Subscription/CardSection/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import DateUtils from '@libs/DateUtils';
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
import {getAmountOwed, getOverdueGracePeriodDate, getSubscriptionStatus, PAYMENT_STATUS} from '@libs/SubscriptionUtils';
import CONST from '@src/CONST';
import type {AccountData} from '@src/types/onyx/Fund';
import type IconAsset from '@src/types/utils/IconAsset';
Expand All @@ -22,97 +22,98 @@ type BillingStatusResult = {
function getBillingStatus(translate: LocaleContextProps['translate'], accountData?: AccountData): BillingStatusResult | undefined {
const cardEnding = (accountData?.cardNumber ?? '')?.slice(-4);

const amountOwed = SubscriptionUtils.getAmountOwed();
const amountOwed = getAmountOwed();

const subscriptionStatus = SubscriptionUtils.getSubscriptionStatus();
const subscriptionStatus = getSubscriptionStatus();

const endDate = SubscriptionUtils.getOverdueGracePeriodDate();
const endDate = getOverdueGracePeriodDate();

const endDateFormatted = endDate ? DateUtils.formatWithUTCTimeZone(fromUnixTime(endDate).toUTCString(), CONST.DATE.MONTH_DAY_YEAR_FORMAT) : null;

const isCurrentCardExpired = DateUtils.isCardExpired(accountData?.cardMonth ?? 0, accountData?.cardYear ?? 0);

switch (subscriptionStatus?.status) {
case SubscriptionUtils.PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED:
case PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED:
return {
title: translate('subscription.billingBanner.policyOwnerAmountOwed.title'),
subtitle: translate('subscription.billingBanner.policyOwnerAmountOwed.subtitle', {date: endDateFormatted ?? ''}),
isError: true,
isRetryAvailable: true,
};

case SubscriptionUtils.PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE:
case PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE:
return {
title: translate('subscription.billingBanner.policyOwnerAmountOwedOverdue.title'),
subtitle: translate('subscription.billingBanner.policyOwnerAmountOwedOverdue.subtitle'),
isError: true,
isRetryAvailable: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is the only substantive change, the rest is lint fixes/fix for the corresponding test

};

case SubscriptionUtils.PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING:
case PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING:
return {
title: translate('subscription.billingBanner.policyOwnerUnderInvoicing.title'),
subtitle: translate('subscription.billingBanner.policyOwnerUnderInvoicing.subtitle', {date: endDateFormatted ?? ''}),
isError: true,
isAddButtonDark: true,
};

case SubscriptionUtils.PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE:
case PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE:
return {
title: translate('subscription.billingBanner.policyOwnerUnderInvoicingOverdue.title'),
subtitle: translate('subscription.billingBanner.policyOwnerUnderInvoicingOverdue.subtitle'),
isError: true,
isAddButtonDark: true,
};

case SubscriptionUtils.PAYMENT_STATUS.BILLING_DISPUTE_PENDING:
case PAYMENT_STATUS.BILLING_DISPUTE_PENDING:
return {
title: translate('subscription.billingBanner.billingDisputePending.title'),
subtitle: translate('subscription.billingBanner.billingDisputePending.subtitle', {amountOwed, cardEnding}),
isError: true,
isRetryAvailable: false,
};

case SubscriptionUtils.PAYMENT_STATUS.CARD_AUTHENTICATION_REQUIRED:
case PAYMENT_STATUS.CARD_AUTHENTICATION_REQUIRED:
return {
title: translate('subscription.billingBanner.cardAuthenticationRequired.title'),
subtitle: translate('subscription.billingBanner.cardAuthenticationRequired.subtitle', {cardEnding}),
isError: true,
isAuthenticationRequired: true,
};

case SubscriptionUtils.PAYMENT_STATUS.INSUFFICIENT_FUNDS:
case PAYMENT_STATUS.INSUFFICIENT_FUNDS:
return {
title: translate('subscription.billingBanner.insufficientFunds.title'),
subtitle: translate('subscription.billingBanner.insufficientFunds.subtitle', {amountOwed}),
isError: true,
isRetryAvailable: true,
};

case SubscriptionUtils.PAYMENT_STATUS.CARD_EXPIRED:
case PAYMENT_STATUS.CARD_EXPIRED:
return {
title: translate('subscription.billingBanner.cardExpired.title'),
subtitle: translate('subscription.billingBanner.cardExpired.subtitle', {amountOwed}),
isError: true,
isRetryAvailable: !isCurrentCardExpired,
};

case SubscriptionUtils.PAYMENT_STATUS.CARD_EXPIRE_SOON:
case PAYMENT_STATUS.CARD_EXPIRE_SOON:
return {
title: translate('subscription.billingBanner.cardExpireSoon.title'),
subtitle: translate('subscription.billingBanner.cardExpireSoon.subtitle'),
isError: false,
icon: Illustrations.CreditCardEyes,
};

case SubscriptionUtils.PAYMENT_STATUS.RETRY_BILLING_SUCCESS:
case PAYMENT_STATUS.RETRY_BILLING_SUCCESS:
return {
title: translate('subscription.billingBanner.retryBillingSuccess.title'),
subtitle: translate('subscription.billingBanner.retryBillingSuccess.subtitle'),
isError: false,
rightIcon: Expensicons.Close,
};

case SubscriptionUtils.PAYMENT_STATUS.RETRY_BILLING_ERROR:
case PAYMENT_STATUS.RETRY_BILLING_ERROR:
return {
title: translate('subscription.billingBanner.retryBillingError.title'),
subtitle: translate('subscription.billingBanner.retryBillingError.subtitle'),
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/CardsSectionUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
// eslint-disable-next-line no-restricted-syntax
import type * as SubscriptionUtils from '@libs/SubscriptionUtils';
import {PAYMENT_STATUS} from '@libs/SubscriptionUtils';
import type {TranslationParameters, TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -108,6 +109,7 @@ describe('CardSectionUtils', () => {
title: 'subscription.billingBanner.policyOwnerAmountOwedOverdue.title',
subtitle: 'subscription.billingBanner.policyOwnerAmountOwedOverdue.subtitle',
isError: true,
isRetryAvailable: true,
});
});

Expand Down
Loading