Skip to content

Commit

Permalink
Merge pull request #56558 from Expensify/amy-retry-payment
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Feb 10, 2025
2 parents ac1418a + f770eb1 commit 92efe71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
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,
};

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

0 comments on commit 92efe71

Please sign in to comment.