Files
discourse-subscriptions/assets/javascripts/discourse/models/plan.js.es6
T

27 lines
769 B
JavaScript
Raw Normal View History

2021-01-27 10:38:33 +01:00
import EmberObject, { computed } from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators";
2019-10-08 19:37:22 +11:00
2019-12-17 16:31:58 +11:00
const Plan = EmberObject.extend({
amountDollars: computed("unit_amount", {
2019-10-31 13:29:11 +11:00
get() {
return parseFloat(this.get("unit_amount") / 100).toFixed(2);
2019-10-31 13:29:11 +11:00
},
set(key, value) {
const decimal = parseFloat(value) * 100;
this.set("unit_amount", decimal);
2019-10-31 13:29:11 +11:00
return value;
2020-09-16 09:53:50 -05:00
},
2019-10-31 13:29:11 +11:00
}),
@discourseComputed("recurring.interval")
billingInterval(interval) {
return interval || "one-time";
},
2019-10-31 11:41:01 +11:00
@discourseComputed("amountDollars", "currency", "billingInterval")
2019-10-31 11:41:01 +11:00
subscriptionRate(amountDollars, currency, interval) {
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
2020-09-16 09:53:50 -05:00
},
2019-10-31 10:44:46 +11:00
});
2019-10-08 19:37:22 +11:00
export default Plan;