🐛 Fixed sending non-integer prices to Tiers API

refs https://github.com/TryGhost/Team/issues/1319

Due to how JS implements numbers, it's possible that when we multiple a
number with 2 decimal places by 100 that we do not end up with an
integer e.g. 9.95 * 100 = 994.999...

This is not a valid price for the API and so we must round it to the
nearest integer. Rounding is safe here, because the errors involved in
floating point operations are very small.
This commit is contained in:
Fabien "egg" O'Carroll 2022-02-08 16:48:10 +02:00 committed by Fabien 'egg' O'Carroll
parent a2b631f8b6
commit 047f28177f

View File

@ -259,8 +259,8 @@ export default class MembersAccessController extends Controller {
@action
updatePortalPreview({forceRefresh} = {forceRefresh: false}) {
// TODO: can these be worked out from settings in membersUtils?
const monthlyPrice = this.stripeMonthlyAmount * 100;
const yearlyPrice = this.stripeYearlyAmount * 100;
const monthlyPrice = Math.round(this.stripeMonthlyAmount * 100);
const yearlyPrice = Math.round(this.stripeYearlyAmount * 100);
let portalPlans = this.settings.get('portalPlans') || [];
let isMonthlyChecked = portalPlans.includes('monthly');