2019-12-02 02:58:14 -05:00
|
|
|
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
2020-05-28 11:32:57 -04:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-09 22:52:55 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2019-10-30 20:41:01 -04:00
|
|
|
const AdminPlan = Plan.extend({
|
2019-10-23 00:55:06 -04:00
|
|
|
isNew: false,
|
2019-10-14 18:40:49 -04:00
|
|
|
name: "",
|
|
|
|
interval: "month",
|
2020-07-15 09:44:40 -04:00
|
|
|
unit_amount: 0,
|
2019-10-14 18:40:49 -04:00
|
|
|
intervals: ["day", "week", "month", "year"],
|
2019-10-22 20:50:54 -04:00
|
|
|
metadata: {},
|
2019-10-14 18:40:49 -04:00
|
|
|
|
2020-05-28 11:32:57 -04:00
|
|
|
@discourseComputed("trial_period_days")
|
2020-07-15 09:44:40 -04:00
|
|
|
parseTrialPeriodDays(trialDays) {
|
|
|
|
if (trialDays) {
|
|
|
|
return parseInt(0 + trialDays, 10);
|
2019-10-24 23:00:59 -04:00
|
|
|
} else {
|
2019-10-23 00:55:06 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-14 18:40:49 -04:00
|
|
|
save() {
|
|
|
|
const data = {
|
2019-10-17 05:34:26 -04:00
|
|
|
nickname: this.nickname,
|
2019-10-14 18:40:49 -04:00
|
|
|
interval: this.interval,
|
2020-07-15 09:44:40 -04:00
|
|
|
amount: this.unit_amount,
|
2019-11-30 01:44:16 -05:00
|
|
|
currency: this.currency,
|
2019-10-23 00:55:06 -04:00
|
|
|
trial_period_days: this.parseTrialPeriodDays,
|
2020-07-22 12:06:34 -04:00
|
|
|
type: this.type,
|
2019-10-22 20:50:54 -04:00
|
|
|
product: this.product,
|
|
|
|
metadata: this.metadata,
|
2019-10-23 19:02:31 -04:00
|
|
|
active: this.active
|
2019-10-14 18:40:49 -04:00
|
|
|
};
|
|
|
|
|
2019-12-02 18:29:44 -05:00
|
|
|
return ajax("/s/admin/plans", { method: "post", data });
|
2019-10-23 00:55:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
update() {
|
|
|
|
const data = {
|
|
|
|
nickname: this.nickname,
|
|
|
|
trial_period_days: this.parseTrialPeriodDays,
|
|
|
|
metadata: this.metadata,
|
2019-10-23 19:02:31 -04:00
|
|
|
active: this.active
|
2019-10-23 00:55:06 -04:00
|
|
|
};
|
|
|
|
|
2019-12-02 18:29:44 -05:00
|
|
|
return ajax(`/s/admin/plans/${this.id}`, { method: "patch", data });
|
2019-10-14 18:40:49 -04:00
|
|
|
}
|
2019-10-09 22:52:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
AdminPlan.reopenClass({
|
2019-10-21 00:28:45 -04:00
|
|
|
findAll(data) {
|
2019-12-02 18:29:44 -05:00
|
|
|
return ajax("/s/admin/plans", { method: "get", data }).then(result =>
|
2019-10-13 21:36:46 -04:00
|
|
|
result.map(plan => AdminPlan.create(plan))
|
2019-10-09 22:52:55 -04:00
|
|
|
);
|
2019-10-17 05:34:26 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
find(id) {
|
2019-12-02 18:29:44 -05:00
|
|
|
return ajax(`/s/admin/plans/${id}`, { method: "get" }).then(plan =>
|
2019-10-17 05:34:26 -04:00
|
|
|
AdminPlan.create(plan)
|
|
|
|
);
|
2019-10-09 22:52:55 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default AdminPlan;
|