Files
discourse-subscriptions/assets/javascripts/discourse/models/admin-subscription.js.es6
T
Justin DiRose c9ff55b46a REFACTOR: Use the Prices API in place of Plans (#17)
Stripe has a newer API called Prices where you can create a price for any product and it can either be recurring or one-time. The easy part is existing Plans work with the Prices API by passing a Plan ID, but objects are returned in the slightly-different Prices API object format.

This commit is a refactor to the new API to handle the data in its new form, and lays the foundation for a one time payment plan to be added to any subscriptions product.
2020-07-15 08:44:40 -05:00

43 lines
1.1 KiB
JavaScript

import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
import getURL from "discourse-common/lib/get-url";
const AdminSubscription = EmberObject.extend({
@discourseComputed("status")
canceled(status) {
return status === "canceled";
},
@discourseComputed("metadata")
metadataUserExists(metadata) {
return metadata.user_id && metadata.username;
},
@discourseComputed("metadata")
subscriptionUserPath(metadata) {
return getURL(`/admin/users/${metadata.user_id}/${metadata.username}`);
},
destroy() {
return ajax(`/s/admin/subscriptions/${this.id}`, {
method: "delete"
}).then(result => AdminSubscription.create(result));
}
});
AdminSubscription.reopenClass({
find() {
return ajax("/s/admin/subscriptions", {
method: "get"
}).then(result => {
if (result === null) {
return { unconfigured: true };
}
return result.map(subscription => AdminSubscription.create(subscription));
});
}
});
export default AdminSubscription;