Skip to content

Commit 9fa85a7

Browse files
feat(payments-next):Redirect old Subscription Management page to new page
Because: * This commit: * Closes #
1 parent 608f3e2 commit 9fa85a7

8 files changed

Lines changed: 97 additions & 11 deletions

File tree

packages/fxa-content-server/app/scripts/lib/payment-server.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ const PaymentServer = {
1919
* @param {Object} subscriptionsConfig
2020
* @param {String} redirectPath
2121
* @param {Object} [rpQueryParams={}]
22+
* @param {String} [paymentsNextUrl]
23+
* @param {Boolean} [usePaymentsNext]
2224
*/
2325
async navigateToPaymentServer(
2426
view,
2527
subscriptionsConfig,
2628
redirectPath,
27-
rpQueryParams = {}
29+
rpQueryParams = {},
30+
paymentsNextUrl,
31+
usePaymentsNext,
2832
) {
2933
const {
3034
managementClientId,
@@ -63,7 +67,8 @@ const PaymentServer = {
6367
flow_id: flowId,
6468
...rpQueryParams,
6569
});
66-
const url = `${managementUrl}/${redirectPath}${queryString}`;
70+
const baseUrl = usePaymentsNext ? paymentsNextUrl : managementUrl;
71+
const url = `${baseUrl}/${redirectPath}${queryString}`;
6772

6873
const unauthenticatedRedirect = () => {
6974
if (isAllowedUnauthenticatedRoute(redirectPath)) {

packages/fxa-content-server/app/scripts/views/subscriptions_management_redirect.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ class SubscriptionsManagementRedirectView extends FormView {
1414

1515
initialize(options) {
1616
this._subscriptionsConfig = {};
17-
if (options && options.config && options.config.subscriptions) {
18-
this._subscriptionsConfig = options.config.subscriptions;
17+
this._paymentsNextUrl = undefined;
18+
if (options && options.config) {
19+
if (options.config.subscriptions) {
20+
this._subscriptionsConfig = options.config.subscriptions;
21+
this._usePaymentsNext = !!options.config.subscriptions.usePaymentsNextSubscriptionManagement;
22+
}
23+
if (options.config.paymentsNextHostedUrl) {
24+
this._paymentsNextUrl = options.config.paymentsNextHostedUrl;
25+
}
1926
}
2027

2128
// Flow events need to be initialized before the navigation
@@ -27,7 +34,10 @@ class SubscriptionsManagementRedirectView extends FormView {
2734
return PaymentServer.navigateToPaymentServer(
2835
this,
2936
this._subscriptionsConfig,
30-
'subscriptions'
37+
this._usePaymentsNext ? 'subscriptions/landing' : 'subscriptions',
38+
{},
39+
this._paymentsNextUrl,
40+
this._usePaymentsNext,
3141
);
3242
}
3343
}

packages/fxa-content-server/app/scripts/views/support.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ const SupportView = BaseView.extend({
4646
this.productSupportApps = {};
4747

4848
this._subscriptionsConfig = {};
49-
if (options && options.config && options.config.subscriptions) {
50-
this._subscriptionsConfig = options.config.subscriptions;
49+
this._paymentsNextUrl = undefined;
50+
if (options && options.config) {
51+
if (options.config.subscriptions) {
52+
this._subscriptionsConfig = options.config.subscriptions;
53+
this._usePaymentsNext = !!options.config.subscriptions.usePaymentsNextSubscriptionManagement;
54+
}
55+
if (options.config.paymentsNextHostedUrl) {
56+
this._paymentsNextUrl = options.config.paymentsNextHostedUrl;
57+
}
5158
}
5259
},
5360

@@ -334,8 +341,10 @@ const SupportView = BaseView.extend({
334341
PaymentServer.navigateToPaymentServer(
335342
this,
336343
this._subscriptionsConfig,
337-
'subscriptions',
338-
queryParams
344+
this._usePaymentsNext ? 'subscriptions/landing' : 'subscriptions',
345+
queryParams,
346+
this._paymentsNextUrl,
347+
this._usePaymentsNext,
339348
);
340349
},
341350
});

packages/fxa-content-server/app/tests/spec/views/subscriptions_management_redirect.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ describe('views/subscriptions_management_redirect', function () {
3636
managementScopes: 'MOCK_SCOPES',
3737
managementTokenTTL: 900,
3838
managementUrl: 'http://example.com',
39+
usePaymentsNextSubscriptionManagement: true,
3940
},
41+
paymentsNextHostedUrl: 'http://payments-next.example.com',
4042
};
4143

4244
sinon.stub(user, 'sessionStatus').callsFake(() => Promise.resolve(account));
@@ -68,8 +70,16 @@ describe('views/subscriptions_management_redirect', function () {
6870
it('renders correctly, initializes flow events, navigates to payments server', () => {
6971
assert.lengthOf(view.$('.redirect-loading'), 1);
7072
assert.isTrue(view.initializeFlowEvents.calledOnce);
71-
assert.deepEqual(PaymentServer.navigateToPaymentServer.args, [
72-
[view, config.subscriptions, 'subscriptions'],
73+
assert.deepEqual(
74+
PaymentServer.navigateToPaymentServer.args, [
75+
[
76+
view,
77+
config.subscriptions,
78+
'subscriptions/landing',
79+
{},
80+
config.paymentsNextHostedUrl,
81+
true,
82+
],
7383
]);
7484
});
7585
});

packages/fxa-content-server/server/lib/configuration.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,12 @@ const conf = (module.exports = convict({
10321032
env: 'SUBSCRIPTIONS_FIRESTORE_CONFIGS_ENABLED',
10331033
format: Boolean,
10341034
},
1035+
usePaymentsNextSubscriptionManagement : {
1036+
default: true,
1037+
doc: 'Whether to redirect to the new Subscription Management Page',
1038+
env: 'FEATURE_FLAGS_PAYMENTS_NEXT_SUBSCRIPTION_MANAGEMENT',
1039+
format: Boolean,
1040+
}
10351041
},
10361042
sync_tokenserver_url: {
10371043
default: 'http://localhost:8000/token',

packages/fxa-content-server/server/lib/routes/react-app/route-definition-index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ function getIndexRouteDefinition(config) {
8282
const WEBPACK_PUBLIC_PATH = `${STATIC_RESOURCE_URL}/${config.get(
8383
'jsResourcePath'
8484
)}/`;
85+
const PAYMENTS_NEXT_HOSTED_URL = config.get('payments_next_hosted_url');
8586

8687
const configForFrontEnd = {
8788
authServerUrl: AUTH_SERVER_URL,
89+
paymentsNextHostedUrl: PAYMENTS_NEXT_HOSTED_URL,
8890
maxEventOffset: MAX_EVENT_OFFSET,
8991
env: ENV,
9092
isCoppaEnabled: COPPA_ENABLED,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const conf = convict({
2424
env: 'SUBSCRIPTIONS_STRIPE_TAX_ENABLED',
2525
format: Boolean,
2626
},
27+
paymentsNextSubscriptionManagement: {
28+
default: false,
29+
doc: 'Whether to redirect to the new Subscription Management Page',
30+
format: Boolean,
31+
env: 'FEATURE_FLAGS_PAYMENTS_NEXT_SUBSCRIPTION_MANAGEMENT',
32+
},
2733
},
2834
amplitude: {
2935
enabled: {
@@ -357,6 +363,14 @@ const conf = convict({
357363
format: 'url',
358364
},
359365
},
366+
paymentsNext: {
367+
url: {
368+
default: 'http://localhost:3035',
369+
doc: 'the url of the Payments-Next server',
370+
env: 'PAYMENTS_NEXT_HOSTED_URL',
371+
format: 'url',
372+
}
373+
}
360374
},
361375
staticResources: {
362376
directory: {

packages/fxa-payments-server/server/lib/server.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ module.exports = () => {
9191
profile: {
9292
url: config.get('servers.profile.url'),
9393
},
94+
paymentsNext: {
95+
url: config.get('servers.paymentsNext.url'),
96+
}
9497
},
9598
paypal: {
9699
apiUrl: config.get('paypal.apiUrl'),
@@ -236,6 +239,33 @@ module.exports = () => {
236239
});
237240
}
238241

242+
app.use((req, res, next) => {
243+
if (!FEATURE_FLAGS.paymentsNextSubscriptionManagement) {
244+
return next();
245+
}
246+
247+
let nextUrl;
248+
try {
249+
nextUrl = config.get('servers.paymentsNext.url');
250+
} catch {
251+
return next();
252+
}
253+
if (!nextUrl) {
254+
return next();
255+
}
256+
257+
if (req.path === '/subscriptions' || req.path.startsWith('/subscriptions/')) {
258+
const queryBeginIndex = req.originalUrl.indexOf('?');
259+
const queryString = queryBeginIndex >= 0 ? req.originalUrl.slice(queryBeginIndex) : '';
260+
261+
const redirectTo = `${nextUrl}/subscriptions/landing${queryString}`;
262+
263+
return res.redirect(redirectTo);
264+
}
265+
266+
return next();
267+
});
268+
239269
// Note - the static route handlers must come last
240270
// because the proxyUrl handler's app.use('/') captures
241271
// all requests that match no others.

0 commit comments

Comments
 (0)