From f4ef8a3ea0f5c75afffbff6033e7a620b576c585 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jun 2022 12:13:21 +0200 Subject: [PATCH] Allow setting plans page currency with url param (#8263) * Allow setting plans page currency with url param GitOrigin-RevId: 5ae977d9872cf5f5b1a234d1273c70c2dd0e14e9 --- .../Features/Subscription/SubscriptionController.js | 13 +++++++++++-- .../src/Subscription/SubscriptionControllerTests.js | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 96cb73e7fd..3bb838d974 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -33,10 +33,19 @@ const validGroupPlanModalOptions = { async function plansPage(req, res) { const plans = SubscriptionViewModelBuilder.buildPlansList() - const { currencyCode: recommendedCurrency } = - await GeoIpLookup.promises.getCurrencyCode( + let recommendedCurrency + if (req.query.currency) { + const queryCurrency = req.query.currency.toUpperCase() + if (GeoIpLookup.isValidCurrencyParam(queryCurrency)) { + recommendedCurrency = queryCurrency + } + } + if (!recommendedCurrency) { + const currencyLookup = await GeoIpLookup.promises.getCurrencyCode( (req.query ? req.query.ip : undefined) || req.ip ) + recommendedCurrency = currencyLookup.currencyCode + } function getDefault(param, category, defaultValue) { const v = req.query && req.query[param] diff --git a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js index 9d22b0b301..b408c15bb0 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js @@ -208,6 +208,7 @@ describe('SubscriptionController', function () { opts.groupPlanModalDefaults.usage.should.equal('foo') done() } + this.GeoIpLookup.isValidCurrencyParam.returns(false) this.req.query = { number: '42', currency: 'ABC',