Ghost/ghost/admin/app/serializers/product.js
Rishabh Garg d16a8781a9 🐛 Fixed sending non-integer prices to tiers api (#2288)
closes 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. We round off prices both at source as well as in ties serializer to make sure we never send non integer prices to API.
2022-03-04 14:48:45 +05:30

18 lines
484 B
JavaScript

import ApplicationSerializer from './application';
export default class ProductSerializer extends ApplicationSerializer {
serialize() {
let json = super.serialize(...arguments);
if (json?.monthly_price?.amount) {
json.monthly_price.amount = Math.round(json.monthly_price.amount);
}
if (json?.yearly_price?.amount) {
json.yearly_price.amount = Math.round(json.yearly_price.amount);
}
return json;
}
}