Previously, when a user canceled a subscription, the access would revoke immediately on Discourse vs. at the end of the billing period. This commit changes the behavior to remove membership at the end of the billing period using Stripe's `cancel_at_period_end` attribute on the Subscription object. This commit now requires the setup of webhooks for subscription processing to occur correctly.
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import Route from "@ember/routing/route";
|
|
import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription";
|
|
import I18n from "I18n";
|
|
|
|
export default Route.extend({
|
|
templateName: "user/billing/subscriptions",
|
|
|
|
model() {
|
|
return UserSubscription.findAll();
|
|
},
|
|
|
|
actions: {
|
|
cancelSubscription(subscription) {
|
|
bootbox.confirm(
|
|
I18n.t(
|
|
"discourse_subscriptions.user.subscriptions.operations.destroy.confirm"
|
|
),
|
|
I18n.t("no_value"),
|
|
I18n.t("yes_value"),
|
|
confirmed => {
|
|
if (confirmed) {
|
|
subscription.set("loading", true);
|
|
|
|
subscription
|
|
.destroy()
|
|
.then(result => subscription.set("status", result.status))
|
|
.catch(data =>
|
|
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
|
|
)
|
|
.finally(() => {
|
|
subscription.set("loading", false);
|
|
this.refresh();
|
|
});
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|
|
});
|