Skip to content

Commit f5059c1

Browse files
authored
Merge pull request #14467 from mozilla/train-245-uplift-1
Train 245 uplift 1
2 parents 747aad5 + 27e4e13 commit f5059c1

File tree

66 files changed

+683
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+683
-608
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
# Secrets
1010
.env
11+
.env.local
12+
.env.development.local
13+
.env.test.local
14+
.env.production.local
1115
.keys
1216
public-key.json
1317
secret-key.json
@@ -39,6 +43,8 @@ tailwind.out.*
3943
# Dependencies
4044
**/node_modules
4145
**/browser_modules
46+
/.pnp
47+
.pnp.js
4248

4349
# Logging
4450
*.log*
@@ -117,6 +123,8 @@ packages/fxa-customs-server/test/mocks/temp.netset
117123

118124
# fxa-payments-server
119125
packages/fxa-payments-server/fxa-content-server-l10n/
126+
packages/fxa-payments-server/public/locales
127+
packages/fxa-payments-server/test
120128

121129
# fxa-profile-server
122130
packages/fxa-profile-server/var

_scripts/clone-l10n.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ AUTH="fxa-auth-server"
135135
# Copy .ftl files for payments, settings, and auth (emails)
136136
case "$MODULE" in
137137
"$PAYMENTS")
138-
copy_ftl "main"
138+
copy_ftl "payments"
139139
;;
140140
"$SETTINGS")
141141
copy_ftl "settings"

packages/fxa-auth-server/lib/payments/paypal/client.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,15 @@ export class PayPalClientError extends Error {
260260
constructor(raw: string, data: NVPResponse, ...params: any) {
261261
super(...params);
262262
this.name = 'PayPalClientError';
263-
this.errorCode = data.L?.length ? parseInt(data.L[0].ERRORCODE) : undefined;
263+
let errors: NVPResponse['L'] = [];
264+
// We can get severity "Error" or "Warning" so filter for "Error" as a priority.
265+
if (data.L?.length) {
266+
errors = data.L.filter((error) => error.SEVERITYCODE === 'Error');
267+
if (errors.length === 0) {
268+
errors = [data.L[0]];
269+
}
270+
}
271+
this.errorCode = errors?.length ? parseInt(errors[0].ERRORCODE) : undefined;
264272
if (!this.message) {
265273
this.message = `PayPal NVP returned a non-success ACK. See "this.raw" or "this.data" for more details. PayPal error code: ${this.errorCode}`;
266274
}

packages/fxa-auth-server/test/local/payments/paypal-client.js

+42
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,46 @@ describe('PayPalClient', () => {
480480
assert.equal(response, searchTransactionResponse);
481481
});
482482
});
483+
484+
describe('PaypalClientError', () => {
485+
const raw = 'blah';
486+
const data = {
487+
L: [
488+
{
489+
ERRORCODE: 10413,
490+
LONGMESSAGE:
491+
'The totals of the cart item amounts do not match order amounts.',
492+
SEVERITYCODE: 'Warning',
493+
SHORTMESSAGE:
494+
'Transaction refused because of an invalid argument. See additional error messages for details.',
495+
},
496+
{
497+
ERRORCODE: 10417,
498+
LONGMESSAGE:
499+
'Instruct the customer to retry the transaction using an alternative payment method from the customers PayPal wallet. The transaction did not complete with the customers selected payment method.',
500+
SEVERITYCODE: 'Error',
501+
SHORTMESSAGE: 'Transaction cannot complete.',
502+
},
503+
],
504+
};
505+
506+
it('handles multiple errors when one error is a warning', () => {
507+
const paypalClientError = new PayPalClientError(raw, data);
508+
assert.deepEqual(paypalClientError.errorCode, 10417);
509+
});
510+
511+
it('falls back to the first error if multiple errors are found', () => {
512+
const dataTwoErrors = deepCopy(data);
513+
dataTwoErrors.L[0].SEVERITYCODE = 'Error';
514+
const paypalClientError = new PayPalClientError(raw, dataTwoErrors);
515+
assert.deepEqual(paypalClientError.errorCode, 10413);
516+
});
517+
518+
it('takes the first response code if no errors are returned', () => {
519+
const dataNoErrors = deepCopy(data);
520+
dataNoErrors.L = [dataNoErrors.L.shift()];
521+
const paypalClientError = new PayPalClientError(raw, dataNoErrors);
522+
assert.deepEqual(paypalClientError.errorCode, 10413);
523+
});
524+
});
483525
});

packages/fxa-payments-server/.gitignore

-9
This file was deleted.

packages/fxa-payments-server/.storybook/components/MockApp.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const MockApp = ({
9595
<AppLocalizationProvider
9696
baseDir="./locales"
9797
userLocales={languages}
98-
bundles={['main']}
98+
bundles={['payments']}
9999
>
100100
<StripeProvider stripe={mockStripe}>
101101
<MockLoader>
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
'use strict';
6+
7+
module.exports = function (grunt) {
8+
grunt.initConfig({
9+
pkg: grunt.file.readJSON('package.json'),
10+
concat: {
11+
ftl: {
12+
src: [
13+
// 'src/branding.ftl' is temporary
14+
// and will be replaced with '../fxa-shared/lib/l10n/branding.ftl'
15+
// in a later ticket - will require coordination with l10n to resolve
16+
// conflicting IDs for identical terms.
17+
'src/branding.ftl',
18+
'src/**/*.ftl',
19+
],
20+
dest: 'public/locales/en/payments.ftl',
21+
},
22+
23+
// We need this for tests because we pull the latest from `fxa-content-server-l10n`
24+
// and place those in our `public` directory at `postinstall` time, and sometimes we have
25+
// FTL updates on our side that haven't landed yet on the l10n side. We want to test
26+
// against _our_ latest, and not necessarily the l10n repo's latest.
27+
'ftl-test': {
28+
src: ['src/branding.ftl', 'src/**/*.ftl'],
29+
dest: 'test/payments.ftl',
30+
},
31+
},
32+
watch: {
33+
ftl: {
34+
files: ['src/**/*.ftl'],
35+
tasks: ['merge-ftl'],
36+
options: {
37+
interrupt: true,
38+
},
39+
},
40+
},
41+
});
42+
43+
grunt.loadNpmTasks('grunt-contrib-watch');
44+
grunt.loadNpmTasks('grunt-contrib-concat');
45+
46+
grunt.registerTask('merge-ftl', ['concat:ftl']);
47+
grunt.registerTask('merge-ftl:test', ['concat:ftl-test']);
48+
grunt.registerTask('watch-ftl', ['watch:ftl']);
49+
};

packages/fxa-payments-server/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ We use rescripts and yarn workspaces to manage our node packages. If you are enc
8484

8585
This launch config currently only works for the tests under the `/src` directory in the `fxa-payments-server` package, not the `/server` directory.
8686

87+
### L10N
88+
89+
Strings are automatically extracted to the [`fxa-content-server-l10n` repo](https://github.com/mozilla/fxa-content-server-l10n) where they reach Pontoon for translations to occur by our l10n team and contributors. This is achieved by concatenating all of our .ftl (Fluent) files into a single `payments.ftl` file with the `merge-ftl` grunttask, and the script that runs in `fxa-content-server-l10n` on a weekly cadence. For more detailed information, check out the [ecosystem platform l10n](https://mozilla.github.io/ecosystem-platform/reference/localization) doc.
90+
8791
## License
8892

8993
MPL-2.0
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
basepath = "."
22

33
[[paths]]
4-
reference = "public/locales/en-US/*.ftl"
4+
reference = "public/locales/en/*.ftl"
55
l10n = "public/locales/{locale}/*.ftl"

packages/fxa-payments-server/package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88
"lint": "npm-run-all --parallel lint:eslint",
99
"lint:eslint": "eslint . .storybook",
1010
"audit": "npm audit --json | audit-filter --nsp-config=.nsprc --audit=-",
11-
"start": "tsc --build ../fxa-react && npm run build-css && pm2 start pm2.config.js && ../../_scripts/check-url.sh localhost:3031/__lbheartbeat__",
11+
"start": "tsc --build ../fxa-react && npm run build-css && grunt merge-ftl && pm2 start pm2.config.js && ../../_scripts/check-url.sh localhost:3031/__lbheartbeat__",
1212
"stop": "pm2 stop pm2.config.js",
1313
"restart": "tsc --build ../fxa-react && npm run build-css && pm2 restart pm2.config.js",
1414
"delete": "pm2 delete pm2.config.js",
1515
"build": "tsc --build ../fxa-react && NODE_ENV=production npm run build-css && SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/ INLINE_RUNTIME_CHUNK=false CI=false rescripts build",
1616
"eject": "react-scripts eject",
1717
"test": "npm-run-all test:frontend test:server",
18-
"test:frontend": "SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/ INLINE_RUNTIME_CHUNK=false rescripts test --watchAll=false",
18+
"test:frontend": "yarn merge-ftl:test && SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/ INLINE_RUNTIME_CHUNK=false rescripts test --watchAll=false",
1919
"test:frontend:watch": "SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/ INLINE_RUNTIME_CHUNK=false rescripts test",
2020
"test:server": "jest --runInBand --coverage --verbose --config server/jest.config.js --forceExit",
2121
"format": "prettier --write --config ../../_dev/.prettierrc '**'",
2222
"storybook": "start-storybook -p 6006",
23-
"build-storybook": "NODE_ENV=production npm run build-css && build-storybook && cp -r public/locales public/images storybook-static/"
23+
"build-storybook": "NODE_ENV=production npm run build-css && build-storybook && cp -r public/images storybook-static/",
24+
"merge-ftl": "grunt merge-ftl",
25+
"merge-ftl:test": "grunt merge-ftl:test",
26+
"watch-ftl": "grunt watch-ftl"
2427
},
2528
"eslintConfig": {
2629
"extends": [
@@ -87,6 +90,10 @@
8790
"eslint-plugin-jest": "^27.1.3",
8891
"eslint-plugin-react": "^7.31.10",
8992
"express-http-proxy": "^1.6.3",
93+
"grunt": "^1.5.3",
94+
"grunt-cli": "^1.4.3",
95+
"grunt-contrib-concat": "^2.1.0",
96+
"grunt-contrib-watch": "^1.1.0",
9097
"handlebars": "^4.7.7",
9198
"intl": "1.2.5",
9299
"jest": "27.5.1",

packages/fxa-payments-server/pm2.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,14 @@ module.exports = {
7272
ignore_watch: ['src/styles/tailwind.out.*'],
7373
time: true,
7474
},
75+
{
76+
name: 'payments-ftl',
77+
script: 'yarn grunt watch-ftl',
78+
cwd: __dirname,
79+
filter_env: ['npm_'],
80+
max_restarts: '1',
81+
min_uptime: '2m',
82+
time: true,
83+
},
7584
],
7685
};

0 commit comments

Comments
 (0)