@@ -14,14 +14,13 @@ import {
1414 IsolatedSelectTaxLocation ,
1515 buildRedirectUrl ,
1616} from '@fxa/payments/ui' ;
17- import {
18- fetchCMSData ,
19- getProductAvailabilityForLocation ,
20- } from '@fxa/payments/ui/actions' ;
17+ import { fetchCMSData , validateLocationAction } from '@fxa/payments/ui/actions' ;
2118import { getApp , TermsAndPrivacy } from '@fxa/payments/ui/server' ;
2219import locationIcon from '@fxa/shared/assets/images/confirm-pairing.svg' ;
2320import type { PageContentOfferingTransformed } from '@fxa/shared/cms' ;
2421import { config } from 'apps/payments/next/config' ;
22+ import { auth } from 'apps/payments/next/auth' ;
23+ import { TaxChangeAllowedStatus } from '@fxa/payments/cart' ;
2524
2625export const dynamic = 'force-dynamic' ;
2726
@@ -35,26 +34,30 @@ export default async function Location({
3534 const acceptLanguage = headers ( ) . get ( 'accept-language' ) ;
3635 const l10n = getApp ( ) . getL10n ( acceptLanguage , params . locale ) ;
3736 const emitterService = getApp ( ) . getEmitterService ( ) ;
37+ const session = await auth ( ) ;
38+ const providedCountryCode = searchParams [ 'countryCode' ] ;
39+ const providedPostalCode = searchParams [ 'postalCode' ] ;
40+ const taxAddress =
41+ providedCountryCode && providedPostalCode
42+ ? {
43+ countryCode : providedCountryCode ,
44+ postalCode : providedPostalCode ,
45+ }
46+ : undefined ;
47+
48+ const fxaUid = session ?. user ?. id ;
3849
3950 let cms : PageContentOfferingTransformed | undefined ;
40- let locationStatus : LocationStatus | undefined ;
51+ let locationStatus : LocationStatus | TaxChangeAllowedStatus | undefined ;
52+ let customerCurrency : string | undefined ;
4153 try {
42- const cmsDataPromise = fetchCMSData (
43- params . offeringId ,
44- acceptLanguage ,
45- params . locale
46- ) ;
47- const locationPromise = await getProductAvailabilityForLocation (
48- params . offeringId ,
49- searchParams [ 'countryCode' ]
50- ) ;
51-
52- const [ cmsData , locationData ] = await Promise . all ( [
53- cmsDataPromise ,
54- locationPromise ,
54+ const [ cmsData , validateLocationResults ] = await Promise . all ( [
55+ fetchCMSData ( params . offeringId , acceptLanguage , params . locale ) ,
56+ validateLocationAction ( params . offeringId , taxAddress , fxaUid ) ,
5557 ] ) ;
5658 cms = cmsData ;
57- locationStatus = locationData . status ;
59+ locationStatus = validateLocationResults . status ;
60+ customerCurrency = validateLocationResults . currentCurrency ;
5861
5962 emitterService . emit ( 'locationView' , locationStatus ) ;
6063 } catch ( error ) {
@@ -105,14 +108,22 @@ export default async function Location({
105108 'Your current location is not supported according to our Terms of Service.'
106109 ) }
107110 </ Banner >
108- ) : locationStatus === LocationStatus . ProductNotAvailable ? (
111+ ) : locationStatus === LocationStatus . ProductNotAvailable ||
112+ locationStatus === TaxChangeAllowedStatus . CurrencyNotFound ? (
109113 < Banner variant = { BannerVariant . Error } showCloseButton = { true } >
110114 { l10n . getString (
111115 'select-tax-location-product-not-available' ,
112116 { productName : purchaseDetails . productName } ,
113117 `${ purchaseDetails . productName } is not available in this location.`
114118 ) }
115119 </ Banner >
120+ ) : locationStatus === TaxChangeAllowedStatus . CurrencyChange ? (
121+ < Banner variant = { BannerVariant . Error } showCloseButton = { true } >
122+ { l10n . getString (
123+ 'location-banner-currency-change' ,
124+ 'Currency change not supported. To continue, select a country that matches your current billing currency.'
125+ ) }
126+ </ Banner >
116127 ) : (
117128 < Banner variant = { BannerVariant . Info } showCloseButton = { true } >
118129 { l10n . getString (
@@ -127,12 +138,30 @@ export default async function Location({
127138 cmsCountries = { cms . countries }
128139 locale = { params . locale . substring ( 0 , 2 ) }
129140 productName = { purchaseDetails . productName }
141+ showNewTaxRateInfoMessage = { false }
130142 unsupportedLocations = {
131143 config . location . subscriptionsUnsupportedLocations
132144 }
145+ currentCurrency = { customerCurrency }
133146 saveAction = { async ( countryCode : string , postalCode : string ) => {
134147 'use server' ;
135148
149+ if ( fxaUid ) {
150+ // call server Action here to validate if tax location change is allowed
151+ const result = await validateLocationAction (
152+ params . offeringId ,
153+ { countryCode, postalCode } ,
154+ fxaUid
155+ ) ;
156+
157+ if ( ! result . isValid ) {
158+ return {
159+ ok : false ,
160+ error : result . status ,
161+ } ;
162+ }
163+ }
164+
136165 searchParams [ 'countryCode' ] = countryCode ;
137166 searchParams [ 'postalCode' ] = postalCode ;
138167 const redirectUrl = new URL (
0 commit comments