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
@@ -0,0 +1,25 @@
## InterstitialOffer
interstitial-offer-button-cancel-subscription = Continue to cancel

## Daily/Weekly/Monthly refers to the user's current subscription interval
interstitial-offer-button-keep-current-interval-daily = Keep daily subscription
interstitial-offer-button-keep-current-interval-weekly = Keep weekly subscription
interstitial-offer-button-keep-current-interval-monthly = Keep monthly subscription
interstitial-offer-button-keep-current-interval-halfyearly = Keep six-month subscription


## Error page
interstitial-offer-error-subscription-not-found-heading = Subscription not found
interstitial-offer-error-subscription-not-found-message = We were unable to find your subscription. Please contact support if you need assistance.

interstitial-offer-error-configuration-heading = Unable to load offer
interstitial-offer-error-configuration-message = We encountered an issue loading this offer. Please try again or contact support.

interstitial-offer-error-no-offer-heading = No offers available
interstitial-offer-error-no-offer-message = There are currently no upgrade offers available for your subscription

interstitial-offer-error-not-eligible-heading = Not eligible for upgrade
interstitial-offer-error-not-eligible-message = Your subscription is not eligible for an upgrade offer at this time.

interstitial-offer-error-general-heading = Something went wrong
interstitial-offer-error-general-message = Something went wrong. Please try again or contact support.
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { notFound, redirect } from 'next/navigation';
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 { auth } from 'apps/payments/next/auth';
import { config } from 'apps/payments/next/config';

export default async function InterstitialOfferErrorPage({
params,
searchParams,
}: {
params: {
locale: string;
subscriptionId: string;
};
searchParams: Record<string, string> | undefined;
}) {
const { locale, subscriptionId } = params;
const acceptLanguage = headers().get('accept-language');

const session = await auth();
if (!session?.user?.id) {
const redirectToUrl = new URL(
`${config.paymentsNextHostedUrl}/${locale}/subscriptions/landing`
);
redirectToUrl.search = new URLSearchParams(searchParams).toString();
redirect(redirectToUrl.href);
}

const uid = session.user.id;

const interstitialOfferContent = await getInterstitialOfferContentAction(
uid,
subscriptionId,
acceptLanguage,
locale
);

if (!interstitialOfferContent) {
notFound();
}

if (interstitialOfferContent.isEligible && interstitialOfferContent.pageContent) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer`);
}

const { reason, webIcon, productName} = interstitialOfferContent;

if (!reason || !webIcon || !productName) {
notFound();
}

const l10n = getApp().getL10n(acceptLanguage, locale);

const getErrorContent = (reason: string) => {
switch (reason) {
case 'subscription_not_found':
return {
heading: l10n.getString(
'interstitial-offer-error-subscription-not-found-heading',
'Subscription not found'
),
message: l10n.getString(
'interstitial-offer-error-subscription-not-found-message',
'We were unable to find your subscription. Please contact support if you need assistance.'
),
};
case 'current_interval_not_found':
case 'stripe_price_id_not_found':
case 'offering_id_not_found':
return {
heading: l10n.getString(
'interstitial-offer-error-configuration-heading',
'Unable to load offer'
),
message: l10n.getString(
'interstitial-offer-error-configuration-message',
'We encountered an issue loading this offer. Please try again or contact support.'
),
};
case 'no_cancel_interstitial_offer_found':
case 'no_upgrade_plan_found':
return {
heading: l10n.getString(
'interstitial-offer-error-no-offer-heading',
'No offers available'
),
message: l10n.getString(
'interstitial-offer-error-no-offer-message',
'There are currently no upgrade offers available for your subscription.'
),
};
case 'not_eligible_for_upgrade_interval':
return {
heading: l10n.getString(
'interstitial-offer-error-not-eligible-heading',
'Not eligible for upgrade'
),
message: l10n.getString(
'interstitial-offer-error-not-eligible-message',
'Your subscription is not eligible for an upgrade offer at this time.'
),
};
case 'general_error':
default:
return {
heading: l10n.getString(
'interstitial-offer-error-general-heading',
'Something went wrong'
),
message: l10n.getString(
'interstitial-offer-error-general-message',
'Something went wrong. Please try again or contact support.'
),
};
}
};

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

return (
<section
className="flex justify-center min-h-[calc(100vh_-_4rem)] tablet:items-center tablet:min-h-[calc(100vh_-_5rem)]"
aria-labelledby="error-heading"
>
<div className="w-full max-w-[480px] flex flex-col justify-center items-center p-10 tablet:bg-white tablet:rounded-xl tablet:border tablet:border-grey-200 tablet:shadow-[0_0_16px_0_rgba(0,0,0,0.08)]">
<div className="w-full flex flex-col items-center gap-6 text-center">
{webIcon && (
<Image
src={webIcon}
alt={productName}
height={64}
width={64}
/>
)}
<h1
id="error-heading"
className="font-bold self-stretch text-center font-header text-xl leading-8"
>
{heading}
</h1>
<p className="w-full self-stretch leading-7 text-lg text-grey-900 text-center tablet:text-left">
{message}
</p>
</div>

<div className="w-full flex flex-col gap-3 mt-12">
<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`}
>
{l10n.getString(
'interstitial-offer-error-button-manage-subscriptions',
'Manage subscriptions'
)}
</Link>
</div>
</div>
</section>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
import { getApp } from '@fxa/payments/ui/server';
import { getInterstitialOfferContentAction } from '@fxa/payments/ui/actions';
import { auth } from 'apps/payments/next/auth';
import { config } from 'apps/payments/next/config';
import Image from 'next/image';
import Link from 'next/link';

export default async function InterstitialOfferPage({
params,
searchParams,
}: {
params: {
locale: string;
subscriptionId: string;
};
searchParams: Record<string, string> | undefined;
}) {
const { locale, subscriptionId } = params;
const acceptLanguage = headers().get('accept-language');
const l10n = getApp().getL10n(acceptLanguage, locale);

const session = await auth();
if (!session?.user?.id) {
const redirectToUrl = new URL(
`${config.paymentsNextHostedUrl}/${locale}/subscriptions/landing`
);
redirectToUrl.search = new URLSearchParams(searchParams).toString();
redirect(redirectToUrl.href);
}

const uid = session.user.id;

let interstitialOfferContent;
try {
interstitialOfferContent = await getInterstitialOfferContentAction(
uid,
subscriptionId,
acceptLanguage,
locale
);
} catch (error) {
redirect(`/${locale}/subscriptions/${subscriptionId}/cancel`);
Copy link
Contributor

Choose a reason for hiding this comment

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

/${locale}/subscriptions/${subscriptionId}/offer/error

}

if (!interstitialOfferContent.isEligible || !interstitialOfferContent.pageContent) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer/error`);
Copy link
Contributor

Choose a reason for hiding this comment

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

/${locale}/subscriptions/${subscriptionId}/offer/error

}

const {
currentInterval,
modalHeading1,
modalMessage,
upgradeButtonLabel,
upgradeButtonUrl,
webIcon,
productName,
} = interstitialOfferContent.pageContent;

const getKeepCurrentSubscriptionFtlIds = (interval: string) => {
switch (interval) {
case 'daily':
return {
ftlId: 'interstitial-offer-button-keep-current-interval-daily',
fallbackText: 'Keep daily subscription',
};
case 'weekly':
return {
ftlId: 'interstitial-offer-button-keep-current-interval-weekly',
fallbackText: 'Keep weekly subscription',
};
case 'halfyearly':
return {
ftlId: 'interstitial-offer-button-keep-current-interval-halfyearly',
fallbackText: 'Keep six-month subscription',
};
case 'monthly':
default:
return {
ftlId: 'interstitial-offer-button-keep-current-interval-monthly',
fallbackText: 'Keep monthly subscription',
};
}
};

const { ftlId, fallbackText } = getKeepCurrentSubscriptionFtlIds(currentInterval);
const keepCurrentSubscriptionButtonText = l10n.getString(ftlId, fallbackText);

return (
<section
className="flex justify-center min-h-[calc(100vh_-_4rem)] tablet:items-center tablet:min-h-[calc(100vh_-_5rem)]"
>
<div className="w-full max-w-[480px] flex flex-col justify-center items-center p-10 tablet:bg-white tablet:rounded-xl tablet:border tablet:border-grey-200 tablet:shadow-[0_0_16px_0_rgba(0,0,0,0.08)]">
<div className="w-full flex flex-col items-center gap-6 text-center">
<Image
src={webIcon}
alt={productName}
height={64}
width={64}
/>
<h1 className="font-bold self-stretch text-center font-header text-xl leading-8 ">
{modalHeading1}
</h1>
</div>
<p className="w-full self-stretch leading-7 text-lg text-grey-900">
{modalMessage &&
modalMessage.map((line, i) => (
<p className="my-2" key={i}>
{line}
</p>
))}
</p>

<div className="w-full flex flex-col gap-3 mt-12">
<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={upgradeButtonUrl}
>
{upgradeButtonLabel}
</Link>
<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/landing`}
>
<span>{keepCurrentSubscriptionButtonText}</span>
</Link>
<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-button-cancel-subscription',
'Continue to cancel'
)}</span>
</Link>
</div>
</div>
</section>
);
}
Loading
Loading