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

25 lines
724 B
JavaScript
Raw Permalink 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
export default class Plan extends EmberObject {
@computed("unit_amount")
get amountDollars() {
return parseFloat(this.get("unit_amount") / 100).toFixed(2);
}
set amountDollars(value) {
const decimal = parseFloat(value) * 100;
this.set("unit_amount", decimal);
}
@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}`;
}
}