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