Skip to content
Merged
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
4 changes: 2 additions & 2 deletions apps/payments/api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FIRESTORE_CONFIG__PROJECT_ID=

# Currency Config
CURRENCY_CONFIG__TAX_IDS={ "EUR": "EU1234", "CHF": "CH1234" }
CURRENCY_CONFIG__CURRENCIES_TO_COUNTRIES={ "USD": ["US", "GB", "NZ", "MY", "SG", "CA", "AS", "GU", "MP", "PR", "VI"], "EUR": ["FR", "DE"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

env config changed to match prod values

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"]}

# StatsD Config
STATS_D_CONFIG__SAMPLE_RATE=
Expand All @@ -53,6 +53,6 @@ STRIPE_EVENTS_CONFIG__FIRESTORE_STRIPE_EVENT_STORE_COLLECTION_NAME=stripeEvents
# Glean Config
GLEAN_CONFIG__ENABLED=false
GLEAN_CONFIG__APPLICATION_ID=
GLEAN_CONFIG__VERSION=0.0.0
GLEAN_CONFIG__VERSION=0.0.0
GLEAN_CONFIG__CHANNEL='development'
GLEAN_CONFIG__LOGGER_APP_NAME='fxa-payments-next'
2 changes: 1 addition & 1 deletion apps/payments/next/.env
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ FIRESTORE_CONFIG__PROJECT_ID=

# Currency Config
CURRENCY_CONFIG__TAX_IDS={ "EUR": "EU1234", "CHF": "CH1234" }
CURRENCY_CONFIG__CURRENCIES_TO_COUNTRIES={ "USD": ["US", "GB", "NZ", "MY", "SG", "CA", "AS", "GU", "MP", "PR", "VI"], "EUR": ["FR", "DE"] }
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"]}

# Churn Intervention Config
CHURN_INTERVENTION_CONFIG__COLLECTION_NAME=churnInterventions
Expand Down
2 changes: 1 addition & 1 deletion libs/payments/currency/src/lib/currency.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CurrencyConfig {

export const MockCurrencyConfig = {
taxIds: { EUR: 'EU1234' },
currenciesToCountries: { USD: ['US'] },
currenciesToCountries: { USD: ['US'], EUR: ['FR', 'DE', 'NL'] },
} satisfies CurrencyConfig;

export const MockCurrencyConfigProvider = {
Expand Down
10 changes: 0 additions & 10 deletions libs/payments/currency/src/lib/currency.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
* 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/. */

/*
* Mapping from ISO 4217 three-letter currency codes to list of ISO 3166-1 alpha-2
* two-letter country codes: {"EUR": ["DE", "FR"], "USD": ["CA", "GB", "US" ]}
* Requirement for only one currency per country. Tested at runtime. Must be uppercased.
*/
export const CURRENCIES_TO_COUNTRIES = {
USD: ['US', 'GB', 'NZ', 'MY', 'SG', 'CA', 'AS', 'GU', 'MP', 'PR', 'VI'],
EUR: ['FR', 'DE'],
};

/*
* PayPal has specific restrictions on how currencies are handled.
* The general documentation for the AMT field is here: https://developer.paypal.com/docs/nvp-soap-api/do-reference-transaction-nvp/#payment-details-fields
Expand Down
9 changes: 6 additions & 3 deletions libs/payments/currency/src/lib/currency.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import {
CurrencyCodeMissingError,
CountryCodeMissingError,
} from './currency.error';
import { CURRENCIES_TO_COUNTRIES } from './currency.constants';
import { CurrencyConfig, MockCurrencyConfigProvider } from './currency.config';
import {
CurrencyConfig,
MockCurrencyConfig,
MockCurrencyConfigProvider,
} from './currency.config';

describe('CurrencyManager', () => {
let currencyManager: CurrencyManager;
Expand All @@ -30,7 +33,7 @@ describe('CurrencyManager', () => {

describe('assertCurrencyCompatibleWithCountry', () => {
const validCountry = faker.helpers.arrayElement(
CURRENCIES_TO_COUNTRIES.USD
MockCurrencyConfig.currenciesToCountries.USD
);
const validCurrency = 'USD';

Expand Down
9 changes: 4 additions & 5 deletions libs/payments/currency/src/lib/currency.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import { Injectable } from '@nestjs/common';
import {
CURRENCIES_TO_COUNTRIES,
SUPPORTED_PAYPAL_CURRENCIES,
VALID_COUNTRY_CODES,
VALID_CURRENCY_CODES,
Expand Down Expand Up @@ -42,7 +41,7 @@ export class CurrencyManager {
if (
!VALID_CURRENCY_CODES.includes(currencyUpper) ||
!SUPPORTED_PAYPAL_CURRENCIES.includes(currencyUpper) ||
!CURRENCIES_TO_COUNTRIES.hasOwnProperty(currencyUpper)
!this.config.currenciesToCountries.hasOwnProperty(currencyUpper)
) {
throw new CurrencyCodeInvalidError(currencyUpper);
}
Expand All @@ -52,9 +51,9 @@ export class CurrencyManager {
}

if (
currencyUpper in CURRENCIES_TO_COUNTRIES &&
!CURRENCIES_TO_COUNTRIES[
currencyUpper as keyof typeof CURRENCIES_TO_COUNTRIES
currencyUpper in this.config.currenciesToCountries &&
!this.config.currenciesToCountries[
currencyUpper as keyof typeof this.config.currenciesToCountries
].includes(country)
) {
throw new CurrencyCountryMismatchError(currencyUpper, country);
Expand Down