Skip to content

Commit 20dc2f8

Browse files
committed
fix(payments-next): Use currency config
Because: * Currencies were defined both in a global/importable variable and in an environment config, causing inconsistent behavior This commit: * Removes the variable, and switches referencing code to the config Closes #PAY-3432
1 parent 80da652 commit 20dc2f8

File tree

6 files changed

+14
-22
lines changed

6 files changed

+14
-22
lines changed

apps/payments/api/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ FIRESTORE_CONFIG__PROJECT_ID=
3838

3939
# Currency Config
4040
CURRENCY_CONFIG__TAX_IDS={ "EUR": "EU1234", "CHF": "CH1234" }
41-
CURRENCY_CONFIG__CURRENCIES_TO_COUNTRIES={ "USD": ["US", "GB", "NZ", "MY", "SG", "CA", "AS", "GU", "MP", "PR", "VI"], "EUR": ["FR", "DE"] }
41+
CURRENCY_CONFIG__CURRENCIES_TO_COUNTRIES={"USD":["AS","CA","GB","GU","MP","MY","NZ","PR","SG","US","VI"],"EUR":["AT","BG","BE","CY","DE","EE","ES","FI","FR","GR","HR","HU","IE","IT","LT","LU","LV","MT","NL","PT","RO","SE","SI","SK"],"CHF":["CH"],"CZK":["CZ"],"DKK":["DK"],"PLN":["PL"]}
4242

4343
# StatsD Config
4444
STATS_D_CONFIG__SAMPLE_RATE=
@@ -53,6 +53,6 @@ STRIPE_EVENTS_CONFIG__FIRESTORE_STRIPE_EVENT_STORE_COLLECTION_NAME=stripeEvents
5353
# Glean Config
5454
GLEAN_CONFIG__ENABLED=false
5555
GLEAN_CONFIG__APPLICATION_ID=
56-
GLEAN_CONFIG__VERSION=0.0.0
56+
GLEAN_CONFIG__VERSION=0.0.0
5757
GLEAN_CONFIG__CHANNEL='development'
5858
GLEAN_CONFIG__LOGGER_APP_NAME='fxa-payments-next'

apps/payments/next/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ FIRESTORE_CONFIG__PROJECT_ID=
9090

9191
# Currency Config
9292
CURRENCY_CONFIG__TAX_IDS={ "EUR": "EU1234", "CHF": "CH1234" }
93-
CURRENCY_CONFIG__CURRENCIES_TO_COUNTRIES={ "USD": ["US", "GB", "NZ", "MY", "SG", "CA", "AS", "GU", "MP", "PR", "VI"], "EUR": ["FR", "DE"] }
93+
CURRENCY_CONFIG__CURRENCIES_TO_COUNTRIES={"USD":["AS","CA","GB","GU","MP","MY","NZ","PR","SG","US","VI"],"EUR":["AT","BG","BE","CY","DE","EE","ES","FI","FR","GR","HR","HU","IE","IT","LT","LU","LV","MT","NL","PT","RO","SE","SI","SK"],"CHF":["CH"],"CZK":["CZ"],"DKK":["DK"],"PLN":["PL"]}
9494

9595
# Churn Intervention Config
9696
CHURN_INTERVENTION_CONFIG__COLLECTION_NAME=churnInterventions

libs/payments/currency/src/lib/currency.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CurrencyConfig {
2424

2525
export const MockCurrencyConfig = {
2626
taxIds: { EUR: 'EU1234' },
27-
currenciesToCountries: { USD: ['US'] },
27+
currenciesToCountries: { USD: ['US'], EUR: ['FR', 'DE', 'NL'] },
2828
} satisfies CurrencyConfig;
2929

3030
export const MockCurrencyConfigProvider = {

libs/payments/currency/src/lib/currency.constants.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
/*
6-
* Mapping from ISO 4217 three-letter currency codes to list of ISO 3166-1 alpha-2
7-
* two-letter country codes: {"EUR": ["DE", "FR"], "USD": ["CA", "GB", "US" ]}
8-
* Requirement for only one currency per country. Tested at runtime. Must be uppercased.
9-
*/
10-
export const CURRENCIES_TO_COUNTRIES = {
11-
USD: ['US', 'GB', 'NZ', 'MY', 'SG', 'CA', 'AS', 'GU', 'MP', 'PR', 'VI'],
12-
EUR: ['FR', 'DE'],
13-
};
14-
155
/*
166
* PayPal has specific restrictions on how currencies are handled.
177
* The general documentation for the AMT field is here: https://developer.paypal.com/docs/nvp-soap-api/do-reference-transaction-nvp/#payment-details-fields

libs/payments/currency/src/lib/currency.manager.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import {
1212
CurrencyCodeMissingError,
1313
CountryCodeMissingError,
1414
} from './currency.error';
15-
import { CURRENCIES_TO_COUNTRIES } from './currency.constants';
16-
import { CurrencyConfig, MockCurrencyConfigProvider } from './currency.config';
15+
import {
16+
CurrencyConfig,
17+
MockCurrencyConfig,
18+
MockCurrencyConfigProvider,
19+
} from './currency.config';
1720

1821
describe('CurrencyManager', () => {
1922
let currencyManager: CurrencyManager;
@@ -30,7 +33,7 @@ describe('CurrencyManager', () => {
3033

3134
describe('assertCurrencyCompatibleWithCountry', () => {
3235
const validCountry = faker.helpers.arrayElement(
33-
CURRENCIES_TO_COUNTRIES.USD
36+
MockCurrencyConfig.currenciesToCountries.USD
3437
);
3538
const validCurrency = 'USD';
3639

libs/payments/currency/src/lib/currency.manager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import { Injectable } from '@nestjs/common';
66
import {
7-
CURRENCIES_TO_COUNTRIES,
87
SUPPORTED_PAYPAL_CURRENCIES,
98
VALID_COUNTRY_CODES,
109
VALID_CURRENCY_CODES,
@@ -42,7 +41,7 @@ export class CurrencyManager {
4241
if (
4342
!VALID_CURRENCY_CODES.includes(currencyUpper) ||
4443
!SUPPORTED_PAYPAL_CURRENCIES.includes(currencyUpper) ||
45-
!CURRENCIES_TO_COUNTRIES.hasOwnProperty(currencyUpper)
44+
!this.config.currenciesToCountries.hasOwnProperty(currencyUpper)
4645
) {
4746
throw new CurrencyCodeInvalidError(currencyUpper);
4847
}
@@ -52,9 +51,9 @@ export class CurrencyManager {
5251
}
5352

5453
if (
55-
currencyUpper in CURRENCIES_TO_COUNTRIES &&
56-
!CURRENCIES_TO_COUNTRIES[
57-
currencyUpper as keyof typeof CURRENCIES_TO_COUNTRIES
54+
currencyUpper in this.config.currenciesToCountries &&
55+
!this.config.currenciesToCountries[
56+
currencyUpper as keyof typeof this.config.currenciesToCountries
5857
].includes(country)
5958
) {
6059
throw new CurrencyCountryMismatchError(currencyUpper, country);

0 commit comments

Comments
 (0)