convert price_in_unit to price_in_cents

GitOrigin-RevId: bae030e9c90f8286d6e6550744849984fe81f63d
This commit is contained in:
Tim Alby 2022-01-12 11:07:21 +01:00 committed by Copybot
parent 3e70546e18
commit bbac46156b
8 changed files with 327 additions and 331 deletions

View file

@ -43,7 +43,7 @@ for (const [usage, planData] of Object.entries(groups)) {
planCode planCode
)} - Group Account (${size} licenses) - ${capitalize(usage)}`, )} - Group Account (${size} licenses) - ${capitalize(usage)}`,
hideFromUsers: true, hideFromUsers: true,
price_in_cents: groups[usage][planCode].USD[size].price_in_unit * 100, price_in_cents: groups[usage][planCode].USD[size].price_in_cents,
annual: true, annual: true,
features: Settings.features[planCode], features: Settings.features[planCode],
groupPlan: true, groupPlan: true,

View file

@ -3,10 +3,7 @@ const logger = require('@overleaf/logger')
function ensurePlansAreSetupCorrectly() { function ensurePlansAreSetupCorrectly() {
Settings.plans.forEach(plan => { Settings.plans.forEach(plan => {
if ( if (typeof plan.price_in_cents !== 'number') {
typeof plan.price_in_unit !== 'number' &&
typeof plan.price_in_cents !== 'number'
) {
logger.fatal({ plan }, 'missing price on plan') logger.fatal({ plan }, 'missing price on plan')
process.exit(1) process.exit(1)
} }
@ -14,6 +11,10 @@ function ensurePlansAreSetupCorrectly() {
logger.fatal({ plan }, 'unclear price attribute on plan') logger.fatal({ plan }, 'unclear price attribute on plan')
process.exit(1) process.exit(1)
} }
if (plan.price_in_unit) {
logger.fatal({ plan }, 'deprecated price_in_unit attribute on plan')
process.exit(1)
}
}) })
} }

View file

@ -3,17 +3,7 @@
* This is to avoid unintended/artifical credits on users Recurly accounts. * This is to avoid unintended/artifical credits on users Recurly accounts.
*/ */
function shouldPlanChangeAtTermEnd(oldPlan, newPlan) { function shouldPlanChangeAtTermEnd(oldPlan, newPlan) {
return getPlanPriceInCents(oldPlan) > getPlanPriceInCents(newPlan) return oldPlan.price_in_cents > newPlan.price_in_cents
}
/**
* Group plans have their price in dollars, but individual plans store the price in cents
*/
function getPlanPriceInCents(plan) {
if (plan.price_in_unit) {
return plan.price_in_unit * 100
}
return plan.price_in_cents
} }
module.exports = { module.exports = {

File diff suppressed because it is too large Load diff

View file

@ -22,10 +22,12 @@ function updateGroupPlanView() {
const modalEl = document.querySelector('[data-ol-group-plan-modal]') const modalEl = document.querySelector('[data-ol-group-plan-modal]')
const { planCode, size, currency, usage } = getFormValues() const { planCode, size, currency, usage } = getFormValues()
const priceInUnit = groupPlans[usage][planCode][currency][size].price_in_unit const priceInCents =
groupPlans[usage][planCode][currency][size].price_in_cents
const priceInUnit = (priceInCents / 100).toFixed()
const currencySymbol = currencySymbols[currency] const currencySymbol = currencySymbols[currency]
const displayPrice = `${currencySymbol}${priceInUnit}` const displayPrice = `${currencySymbol}${priceInUnit}`
const perUserPrice = parseFloat((priceInUnit / size).toFixed(2)) const perUserPrice = parseFloat((priceInCents / 100 / size).toFixed(2))
modalEl.querySelectorAll('[data-ol-group-plan-plan-code]').forEach(el => { modalEl.querySelectorAll('[data-ol-group-plan-plan-code]').forEach(el => {
el.hidden = el.getAttribute('data-ol-group-plan-plan-code') !== planCode el.hidden = el.getAttribute('data-ol-group-plan-plan-code') !== planCode

View file

@ -161,8 +161,9 @@ App.controller(
let perUserDisplayPricePlaceholder = '...' let perUserDisplayPricePlaceholder = '...'
const currencySymbol = $scope.options.currencySymbols[currency] const currencySymbol = $scope.options.currencySymbols[currency]
if (taxRate === 0) { if (taxRate === 0) {
const basePriceInUnit = const basePriceInCents =
$scope.groupPlans[usage][plan_code][currency][size].price_in_unit $scope.groupPlans[usage][plan_code][currency][size].price_in_cents
const basePriceInUnit = (basePriceInCents / 100).toFixed()
recurlyPricePlaceholder.total = `${currencySymbol}${basePriceInUnit}` recurlyPricePlaceholder.total = `${currencySymbol}${basePriceInUnit}`
perUserDisplayPricePlaceholder = getPricePerUser( perUserDisplayPricePlaceholder = getPricePerUser(
basePriceInUnit, basePriceInUnit,

View file

@ -23,7 +23,9 @@ async function getRecurlyGroupPrices() {
prices[usage] = prices[usage] || {} prices[usage] = prices[usage] || {}
prices[usage][type] = prices[usage][type] || {} prices[usage][type] = prices[usage][type] || {}
prices[usage][type][currency] = prices[usage][type][currency] || {} prices[usage][type][currency] = prices[usage][type][currency] || {}
prices[usage][type][currency][size] = { price_in_unit: unitAmount } prices[usage][type][currency][size] = {
price_in_cents: unitAmount * 100,
}
}) })
} }
} }

View file

@ -18,12 +18,12 @@ const plans = {
}, },
expensiveGroup: { expensiveGroup: {
plancode: 'group_expensive', plancode: 'group_expensive',
price_in_unit: 495, price_in_cents: 49500,
groupPlan: true, groupPlan: true,
}, },
cheapGroup: { cheapGroup: {
plancode: 'group_cheap', plancode: 'group_cheap',
price_in_unit: 10, price_in_cents: 1000,
groupPlan: true, groupPlan: true,
}, },
bad: {}, bad: {},