Просмотр исходного кода

Allow setting plans page currency with url param (#8263)

* Allow setting plans page currency with url param

GitOrigin-RevId: 5ae977d9872cf5f5b1a234d1273c70c2dd0e14e9
Thomas 4 лет назад
Родитель
Сommit
f4ef8a3ea0

+ 11 - 2
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]

+ 1 - 0
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',