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

* Allow setting plans page currency with url param

GitOrigin-RevId: 5ae977d9872cf5f5b1a234d1273c70c2dd0e14e9
This commit is contained in:
Thomas 2022-06-03 12:13:21 +02:00 committed by Copybot
parent 11fddee8e4
commit f4ef8a3ea0
2 changed files with 12 additions and 2 deletions

View file

@ -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]

View file

@ -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',