Skip to content

Commit 1e1ba4a

Browse files
Merge pull request #18849 from mozilla/FXA-11378
fix(payments-next): fix localization of prices.
2 parents c12c434 + 961b3db commit 1e1ba4a

14 files changed

Lines changed: 68 additions & 29 deletions

File tree

apps/payments/next/app/[locale]/[offeringId]/[interval]/checkout/[cartId]/layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export default async function CheckoutLayout({
8989
amount={cart.upcomingInvoicePreview.listAmount}
9090
currency={cart.upcomingInvoicePreview.currency}
9191
interval={cart.interval}
92+
locale={locale}
9293
/>
9394
}
9495
totalPrice={
@@ -97,8 +98,10 @@ export default async function CheckoutLayout({
9798
amount={cart.upcomingInvoicePreview.totalAmount}
9899
currency={cart.upcomingInvoicePreview.currency}
99100
interval={cart.interval}
101+
locale={locale}
100102
/>
101103
}
104+
locale={ locale }
102105
/>
103106
{cart.state === CartState.START && (
104107
<div

apps/payments/next/app/[locale]/[offeringId]/[interval]/checkout/[cartId]/success/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ export default async function CheckoutSuccess({
127127
<div className="flex items-center justify-between text-grey-400">
128128
{l10n.getLocalizedCurrencyString(
129129
cart.latestInvoicePreview?.totalAmount,
130-
cart.latestInvoicePreview?.currency
130+
cart.latestInvoicePreview?.currency,
131+
locale
131132
)}
132133
{cart.paymentInfo.type === 'external_paypal' ? (
133134
<Image src={getCardIcon('paypal')} alt="paypal" />

apps/payments/next/app/[locale]/[offeringId]/[interval]/upgrade/[cartId]/(mainLayout)/layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default async function UpgradeSuccessLayout({
6363
amount={cart.upcomingInvoicePreview.listAmount}
6464
currency={cart.upcomingInvoicePreview.currency}
6565
interval={cart.interval}
66+
locale={locale}
6667
/>
6768
}
6869
totalPrice={
@@ -71,8 +72,10 @@ export default async function UpgradeSuccessLayout({
7172
amount={cart.upcomingInvoicePreview.totalAmount}
7273
currency={cart.upcomingInvoicePreview.currency}
7374
interval={cart.interval}
75+
locale={locale}
7476
/>
7577
}
78+
locale={ locale }
7679
/>
7780
</section>
7881
<div className="bg-white rounded-b-lg shadow-sm shadow-grey-300 border-t-0 mb-6 pt-4 px-4 pb-14 rounded-t-lg text-grey-600 tablet:clip-shadow tablet:rounded-t-none desktop:px-12 desktop:pb-12">

apps/payments/next/app/[locale]/[offeringId]/[interval]/upgrade/[cartId]/(mainLayout)/success/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export default async function UpgradeSuccess({
123123
<div className="flex items-center justify-between text-grey-400">
124124
{l10n.getLocalizedCurrencyString(
125125
cart.latestInvoicePreview?.totalAmount,
126-
cart.latestInvoicePreview?.currency
126+
cart.latestInvoicePreview?.currency,
127+
locale
127128
)}
128129
{cart.paymentInfo.type === 'external_paypal' ? (
129130
<Image src={getCardIcon('paypal')} alt="paypal" />

apps/payments/next/app/[locale]/[offeringId]/[interval]/upgrade/[cartId]/(startLayout)/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default async function UpgradeLayout({
7373
fromPrice={cart.fromPrice}
7474
fromPurchaseDetails={currentPurchaseDetails}
7575
purchaseDetails={purchaseDetails}
76+
locale={locale}
7677
/>
7778
</section>
7879

apps/payments/next/app/page.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import Link from 'next/link';
6+
import { headers } from 'next/headers';
7+
import { determineLocale } from '@fxa/shared/l10n';
68

79
export default function Index() {
810
// TODO - Remove before launch -
911
// This was only added to aid in initial implementation
1012
// The Subscription Platform doesn't currently have a root page,
1113
// and instead redirects to the Subscription Management page.
1214
// This page will be fixed before launch by FXA-8304
15+
const acceptLanguage = headers().get('accept-language') || '';
16+
17+
const browserLocale = determineLocale(acceptLanguage);
18+
const locale = browserLocale.split('-')[0];
19+
1320
return (
1421
<>
1522
<main className="mt-16 min-h-[calc(100vh_-_4rem)]">
@@ -21,7 +28,7 @@ export default function Index() {
2128
<h2>VPN - Monthly</h2>
2229
<Link
2330
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
24-
href="/en/vpn/monthly/landing"
31+
href={`/${locale}/vpn/monthly/landing`}
2532
>
2633
Redirect
2734
</Link>
@@ -30,7 +37,7 @@ export default function Index() {
3037
<h2>VPN - Yearly</h2>
3138
<Link
3239
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
33-
href="/en/vpn/yearly/landing"
40+
href={`/${locale}/vpn/yearly/landing`}
3441
>
3542
Redirect
3643
</Link>
@@ -42,7 +49,7 @@ export default function Index() {
4249
<h2>123Done Pro - Monthly</h2>
4350
<Link
4451
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
45-
href="/en/123donepro/monthly/new"
52+
href={`/${locale}/123donepro/monthly/new`}
4653
>
4754
Redirect
4855
</Link>

apps/payments/next/tests/app/page.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import '@testing-library/jest-dom';
66
import { render, screen } from '@testing-library/react';
77
import Index from '../../app/page';
88

9+
jest.mock('next/headers', () => ({
10+
headers: () => ({
11+
get: (key: string) => {
12+
if (key === 'accept-language') return 'en-US,en;q=0.5';
13+
return null;
14+
},
15+
}),
16+
}))
17+
918
describe('Page', () => {
1019
it('renders Page as expected', async () => {
1120
render(Index());

libs/payments/ui/src/lib/client/components/PurchaseDetails/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ type PurchaseDetailsProps = {
2525
webIcon: string;
2626
};
2727
totalPrice: React.ReactNode;
28+
locale: string;
2829
};
2930

3031
export function PurchaseDetails(props: PurchaseDetailsProps) {
31-
const { invoice, priceInterval, purchaseDetails, totalPrice } = props;
32+
const { invoice, priceInterval, purchaseDetails, totalPrice, locale } = props;
3233
const { details, productName, subtitle, webIcon } = purchaseDetails;
3334
const {
3435
currency,
@@ -92,7 +93,7 @@ export function PurchaseDetails(props: PurchaseDetailsProps) {
9293
<Localized id="next-plan-details-list-price">
9394
<p>List Price</p>
9495
</Localized>
95-
<p>{getLocalizedCurrencyString(listAmount, currency)}</p>
96+
<p>{getLocalizedCurrencyString(listAmount, currency, locale)}</p>
9697
</li>
9798
)}
9899

@@ -101,7 +102,7 @@ export function PurchaseDetails(props: PurchaseDetailsProps) {
101102
<Localized id="next-coupon-promo-code">
102103
<p>Promo Code</p>
103104
</Localized>
104-
<p>{getLocalizedCurrencyString(-1 * discountAmount, currency)}</p>
105+
<p>{getLocalizedCurrencyString(-1 * discountAmount, currency, locale)}</p>
105106
</li>
106107
)}
107108

@@ -114,7 +115,8 @@ export function PurchaseDetails(props: PurchaseDetailsProps) {
114115
<p>
115116
{getLocalizedCurrencyString(
116117
exclusiveTaxRates[0].amount,
117-
currency
118+
currency,
119+
locale
118120
)}
119121
</p>
120122
</li>
@@ -132,7 +134,7 @@ export function PurchaseDetails(props: PurchaseDetailsProps) {
132134
<p>{taxRate.title}</p>
133135
</Localized>
134136
<p>
135-
{getLocalizedCurrencyString(taxRate.amount, currency)}
137+
{getLocalizedCurrencyString(taxRate.amount, currency, locale)}
136138
</p>
137139
</li>
138140
)

libs/payments/ui/src/lib/server/components/PriceInterval/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ type PriceIntervalProps = {
1010
amount: number;
1111
currency: string;
1212
interval: string;
13+
locale: string;
1314
};
1415

1516
export async function PriceInterval(props: PriceIntervalProps) {
16-
const { l10n, amount, currency, interval } = props;
17+
const { l10n, amount, currency, interval, locale } = props;
1718
return l10n.getString(
1819
`plan-price-interval-${interval}`,
1920
{
2021
amount: l10n.getLocalizedCurrency(amount, currency),
2122
},
22-
formatPlanPricing(amount, currency, interval)
23+
formatPlanPricing(amount, currency, interval, false, 0, locale)
2324
);
2425
}

libs/payments/ui/src/lib/server/components/UpgradePurchaseDetails/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type UpgradePurchaseDetailsProps = {
2727
productName: string;
2828
webIcon: string;
2929
};
30+
locale: string;
3031
};
3132

3233
export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
@@ -37,6 +38,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
3738
invoice,
3839
l10n,
3940
purchaseDetails,
41+
locale
4042
} = props;
4143
const { productName, subtitle, webIcon } = purchaseDetails;
4244
const {
@@ -77,6 +79,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
7779
amount={fromPrice.listAmount}
7880
currency={fromPrice.currency}
7981
interval={fromPrice.interval}
82+
locale={locale}
8083
/>
8184
{fromPurchaseDetails.subtitle && (
8285
<span>
@@ -112,6 +115,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
112115
amount={listAmount}
113116
currency={currency}
114117
interval={interval}
118+
locale={locale}
115119
/>
116120
{subtitle && (
117121
<span>
@@ -138,7 +142,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
138142
`${productName} (${formatPlanInterval(interval)})`
139143
)}
140144
</p>
141-
<p>{l10n.getLocalizedCurrencyString(listAmount, currency)}</p>
145+
<p>{l10n.getLocalizedCurrencyString(listAmount, currency, locale)}</p>
142146
</li>
143147
)}
144148

@@ -151,7 +155,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
151155
)}
152156
</p>
153157
<p>
154-
{l10n.getLocalizedCurrencyString(-1 * discountAmount, currency)}
158+
{l10n.getLocalizedCurrencyString(-1 * discountAmount, currency, locale)}
155159
</p>
156160
</li>
157161
)}
@@ -167,7 +171,8 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
167171
<p>
168172
{l10n.getLocalizedCurrencyString(
169173
exclusiveTaxRates[0].amount,
170-
currency
174+
currency,
175+
locale
171176
)}
172177
</p>
173178
</li>
@@ -183,7 +188,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
183188
>
184189
<p>{l10n.getString('tax', taxRate.title)}</p>
185190
<p>
186-
{l10n.getLocalizedCurrencyString(taxRate.amount, currency)}
191+
{l10n.getLocalizedCurrencyString(taxRate.amount, currency, locale)}
187192
</p>
188193
</li>
189194
)
@@ -205,6 +210,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
205210
amount={totalAmount}
206211
currency={currency}
207212
interval={interval}
213+
locale={locale}
208214
/>
209215
</p>
210216
</li>
@@ -224,7 +230,7 @@ export function UpgradePurchaseDetails(props: UpgradePurchaseDetailsProps) {
224230
className="overflow-hidden text-ellipsis whitespace-nowrap"
225231
data-testid="prorated-price"
226232
>
227-
{l10n.getLocalizedCurrencyString(oneTimeCharge, currency)}
233+
{l10n.getLocalizedCurrencyString(oneTimeCharge, currency, locale)}
228234
</p>
229235
</div>
230236
</>

0 commit comments

Comments
 (0)