Files
discourse-subscriptions/assets/javascripts/discourse/models/plan.js.es6
T
Justin DiRose 9c46794e80 DEV: Remove deprecations & improve error handling (#12)
- Replace deprecated methods on client
- Fix broken dropdowns due to select kit 2 upgrade
- Graceful error handling when Stripe keys are not configured but plugin enabled
2020-05-28 10:32:57 -05:00

32 lines
832 B
JavaScript

import EmberObject from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
const Plan = EmberObject.extend({
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;
}
}),
@discourseComputed("amountDollars", "currency", "interval")
subscriptionRate(amountDollars, currency, interval) {
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
}
});
Plan.reopenClass({
findAll(data) {
return ajax("/s/plans", { method: "get", data }).then(result =>
result.map(plan => Plan.create(plan))
);
}
});
export default Plan;