2019-12-17 16:31:58 +11:00
|
|
|
import EmberObject from "@ember/object";
|
2020-05-28 10:32:57 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-08 19:37:22 +11:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
|
2019-12-17 16:31:58 +11:00
|
|
|
const Plan = EmberObject.extend({
|
2020-07-15 08:44:40 -05:00
|
|
|
amountDollars: Ember.computed("unit_amount", {
|
2019-10-31 13:29:11 +11:00
|
|
|
get() {
|
2020-07-15 08:44:40 -05:00
|
|
|
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;
|
2020-07-15 08:44:40 -05:00
|
|
|
this.set("unit_amount", decimal);
|
2019-10-31 13:29:11 +11:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}),
|
2020-07-15 08:44:40 -05:00
|
|
|
@discourseComputed("recurring.interval")
|
|
|
|
|
billingInterval(interval) {
|
|
|
|
|
return interval || "one-time";
|
|
|
|
|
},
|
2019-10-31 11:41:01 +11:00
|
|
|
|
2020-07-15 08:44:40 -05:00
|
|
|
@discourseComputed("amountDollars", "currency", "billingInterval")
|
2019-10-31 11:41:01 +11:00
|
|
|
subscriptionRate(amountDollars, currency, interval) {
|
2020-04-23 16:06:02 +05:30
|
|
|
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
2019-10-31 13:31:24 +11:00
|
|
|
}
|
2019-10-31 10:44:46 +11:00
|
|
|
});
|
2019-10-08 19:37:22 +11:00
|
|
|
|
|
|
|
|
Plan.reopenClass({
|
2019-11-04 16:37:21 +11:00
|
|
|
findAll(data) {
|
2019-12-03 10:29:44 +11:00
|
|
|
return ajax("/s/plans", { method: "get", data }).then(result =>
|
2019-10-17 20:34:26 +11:00
|
|
|
result.map(plan => Plan.create(plan))
|
2019-10-09 09:11:02 +11:00
|
|
|
);
|
2019-10-08 19:37:22 +11:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default Plan;
|