2021-01-27 04:38:33 -05:00
|
|
|
import EmberObject, { computed } from "@ember/object";
|
2020-05-28 11:32:57 -04:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-08 04:37:22 -04:00
|
|
|
|
2024-11-29 10:42:50 -05: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);
|
|
|
|
}
|
|
|
|
|
2020-07-15 09:44:40 -04:00
|
|
|
@discourseComputed("recurring.interval")
|
|
|
|
billingInterval(interval) {
|
|
|
|
return interval || "one-time";
|
2024-11-29 10:42:50 -05:00
|
|
|
}
|
2019-10-30 20:41:01 -04:00
|
|
|
|
2020-07-15 09:44:40 -04:00
|
|
|
@discourseComputed("amountDollars", "currency", "billingInterval")
|
2019-10-30 20:41:01 -04:00
|
|
|
subscriptionRate(amountDollars, currency, interval) {
|
2020-04-23 06:36:02 -04:00
|
|
|
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
2024-11-29 10:42:50 -05:00
|
|
|
}
|
|
|
|
}
|