discourse-subscriptions/assets/javascripts/discourse/models/plan.js

27 lines
769 B
JavaScript
Raw Normal View History

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