2019-10-30 19:44:46 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2019-10-08 04:37:22 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2019-10-30 19:44:46 -04:00
|
|
|
const Plan = Discourse.Model.extend({
|
2019-10-30 22:29:11 -04:00
|
|
|
amountDollars: Ember.computed("amount", {
|
|
|
|
get() {
|
|
|
|
return parseFloat(this.get("amount") / 100).toFixed(2);
|
|
|
|
},
|
|
|
|
set(key, value) {
|
|
|
|
const decimal = parseFloat(value) * 100;
|
|
|
|
this.set("amount", decimal);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}),
|
2019-10-30 20:41:01 -04:00
|
|
|
|
|
|
|
@computed("amountDollars", "currency", "interval")
|
|
|
|
subscriptionRate(amountDollars, currency, interval) {
|
|
|
|
return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
2019-10-30 22:31:24 -04:00
|
|
|
}
|
2019-10-30 19:44:46 -04:00
|
|
|
});
|
2019-10-08 04:37:22 -04:00
|
|
|
|
|
|
|
Plan.reopenClass({
|
2019-11-04 00:37:21 -05:00
|
|
|
findAll(data) {
|
|
|
|
return ajax("/patrons/plans", { method: "get", data }).then(result =>
|
2019-10-17 05:34:26 -04:00
|
|
|
result.map(plan => Plan.create(plan))
|
2019-10-08 18:11:02 -04:00
|
|
|
);
|
2019-10-08 04:37:22 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Plan;
|