-
Notifications
You must be signed in to change notification settings - Fork 219
feat(payments-next): Cancellation flow: Create page - Interstitial Offer #19859
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
Open
elizabeth-ilina
wants to merge
1
commit into
main
Choose a base branch
from
PAY-3371-create-page-interstitial-offer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+556
−23
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/en.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
167 changes: 167 additions & 0 deletions
167
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/error/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
145 changes: 145 additions & 0 deletions
145
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`); | ||
| } | ||
|
|
||
| if (!interstitialOfferContent.isEligible || !interstitialOfferContent.pageContent) { | ||
| redirect(`/${locale}/subscriptions/${subscriptionId}/offer/error`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| 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> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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