An implementation of refunds from the Admin dashboard. To refund, go to Plugins > Subscriptions > Subscriptions then click the `Cancel` button. You'll be presented with a modal. If you wish to refund only the most recent payment, check the box. This only implements refunds for Subscriptions, not One Time Payments. One Time Payments will still need to be handled manually at this time.
49 lines
1.2 KiB
JavaScript
49 lines
1.2 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(refund) {
|
|
const data = {
|
|
refund: refund,
|
|
};
|
|
return ajax(`/s/admin/subscriptions/${this.id}`, {
|
|
method: "delete",
|
|
data,
|
|
}).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;
|