Skip to content

Commit bed8acb

Browse files
Merge pull request #20375 from mozilla/PAY-3587-pay-pal-do-not-restrict-payments-with-mismatched-currency-billing-countries
feat(payments-next): [PayPal] Do not restrict payments with mismatched currency + billing countries
2 parents 8d386b8 + f1711c7 commit bed8acb

4 files changed

Lines changed: 0 additions & 131 deletions

File tree

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@
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
import { Test } from '@nestjs/testing';
5-
import { faker } from '@faker-js/faker';
65

76
import { CurrencyManager } from './currency.manager';
8-
import {
9-
CurrencyCodeInvalidError,
10-
CountryCodeInvalidError,
11-
CurrencyCountryMismatchError,
12-
CurrencyCodeMissingError,
13-
CountryCodeMissingError,
14-
} from './currency.error';
157
import {
168
CurrencyConfig,
17-
MockCurrencyConfig,
189
MockCurrencyConfigProvider,
1910
} from './currency.config';
2011

@@ -31,65 +22,6 @@ describe('CurrencyManager', () => {
3122
mockCurrencyConfig = module.get(CurrencyConfig);
3223
});
3324

34-
describe('assertCurrencyCompatibleWithCountry', () => {
35-
const validCountry = faker.helpers.arrayElement(
36-
MockCurrencyConfig.currenciesToCountries.USD
37-
);
38-
const validCurrency = 'USD';
39-
40-
it('asserts when currency to country is valid', () => {
41-
currencyManager.assertCurrencyCompatibleWithCountry(
42-
validCurrency,
43-
validCountry
44-
);
45-
});
46-
47-
it('throws an error when currency is empty', () => {
48-
expect(() =>
49-
currencyManager.assertCurrencyCompatibleWithCountry('', validCountry)
50-
).toThrow(CurrencyCodeMissingError);
51-
});
52-
53-
it('throws an error when currency is invalid', () => {
54-
expect(() =>
55-
currencyManager.assertCurrencyCompatibleWithCountry('KPW', validCountry)
56-
).toThrow(CurrencyCodeInvalidError);
57-
});
58-
59-
it('throws an error when country is missing', () => {
60-
const countryCode = '';
61-
62-
expect(() =>
63-
currencyManager.assertCurrencyCompatibleWithCountry(
64-
validCurrency,
65-
countryCode
66-
)
67-
).toThrow(CountryCodeMissingError);
68-
});
69-
70-
it('throws an error when country is invalid', () => {
71-
const countryCode = faker.location.countryCode('alpha-3');
72-
73-
expect(() =>
74-
currencyManager.assertCurrencyCompatibleWithCountry(
75-
validCurrency,
76-
countryCode
77-
)
78-
).toThrow(CountryCodeInvalidError);
79-
});
80-
81-
it('throws an error when currency to country do not match', () => {
82-
const currencyCode = 'EUR';
83-
84-
expect(() =>
85-
currencyManager.assertCurrencyCompatibleWithCountry(
86-
currencyCode,
87-
validCountry
88-
)
89-
).toThrow(CurrencyCountryMismatchError);
90-
});
91-
});
92-
9325
describe('getTaxId', () => {
9426
it('returns the correct tax id for currency', async () => {
9527
const mockCurrency = Object.entries(mockCurrencyConfig.taxIds)[0];

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

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

55
import { Injectable } from '@nestjs/common';
6-
import {
7-
SUPPORTED_PAYPAL_CURRENCIES,
8-
VALID_COUNTRY_CODES,
9-
VALID_CURRENCY_CODES,
10-
} from './currency.constants';
11-
import {
12-
CurrencyCodeInvalidError,
13-
CountryCodeInvalidError,
14-
CurrencyCountryMismatchError,
15-
CurrencyCodeMissingError,
16-
CountryCodeMissingError,
17-
} from './currency.error';
186
import { CurrencyConfig } from './currency.config';
197

208
@Injectable()
@@ -24,42 +12,6 @@ export class CurrencyManager {
2412
this.taxIds = this.config.taxIds;
2513
}
2614

27-
/**
28-
* Verify that provided source country and plan currency are compatible with
29-
* valid currencies and countries as listed in constants
30-
*
31-
* @param currency Currency of customer
32-
* @param country Country of customer
33-
* @returns True if currency is compatible with country, else throws error
34-
*/
35-
assertCurrencyCompatibleWithCountry(currency: string, country: string): void {
36-
if (!currency) throw new CurrencyCodeMissingError();
37-
if (!country) throw new CountryCodeMissingError();
38-
39-
const currencyUpper = currency.toUpperCase();
40-
41-
if (
42-
!VALID_CURRENCY_CODES.includes(currencyUpper) ||
43-
!SUPPORTED_PAYPAL_CURRENCIES.includes(currencyUpper) ||
44-
!this.config.currenciesToCountries.hasOwnProperty(currencyUpper)
45-
) {
46-
throw new CurrencyCodeInvalidError(currencyUpper);
47-
}
48-
49-
if (!VALID_COUNTRY_CODES.includes(country)) {
50-
throw new CountryCodeInvalidError(country);
51-
}
52-
53-
if (
54-
currencyUpper in this.config.currenciesToCountries &&
55-
!this.config.currenciesToCountries[
56-
currencyUpper as keyof typeof this.config.currenciesToCountries
57-
].includes(country)
58-
) {
59-
throw new CurrencyCountryMismatchError(currencyUpper, country);
60-
}
61-
}
62-
6315
getTaxId(currency: string) {
6416
return this.taxIds[currency.toUpperCase()];
6517
}

libs/payments/management/src/lib/subscriptionManagement.service.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import {
5151
TrialSubscriptionContentFactory,
5252
} from '@fxa/payments/management';
5353
import {
54-
BillingAgreementFactory,
5554
MockPaypalClientConfigProvider,
5655
PaypalBillingAgreementManager,
5756
PayPalClient,
@@ -2242,7 +2241,6 @@ describe('SubscriptionManagementService', () => {
22422241
collection_method: 'send_invoice',
22432242
})
22442243
);
2245-
const mockBillingAgreement = BillingAgreementFactory();
22462244
const mockStripeCustomer = StripeResponseFactory(StripeCustomerFactory());
22472245

22482246
jest
@@ -2266,12 +2264,6 @@ describe('SubscriptionManagementService', () => {
22662264
jest
22672265
.spyOn(paypalBillingAgreementManager, 'create')
22682266
.mockResolvedValue(faker.string.uuid());
2269-
jest
2270-
.spyOn(paypalBillingAgreementManager, 'retrieve')
2271-
.mockResolvedValue(mockBillingAgreement);
2272-
jest
2273-
.spyOn(currencyManager, 'assertCurrencyCompatibleWithCountry')
2274-
.mockReturnValue();
22752267
jest
22762268
.spyOn(customerManager, 'update')
22772269
.mockResolvedValue(mockStripeCustomer);

libs/payments/management/src/lib/subscriptionManagement.service.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,13 +1228,6 @@ export class SubscriptionManagementService {
12281228
token
12291229
);
12301230

1231-
const billingAgreement =
1232-
await this.paypalBillingAgreementManager.retrieve(billingAgreementId);
1233-
this.currencyManager.assertCurrencyCompatibleWithCountry(
1234-
currency,
1235-
billingAgreement.countryCode
1236-
);
1237-
12381231
await this.customerManager.update(accountCustomer.stripeCustomerId, {
12391232
metadata: {
12401233
[STRIPE_CUSTOMER_METADATA.PaypalAgreement]: billingAgreementId,

0 commit comments

Comments
 (0)