Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ export default async function LoyaltyDiscountCancelErrorPage({

const uid = session.user.id;

const pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
notFound();
}

if (!pageContent) {
notFound();
Expand All @@ -59,13 +64,10 @@ export default async function LoyaltyDiscountCancelErrorPage({
}

const { cmsOfferingContent, reason } = churnCancelContentEligibility;
if (!cmsOfferingContent) {
notFound();
}

const cancelContent = pageContent.cancelContent;

if (cancelContent.flowType !== 'cancel') {
if (cancelContent.flowType !== 'cancel' || !cmsOfferingContent) {
return (
<ChurnError
cmsOfferingContent={cmsOfferingContent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ export default async function LoyaltyDiscountCancelPage({

const uid = session.user.id;

const pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
redirect(
`/${locale}/subscriptions/${subscriptionId}/loyalty-discount/cancel/error`
);
}

if (!pageContent) notFound();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ export default async function LoyaltyDiscountStaySubscribedErrorPage({

const uid = session.user.id;

const pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
notFound();
}

if (!pageContent) {
notFound();
Expand All @@ -55,9 +60,6 @@ export default async function LoyaltyDiscountStaySubscribedErrorPage({
}

const { cmsOfferingContent, reason } = churnStaySubscribedEligibility;
if (!cmsOfferingContent) {
notFound();
}

return (
<ChurnError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ export default async function LoyaltyDiscountStaySubscribedPage({

const uid = session.user.id;

const pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
redirect(
`/${locale}/subscriptions/${subscriptionId}/loyalty-discount/stay-subscribed/error`
);
}

if (!pageContent) notFound();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
interstitial-offer-error-subscription-not-found-heading = We couldn’t find an active subscription
interstitial-offer-error-subscription-not-found-message = It looks like this subscription may no longer be active.

interstitial-offer-error-customer-mismatch-heading = Coupon can’t be redeemed
interstitial-offer-error-customer-mismatch-message = This coupon was issued for a different subscription and can only be redeemed by the original recipient.

interstitial-offer-error-general-heading = Offer isn’t available
interstitial-offer-error-general-message = It looks like this offer is not available at this time.

interstitial-offer-error-button-back-to-subscriptions = Back to subscriptions
interstitial-offer-error-button-cancel-subscription = Continue to cancel
interstitial-offer-error-button-sign-in = Sign in
interstitial-offer-error-button-contact-support = Contact Support
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Link from 'next/link';
import Image from 'next/image';
import { getApp } from '@fxa/payments/ui/server';
import { getInterstitialOfferContentAction } from '@fxa/payments/ui/actions';
import { LinkExternal } from '@fxa/shared/react';
import { auth } from 'apps/payments/next/auth';
import { config } from 'apps/payments/next/config';

Expand Down Expand Up @@ -63,7 +64,7 @@ export default async function InterstitialOfferErrorPage({
const reason = interstitialOfferContent.reason ?? 'general_error';

if (webIcon && !productName) {
throw new Error('Missing productName for interstitial offer icon');
console.error('Missing productName for interstitial offer icon');
}

const l10n = getApp().getL10n(acceptLanguage, locale);
Expand All @@ -81,7 +82,40 @@ export default async function InterstitialOfferErrorPage({
'interstitial-offer-error-subscription-not-found-message',
'It looks like this subscription may no longer be active.'
),
showContinueToCancelButton: false,
primaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
),
href: `/${locale}/subscriptions/landing`,
},
secondaryButton: null,
};
case 'customer_mismatch':
return {
heading: l10n.getString(
'interstitial-offer-error-customer-mismatch-heading',
'Coupon can’t be redeemed'
),
message: l10n.getString(
'interstitial-offer-error-customer-mismatch-message',
'This coupon was issued for a different subscription and can only be redeemed by the original recipient.'
),
primaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-sign-in',
'Sign in'
),
href: `/${locale}/subscriptions/landing`,
},
secondaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-contact-support',
'Contact Support'
),
href: 'https://support.mozilla.org/',
isExternal: true,
},
};
default:
return {
Expand All @@ -93,12 +127,26 @@ export default async function InterstitialOfferErrorPage({
'interstitial-offer-error-general-message',
'It looks like this offer is not available at this time.'
),
showContinueToCancelButton: true,
primaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
),
href: `/${locale}/subscriptions/landing`,
},
secondaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-cancel-subscription',
'Continue to cancel'
),
href: `/${locale}/subscriptions/${subscriptionId}/cancel`,
isExternal: false,
},
};
}
};

const { heading, message, showContinueToCancelButton } = getErrorContent(reason);
const { heading, message, primaryButton, secondaryButton } = getErrorContent(reason);

return (
<section
Expand Down Expand Up @@ -128,23 +176,26 @@ export default async function InterstitialOfferErrorPage({
<div className="w-full flex flex-col gap-3 mt-10">
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-white text-center font-bold py-4 px-6 bg-blue-500 hover:bg-blue-700 flex w-full"
href={`/${locale}/subscriptions/landing`}
href={primaryButton.href}
>
{l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
)}
{primaryButton.label}
</Link>
{showContinueToCancelButton && (
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-center font-bold py-4 px-6 bg-grey-10 border-grey-200 hover:bg-grey-50 flex w-full"
href={`/${locale}/subscriptions/${subscriptionId}/cancel`}
>
<span>{l10n.getString(
'interstitial-offer-error-button-cancel-subscription',
'Continue to cancel'
)}</span>
</Link>
{secondaryButton && (
secondaryButton.isExternal ? (
<LinkExternal
className="border box-border font-header h-14 items-center justify-center rounded-md text-center font-bold py-4 px-6 bg-grey-10 border-grey-200 hover:bg-grey-50 flex w-full"
href={secondaryButton.href}
>
{secondaryButton.label}
</LinkExternal>
) : (
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-center font-bold py-4 px-6 bg-grey-10 border-grey-200 hover:bg-grey-50 flex w-full"
href={secondaryButton.href}
>
<span>{secondaryButton.label}</span>
</Link>
)
)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
NotifierSnsProvider,
} from '@fxa/shared/notifier';
import { ChurnInterventionService } from './churn-intervention.service';
import { ChurnSubscriptionCustomerMismatchError } from './churn-intervention.error';

describe('ChurnInterventionService', () => {
let accountCustomerManager: AccountCustomerManager;
Expand Down Expand Up @@ -180,6 +179,43 @@ describe('ChurnInterventionService', () => {
jest.resetAllMocks();
});

it('returns ineligible when customer does not match subscription', async () => {
const mockStripeCustomer = StripeCustomerFactory();
const mockAccountCustomer = ResultAccountCustomerFactory({
stripeCustomerId: mockStripeCustomer.id,
});
const mockSubscription = StripeResponseFactory(
StripeSubscriptionFactory()
);

jest
.spyOn(accountCustomerManager, 'getAccountCustomerByUid')
.mockResolvedValue(mockAccountCustomer);
jest
.spyOn(subscriptionManager, 'retrieve')
.mockResolvedValue(mockSubscription);

const result =
await churnInterventionService.determineStaySubscribedEligibility(
uid,
subscriptionId
);

expect(result).toEqual({
isEligible: false,
reason: 'customer_mismatch',
cmsChurnInterventionEntry: null,
cmsOfferingContent: null,
});
expect(mockStatsD.increment).toHaveBeenCalledWith(
'stay_subscribed_eligibility',
{
eligibility: 'ineligible',
reason: 'customer_mismatch',
}
);
});

it('returns ineligible when no churn intervention entries are found', async () => {
const rawResult = ChurnInterventionByProductIdRawResultFactory();
const util = new ChurnInterventionByProductIdResultUtil(rawResult);
Expand Down Expand Up @@ -1047,7 +1083,7 @@ describe('ChurnInterventionService', () => {
});

describe('determineCancelInterstitialOfferEligibility', () => {
it('throws if customer does not match', async () => {
it('returns ineligible when customer does not match', async () => {
const mockUid = faker.string.uuid();
const mockStripeCustomer = StripeCustomerFactory();
const mockSubscription = StripeResponseFactory(
Expand All @@ -1065,13 +1101,19 @@ describe('ChurnInterventionService', () => {
.spyOn(subscriptionManager, 'retrieve')
.mockResolvedValue(StripeResponseFactory(mockSubscription));

expect(mockStatsD.increment).not.toHaveBeenCalled();
await expect(
churnInterventionService.determineCancelInterstitialOfferEligibility({
const result =
await churnInterventionService.determineCancelInterstitialOfferEligibility({
uid: mockUid,
subscriptionId: mockSubscription.id,
})
).rejects.toBeInstanceOf(ChurnSubscriptionCustomerMismatchError);
});

expect(result).toEqual({
isEligible: false,
reason: 'customer_mismatch',
cmsCancelInterstitialOfferResult: null,
webIcon: null,
productName: null,
});
});

it('returns not eligible if subscription not active', async () => {
Expand Down Expand Up @@ -1776,7 +1818,7 @@ describe('ChurnInterventionService', () => {
});

describe('determineCancelChurnContentEligibility', () => {
it('throws if customer does not match', async () => {
it('returns ineligible when customer does not match', async () => {
const mockUid = faker.string.uuid();
const mockStripeCustomer = StripeCustomerFactory();
const mockSubscription = StripeResponseFactory(
Expand All @@ -1794,14 +1836,18 @@ describe('ChurnInterventionService', () => {
.spyOn(subscriptionManager, 'retrieve')
.mockResolvedValue(StripeResponseFactory(mockSubscription));

await expect(
churnInterventionService.determineCancelChurnContentEligibility({
const result =
await churnInterventionService.determineCancelChurnContentEligibility({
uid: mockUid,
subscriptionId: mockSubscription.id,
})
).rejects.toBeInstanceOf(ChurnSubscriptionCustomerMismatchError);
});

expect(mockStatsD.increment).not.toHaveBeenCalled();
expect(result).toEqual({
isEligible: false,
reason: 'customer_mismatch',
cmsChurnInterventionEntry: null,
cmsOfferingContent: null,
});
});

it('returns not eligible if subscription not active', async () => {
Expand Down
Loading