Files
discourse-subscriptions/assets/javascripts/discourse/models/admin-plan.js
T

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-10-10 13:52:55 +11:00
import { ajax } from "discourse/lib/ajax";
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
@discourseComputed("trial_period_days")
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,
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,
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
};
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
};
return ajax(`/s/admin/plans/${this.id}`, { method: "patch", data });
2024-11-29 15:42:50 +00:00
}
}