DEV: Convert to native class syntax (#249)
This commit is contained in:
parent
c7a35e1c89
commit
3149828c22
|
@ -3,43 +3,53 @@ import { action } from "@ember/object";
|
||||||
import { equal } from "@ember/object/computed";
|
import { equal } from "@ember/object/computed";
|
||||||
import { later } from "@ember/runloop";
|
import { later } from "@ember/runloop";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
|
import { classNameBindings } from "@ember-decorators/component";
|
||||||
|
import { observes } from "@ember-decorators/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const SIDEBAR_BODY_CLASS = "subscription-campaign-sidebar";
|
const SIDEBAR_BODY_CLASS = "subscription-campaign-sidebar";
|
||||||
|
|
||||||
export default Component.extend({
|
@classNameBindings("isGoalMet:goal-met")
|
||||||
router: service(),
|
export default class CampaignBanner extends Component {
|
||||||
dismissed: false,
|
@service router;
|
||||||
loading: false,
|
|
||||||
dropShadowColor: setting(
|
dismissed = false;
|
||||||
"discourse_subscriptions_campaign_banner_shadow_color"
|
loading = false;
|
||||||
),
|
|
||||||
backgroundImageUrl: setting(
|
@setting("discourse_subscriptions_campaign_banner_shadow_color")
|
||||||
"discourse_subscriptions_campaign_banner_bg_image"
|
dropShadowColor;
|
||||||
),
|
|
||||||
isSidebar: equal(
|
@setting("discourse_subscriptions_campaign_banner_bg_image")
|
||||||
|
backgroundImageUrl;
|
||||||
|
|
||||||
|
@equal(
|
||||||
"siteSettings.discourse_subscriptions_campaign_banner_location",
|
"siteSettings.discourse_subscriptions_campaign_banner_location",
|
||||||
"Sidebar"
|
"Sidebar"
|
||||||
),
|
)
|
||||||
subscribers: setting("discourse_subscriptions_campaign_subscribers"),
|
isSidebar;
|
||||||
subscriberGoal: equal(
|
|
||||||
"siteSettings.discourse_subscriptions_campaign_type",
|
@setting("discourse_subscriptions_campaign_subscribers") subscribers;
|
||||||
"Subscribers"
|
|
||||||
),
|
@equal("siteSettings.discourse_subscriptions_campaign_type", "Subscribers")
|
||||||
currency: setting("discourse_subscriptions_currency"),
|
subscriberGoal;
|
||||||
amountRaised: setting("discourse_subscriptions_campaign_amount_raised"),
|
|
||||||
goalTarget: setting("discourse_subscriptions_campaign_goal"),
|
@setting("discourse_subscriptions_currency") currency;
|
||||||
product: setting("discourse_subscriptions_campaign_product"),
|
|
||||||
pricingTableEnabled: setting("discourse_subscriptions_pricing_table_enabled"),
|
@setting("discourse_subscriptions_campaign_amount_raised") amountRaised;
|
||||||
showContributors: setting(
|
|
||||||
"discourse_subscriptions_campaign_show_contributors"
|
@setting("discourse_subscriptions_campaign_goal") goalTarget;
|
||||||
),
|
|
||||||
classNameBindings: ["isGoalMet:goal-met"],
|
@setting("discourse_subscriptions_campaign_product") product;
|
||||||
|
|
||||||
|
@setting("discourse_subscriptions_pricing_table_enabled") pricingTableEnabled;
|
||||||
|
|
||||||
|
@setting("discourse_subscriptions_campaign_show_contributors")
|
||||||
|
showContributors;
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
super.init(...arguments);
|
||||||
|
|
||||||
this.set("contributors", []);
|
this.set("contributors", []);
|
||||||
|
|
||||||
|
@ -66,10 +76,10 @@ export default Component.extend({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super(...arguments);
|
super.didInsertElement(...arguments);
|
||||||
if (this.isSidebar && this.shouldShow && !this.site.mobileView) {
|
if (this.isSidebar && this.shouldShow && !this.site.mobileView) {
|
||||||
document.body.classList.add(SIDEBAR_BODY_CLASS);
|
document.body.classList.add(SIDEBAR_BODY_CLASS);
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,12 +104,12 @@ export default Component.extend({
|
||||||
document.body.classList.add("success-animation-off");
|
document.body.classList.add("success-animation-off");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
this._super(...arguments);
|
super.willDestroyElement(...arguments);
|
||||||
document.body.classList.remove(SIDEBAR_BODY_CLASS);
|
document.body.classList.remove(SIDEBAR_BODY_CLASS);
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("backgroundImageUrl")
|
@discourseComputed("backgroundImageUrl")
|
||||||
bannerInfoStyle(backgroundImageUrl) {
|
bannerInfoStyle(backgroundImageUrl) {
|
||||||
|
@ -114,7 +124,7 @@ export default Component.extend({
|
||||||
var(--campaign-background-image);
|
var(--campaign-background-image);
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-repeat: no-repeat;`;
|
background-repeat: no-repeat;`;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed(
|
@discourseComputed(
|
||||||
"router.currentRouteName",
|
"router.currentRouteName",
|
||||||
|
@ -143,14 +153,14 @@ export default Component.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
return showOnRoute && currentUser && enabled && visible;
|
return showOnRoute && currentUser && enabled && visible;
|
||||||
},
|
}
|
||||||
|
|
||||||
@observes("dismissed")
|
@observes("dismissed")
|
||||||
_updateBodyClasses() {
|
_updateBodyClasses() {
|
||||||
if (this.dismissed) {
|
if (this.dismissed) {
|
||||||
document.body.classList.remove(SIDEBAR_BODY_CLASS);
|
document.body.classList.remove(SIDEBAR_BODY_CLASS);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("dismissed")
|
@discourseComputed("dismissed")
|
||||||
visible(dismissed) {
|
visible(dismissed) {
|
||||||
|
@ -166,7 +176,7 @@ export default Component.extend({
|
||||||
(!dismissedBannerKey || now - bannerDismissedTime > threeMonths) &&
|
(!dismissedBannerKey || now - bannerDismissedTime > threeMonths) &&
|
||||||
!dismissed
|
!dismissed
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
subscribeRoute() {
|
subscribeRoute() {
|
||||||
|
@ -174,7 +184,7 @@ export default Component.extend({
|
||||||
return "subscriptions";
|
return "subscriptions";
|
||||||
}
|
}
|
||||||
return "subscribe";
|
return "subscribe";
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
isGoalMet() {
|
isGoalMet() {
|
||||||
|
@ -182,7 +192,7 @@ export default Component.extend({
|
||||||
? this.subscribers
|
? this.subscribers
|
||||||
: this.amountRaised;
|
: this.amountRaised;
|
||||||
return currentVolume >= this.goalTarget;
|
return currentVolume >= this.goalTarget;
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
dismissBanner() {
|
dismissBanner() {
|
||||||
|
@ -191,5 +201,5 @@ export default Component.extend({
|
||||||
key: "dismissed_campaign_banner",
|
key: "dismissed_campaign_banner",
|
||||||
value: Date.now(),
|
value: Date.now(),
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default Component.extend({
|
export default class CreateCouponForm extends Component {
|
||||||
|
discountType = "amount";
|
||||||
|
discount = null;
|
||||||
|
promoCode = null;
|
||||||
|
active = false;
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
discountTypes() {
|
discountTypes() {
|
||||||
return [
|
return [
|
||||||
{ id: "amount", name: "Amount" },
|
{ id: "amount", name: "Amount" },
|
||||||
{ id: "percent", name: "Percent" },
|
{ id: "percent", name: "Percent" },
|
||||||
];
|
];
|
||||||
},
|
}
|
||||||
discountType: "amount",
|
|
||||||
discount: null,
|
|
||||||
promoCode: null,
|
|
||||||
active: false,
|
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
createNewCoupon() {
|
createNewCoupon() {
|
||||||
const createParams = {
|
const createParams = {
|
||||||
promo: this.promoCode,
|
promo: this.promoCode,
|
||||||
|
@ -24,9 +26,10 @@ export default Component.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
this.create(createParams);
|
this.create(createParams);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
cancelCreate() {
|
cancelCreate() {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default Component.extend({
|
export default class PaymentOptions extends Component {
|
||||||
@discourseComputed("plans")
|
@discourseComputed("plans")
|
||||||
orderedPlans(plans) {
|
orderedPlans(plans) {
|
||||||
if (plans) {
|
if (plans) {
|
||||||
return plans.sort((a, b) => (a.unit_amount > b.unit_amount ? 1 : -1));
|
return plans.sort((a, b) => (a.unit_amount > b.unit_amount ? 1 : -1));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super(...arguments);
|
super.didInsertElement(...arguments);
|
||||||
if (this.plans && this.plans.length === 1) {
|
if (this.plans && this.plans.length === 1) {
|
||||||
this.set("selectedPlan", this.plans[0].id);
|
this.set("selectedPlan", this.plans[0].id);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
actions: {
|
|
||||||
|
@action
|
||||||
clickPlan(plan) {
|
clickPlan(plan) {
|
||||||
this.set("selectedPlan", plan.id);
|
this.set("selectedPlan", plan.id);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import { tagName } from "@ember-decorators/component";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const RECURRING = "recurring";
|
const RECURRING = "recurring";
|
||||||
|
|
||||||
export default Component.extend({
|
@tagName("")
|
||||||
tagName: "",
|
export default class PaymentPlan extends Component {
|
||||||
|
|
||||||
@discourseComputed("selectedPlan")
|
@discourseComputed("selectedPlan")
|
||||||
selectedClass(planId) {
|
selectedClass(planId) {
|
||||||
return planId === this.plan.id ? "btn-primary" : "";
|
return planId === this.plan.id ? "btn-primary" : "";
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("plan.type")
|
@discourseComputed("plan.type")
|
||||||
recurringPlan(type) {
|
recurringPlan(type) {
|
||||||
return type === RECURRING;
|
return type === RECURRING;
|
||||||
},
|
}
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
planClick() {
|
planClick() {
|
||||||
this.clickPlan(this.plan);
|
this.clickPlan(this.plan);
|
||||||
return false;
|
return false;
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
|
import { classNames } from "@ember-decorators/component";
|
||||||
|
|
||||||
export default Component.extend({
|
@classNames("product")
|
||||||
classNames: ["product"],
|
export default class ProductItem extends Component {}
|
||||||
});
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
|
import { classNames } from "@ember-decorators/component";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default Component.extend({
|
@classNames("product-list")
|
||||||
classNames: ["product-list"],
|
export default class ProductList extends Component {
|
||||||
|
|
||||||
@discourseComputed("products")
|
@discourseComputed("products")
|
||||||
emptyProducts(products) {
|
emptyProducts(products) {
|
||||||
return isEmpty(products);
|
return isEmpty(products);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,22 +1,27 @@
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
|
import { classNames } from "@ember-decorators/component";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import ComboBoxComponent from "select-kit/components/combo-box";
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
||||||
|
import {
|
||||||
|
pluginApiIdentifiers,
|
||||||
|
selectKitOptions,
|
||||||
|
} from "select-kit/components/select-kit";
|
||||||
|
|
||||||
export default ComboBoxComponent.extend({
|
@selectKitOptions({
|
||||||
pluginApiIdentifiers: ["subscribe-ca-province-select"],
|
|
||||||
classNames: ["subscribe-address-state-select"],
|
|
||||||
nameProperty: "name",
|
|
||||||
valueProperty: "value",
|
|
||||||
|
|
||||||
selectKitOptions: {
|
|
||||||
filterable: true,
|
filterable: true,
|
||||||
allowAny: false,
|
allowAny: false,
|
||||||
translatedNone: I18n.t(
|
translatedNone: I18n.t(
|
||||||
"discourse_subscriptions.subscribe.cardholder_address.province"
|
"discourse_subscriptions.subscribe.cardholder_address.province"
|
||||||
),
|
),
|
||||||
},
|
})
|
||||||
|
@pluginApiIdentifiers("subscribe-ca-province-select")
|
||||||
|
@classNames("subscribe-address-state-select")
|
||||||
|
export default class SubscribeCaProvinceSelect extends ComboBoxComponent {
|
||||||
|
nameProperty = "name";
|
||||||
|
valueProperty = "value";
|
||||||
|
|
||||||
content: computed(function () {
|
@computed
|
||||||
|
get content() {
|
||||||
return [
|
return [
|
||||||
["AB", "Alberta"],
|
["AB", "Alberta"],
|
||||||
["BC", "British Columbia"],
|
["BC", "British Columbia"],
|
||||||
|
@ -34,5 +39,5 @@ export default ComboBoxComponent.extend({
|
||||||
].map((arr) => {
|
].map((arr) => {
|
||||||
return { value: arr[0], name: arr[1] };
|
return { value: arr[0], name: arr[1] };
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
|
|
||||||
export default Component.extend({
|
export default class SubscribeCard extends Component {
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super(...arguments);
|
super.didInsertElement(...arguments);
|
||||||
this.cardElement.mount("#card-element");
|
this.cardElement.mount("#card-element");
|
||||||
this.setCardElementStyles();
|
this.setCardElementStyles();
|
||||||
},
|
}
|
||||||
|
|
||||||
setCardElementStyles() {
|
setCardElementStyles() {
|
||||||
const root = document.querySelector(":root");
|
const root = document.querySelector(":root");
|
||||||
|
@ -23,9 +23,9 @@ export default Component.extend({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
didDestroyElement() {
|
didDestroyElement() {
|
||||||
this._super(...arguments);
|
super.didDestroyElement(...arguments);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,22 +1,27 @@
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
|
import { classNames } from "@ember-decorators/component";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import ComboBoxComponent from "select-kit/components/combo-box";
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
||||||
|
import {
|
||||||
|
pluginApiIdentifiers,
|
||||||
|
selectKitOptions,
|
||||||
|
} from "select-kit/components/select-kit";
|
||||||
|
|
||||||
export default ComboBoxComponent.extend({
|
@pluginApiIdentifiers("subscribe-country-select")
|
||||||
pluginApiIdentifiers: ["subscribe-country-select"],
|
@selectKitOptions({
|
||||||
classNames: ["subscribe-address-country-select"],
|
|
||||||
nameProperty: "name",
|
|
||||||
valueProperty: "value",
|
|
||||||
|
|
||||||
selectKitOptions: {
|
|
||||||
filterable: true,
|
filterable: true,
|
||||||
allowAny: false,
|
allowAny: false,
|
||||||
translatedNone: I18n.t(
|
translatedNone: I18n.t(
|
||||||
"discourse_subscriptions.subscribe.cardholder_address.country"
|
"discourse_subscriptions.subscribe.cardholder_address.country"
|
||||||
),
|
),
|
||||||
},
|
})
|
||||||
|
@classNames("subscribe-address-country-select")
|
||||||
|
export default class SubscribeCountrySelect extends ComboBoxComponent {
|
||||||
|
nameProperty = "name";
|
||||||
|
valueProperty = "value";
|
||||||
|
|
||||||
content: computed(function () {
|
@computed
|
||||||
|
get content() {
|
||||||
return [
|
return [
|
||||||
["AF", I18n.t("discourse_subscriptions.subscribe.countries.AF")],
|
["AF", I18n.t("discourse_subscriptions.subscribe.countries.AF")],
|
||||||
["AX", I18n.t("discourse_subscriptions.subscribe.countries.AX")],
|
["AX", I18n.t("discourse_subscriptions.subscribe.countries.AX")],
|
||||||
|
@ -270,5 +275,5 @@ export default ComboBoxComponent.extend({
|
||||||
].map((arr) => {
|
].map((arr) => {
|
||||||
return { value: arr[0], name: arr[1] };
|
return { value: arr[0], name: arr[1] };
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,22 +1,27 @@
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
|
import { classNames } from "@ember-decorators/component";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import ComboBoxComponent from "select-kit/components/combo-box";
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
||||||
|
import {
|
||||||
|
pluginApiIdentifiers,
|
||||||
|
selectKitOptions,
|
||||||
|
} from "select-kit/components/select-kit";
|
||||||
|
|
||||||
export default ComboBoxComponent.extend({
|
@pluginApiIdentifiers("subscribe-us-state-select")
|
||||||
pluginApiIdentifiers: ["subscribe-us-state-select"],
|
@selectKitOptions({
|
||||||
classNames: ["subscribe-address-state-select"],
|
|
||||||
nameProperty: "name",
|
|
||||||
valueProperty: "value",
|
|
||||||
|
|
||||||
selectKitOptions: {
|
|
||||||
filterable: true,
|
filterable: true,
|
||||||
allowAny: false,
|
allowAny: false,
|
||||||
translatedNone: I18n.t(
|
translatedNone: I18n.t(
|
||||||
"discourse_subscriptions.subscribe.cardholder_address.state"
|
"discourse_subscriptions.subscribe.cardholder_address.state"
|
||||||
),
|
),
|
||||||
},
|
})
|
||||||
|
@classNames("subscribe-address-state-select")
|
||||||
|
export default class SubscribeUsStateSelect extends ComboBoxComponent {
|
||||||
|
nameProperty = "name";
|
||||||
|
valueProperty = "value";
|
||||||
|
|
||||||
content: computed(function () {
|
@computed
|
||||||
|
get content() {
|
||||||
return [
|
return [
|
||||||
["AL", "Alabama"],
|
["AL", "Alabama"],
|
||||||
["AK", "Alaska"],
|
["AK", "Alaska"],
|
||||||
|
@ -84,5 +89,5 @@ export default ComboBoxComponent.extend({
|
||||||
].map((arr) => {
|
].map((arr) => {
|
||||||
return { value: arr[0], name: arr[1] };
|
return { value: arr[0], name: arr[1] };
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import AdminCoupon from "discourse/plugins/discourse-subscriptions/discourse/models/admin-coupon";
|
import AdminCoupon from "discourse/plugins/discourse-subscriptions/discourse/models/admin-coupon";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsCouponsController extends Controller {
|
||||||
creating: null,
|
creating = null;
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
openCreateForm() {
|
openCreateForm() {
|
||||||
this.set("creating", true);
|
this.set("creating", true);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
closeCreateForm() {
|
closeCreateForm() {
|
||||||
this.set("creating", false);
|
this.set("creating", false);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
createNewCoupon(params) {
|
createNewCoupon(params) {
|
||||||
AdminCoupon.save(params)
|
AdminCoupon.save(params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -19,14 +24,18 @@ export default Controller.extend({
|
||||||
this.send("reloadModel");
|
this.send("reloadModel");
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
deleteCoupon(coupon) {
|
deleteCoupon(coupon) {
|
||||||
AdminCoupon.destroy(coupon)
|
AdminCoupon.destroy(coupon)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.send("reloadModel");
|
this.send("reloadModel");
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
toggleActive(coupon) {
|
toggleActive(coupon) {
|
||||||
const couponData = {
|
const couponData = {
|
||||||
id: coupon.id,
|
id: coupon.id,
|
||||||
|
@ -37,6 +46,5 @@ export default Controller.extend({
|
||||||
this.send("reloadModel");
|
this.send("reloadModel");
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsDashboardController extends Controller {
|
||||||
queryParams: ["order", "descending"],
|
queryParams = ["order", "descending"];
|
||||||
order: null,
|
order = null;
|
||||||
descending: true,
|
descending = true;
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
loadMore() {},
|
loadMore() {}
|
||||||
|
|
||||||
|
@action
|
||||||
orderPayments(order) {
|
orderPayments(order) {
|
||||||
if (order === this.get("order")) {
|
if (order === this.get("order")) {
|
||||||
this.toggleProperty("descending");
|
this.toggleProperty("descending");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("order", order);
|
this.set("order", order);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsPlansIndexController extends Controller {
|
||||||
actions: {
|
@action
|
||||||
editPlan(id) {
|
editPlan(id) {
|
||||||
return DiscourseURL.redirectTo(
|
return DiscourseURL.redirectTo(
|
||||||
`/admin/plugins/discourse-subscriptions/plans/${id}`
|
`/admin/plugins/discourse-subscriptions/plans/${id}`
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsPlansShowController extends Controller {
|
||||||
router: service(),
|
@service router;
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
createPlan() {
|
createPlan() {
|
||||||
if (this.get("model.plan.product_id") === undefined) {
|
if (this.get("model.plan.product_id") === undefined) {
|
||||||
const productID = this.get("model.products.firstObject.id");
|
const productID = this.get("model.products.firstObject.id");
|
||||||
|
@ -15,11 +16,8 @@ export default Controller.extend({
|
||||||
this.get("model.plan")
|
this.get("model.plan")
|
||||||
.save()
|
.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.router.transitionTo(
|
this.router.transitionTo("adminPlugins.discourse-subscriptions.plans");
|
||||||
"adminPlugins.discourse-subscriptions.plans"
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
|
||||||
export default Controller.extend({});
|
export default class AdminPluginsDiscourseSubscriptionsPlansController extends Controller {}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
|
||||||
export default Controller.extend({});
|
export default class AdminPluginsDiscourseSubscriptionsProductsIndexController extends Controller {}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import { alias } from "@ember/object/computed";
|
import { alias } from "@ember/object/computed";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
@ -7,15 +8,15 @@ import discourseComputed from "discourse-common/utils/decorators";
|
||||||
const RECURRING = "recurring";
|
const RECURRING = "recurring";
|
||||||
const ONE_TIME = "one_time";
|
const ONE_TIME = "one_time";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsProductsShowPlansShowController extends Controller {
|
||||||
// Also defined in settings.
|
// Also defined in settings.
|
||||||
selectedCurrency: alias("model.plan.currency"),
|
@alias("model.plan.currency") selectedCurrency;
|
||||||
selectedInterval: alias("model.plan.interval"),
|
@alias("model.plan.interval") selectedInterval;
|
||||||
|
|
||||||
@discourseComputed("model.plan.metadata.group_name")
|
@discourseComputed("model.plan.metadata.group_name")
|
||||||
selectedGroup(groupName) {
|
selectedGroup(groupName) {
|
||||||
return groupName || "no-group";
|
return groupName || "no-group";
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("model.groups")
|
@discourseComputed("model.groups")
|
||||||
availableGroups(groups) {
|
availableGroups(groups) {
|
||||||
|
@ -26,7 +27,7 @@ export default Controller.extend({
|
||||||
},
|
},
|
||||||
...groups,
|
...groups,
|
||||||
];
|
];
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
currencies() {
|
currencies() {
|
||||||
|
@ -43,7 +44,7 @@ export default Controller.extend({
|
||||||
{ id: "JPY", name: "JPY" },
|
{ id: "JPY", name: "JPY" },
|
||||||
{ id: "ZAR", name: "ZAR" },
|
{ id: "ZAR", name: "ZAR" },
|
||||||
];
|
];
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
availableIntervals() {
|
availableIntervals() {
|
||||||
|
@ -53,31 +54,32 @@ export default Controller.extend({
|
||||||
{ id: "month", name: "month" },
|
{ id: "month", name: "month" },
|
||||||
{ id: "year", name: "year" },
|
{ id: "year", name: "year" },
|
||||||
];
|
];
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("model.plan.isNew")
|
@discourseComputed("model.plan.isNew")
|
||||||
planFieldDisabled(isNew) {
|
planFieldDisabled(isNew) {
|
||||||
return !isNew;
|
return !isNew;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("model.product.id")
|
@discourseComputed("model.product.id")
|
||||||
productId(id) {
|
productId(id) {
|
||||||
return id;
|
return id;
|
||||||
},
|
}
|
||||||
|
|
||||||
redirect(product_id) {
|
redirect(product_id) {
|
||||||
DiscourseURL.redirectTo(
|
DiscourseURL.redirectTo(
|
||||||
`/admin/plugins/discourse-subscriptions/products/${product_id}`
|
`/admin/plugins/discourse-subscriptions/products/${product_id}`
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
changeRecurring() {
|
changeRecurring() {
|
||||||
const recurring = this.get("model.plan.isRecurring");
|
const recurring = this.get("model.plan.isRecurring");
|
||||||
this.set("model.plan.type", recurring ? ONE_TIME : RECURRING);
|
this.set("model.plan.type", recurring ? ONE_TIME : RECURRING);
|
||||||
this.set("model.plan.isRecurring", !recurring);
|
this.set("model.plan.isRecurring", !recurring);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
createPlan() {
|
createPlan() {
|
||||||
if (this.model.plan.metadata.group_name === "no-group") {
|
if (this.model.plan.metadata.group_name === "no-group") {
|
||||||
this.set("model.plan.metadata.group_name", null);
|
this.set("model.plan.metadata.group_name", null);
|
||||||
|
@ -86,8 +88,9 @@ export default Controller.extend({
|
||||||
.save()
|
.save()
|
||||||
.then(() => this.redirect(this.productId))
|
.then(() => this.redirect(this.productId))
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
updatePlan() {
|
updatePlan() {
|
||||||
if (this.model.plan.metadata.group_name === "no-group") {
|
if (this.model.plan.metadata.group_name === "no-group") {
|
||||||
this.set("model.plan.metadata.group_name", null);
|
this.set("model.plan.metadata.group_name", null);
|
||||||
|
@ -96,6 +99,5 @@ export default Controller.extend({
|
||||||
.update()
|
.update()
|
||||||
.then(() => this.redirect(this.productId))
|
.then(() => this.redirect(this.productId))
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsProductsShowController extends Controller {
|
||||||
router: service(),
|
@service router;
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
cancelProduct() {
|
cancelProduct() {
|
||||||
this.router.transitionTo("adminPlugins.discourse-subscriptions.products");
|
this.router.transitionTo("adminPlugins.discourse-subscriptions.products");
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
createProduct() {
|
createProduct() {
|
||||||
this.get("model.product")
|
this.get("model.product")
|
||||||
.save()
|
.save()
|
||||||
|
@ -20,8 +22,9 @@ export default Controller.extend({
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
updateProduct() {
|
updateProduct() {
|
||||||
this.get("model.product")
|
this.get("model.product")
|
||||||
.update()
|
.update()
|
||||||
|
@ -31,6 +34,5 @@ export default Controller.extend({
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -5,10 +5,11 @@ import I18n from "discourse-i18n";
|
||||||
import AdminCancelSubscription from "../components/modal/admin-cancel-subscription";
|
import AdminCancelSubscription from "../components/modal/admin-cancel-subscription";
|
||||||
import AdminSubscription from "../models/admin-subscription";
|
import AdminSubscription from "../models/admin-subscription";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsSubscriptionsController extends Controller {
|
||||||
modal: service(),
|
@service modal;
|
||||||
dialog: service(),
|
@service dialog;
|
||||||
loading: false,
|
|
||||||
|
loading = false;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
showCancelModal(subscription) {
|
showCancelModal(subscription) {
|
||||||
|
@ -18,7 +19,7 @@ export default Controller.extend({
|
||||||
cancelSubscription: this.cancelSubscription,
|
cancelSubscription: this.cancelSubscription,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
loadMore() {
|
loadMore() {
|
||||||
|
@ -34,7 +35,7 @@ export default Controller.extend({
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
cancelSubscription(model) {
|
cancelSubscription(model) {
|
||||||
|
@ -56,5 +57,5 @@ export default Controller.extend({
|
||||||
subscription.set("loading", false);
|
subscription.set("loading", false);
|
||||||
closeModal();
|
closeModal();
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -7,24 +7,24 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class AdminPluginsDiscourseSubscriptionsController extends Controller {
|
||||||
loading: false,
|
@service dialog;
|
||||||
dialog: service(),
|
loading = false;
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
stripeConfigured() {
|
stripeConfigured() {
|
||||||
return !!this.siteSettings.discourse_subscriptions_public_key;
|
return !!this.siteSettings.discourse_subscriptions_public_key;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
campaignEnabled() {
|
campaignEnabled() {
|
||||||
return this.siteSettings.discourse_subscriptions_campaign_enabled;
|
return this.siteSettings.discourse_subscriptions_campaign_enabled;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
campaignProductSet() {
|
campaignProductSet() {
|
||||||
return !!this.siteSettings.discourse_subscriptions_campaign_product;
|
return !!this.siteSettings.discourse_subscriptions_campaign_product;
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
triggerManualRefresh() {
|
triggerManualRefresh() {
|
||||||
|
@ -35,7 +35,7 @@ export default Controller.extend({
|
||||||
I18n.t("discourse_subscriptions.campaign.refresh_page")
|
I18n.t("discourse_subscriptions.campaign.refresh_page")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
createOneClickCampaign() {
|
createOneClickCampaign() {
|
||||||
|
@ -62,5 +62,5 @@ export default Controller.extend({
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ import Controller from "@ember/controller";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class SubscribeIndexController extends Controller {
|
||||||
@discourseComputed()
|
@discourseComputed()
|
||||||
isLoggedIn() {
|
isLoggedIn() {
|
||||||
return User.current();
|
return User.current();
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* global Stripe */
|
/* global Stripe */
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import { not } from "@ember/object/computed";
|
import { not } from "@ember/object/computed";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
@ -7,25 +8,28 @@ import I18n from "I18n";
|
||||||
import Subscription from "discourse/plugins/discourse-subscriptions/discourse/models/subscription";
|
import Subscription from "discourse/plugins/discourse-subscriptions/discourse/models/subscription";
|
||||||
import Transaction from "discourse/plugins/discourse-subscriptions/discourse/models/transaction";
|
import Transaction from "discourse/plugins/discourse-subscriptions/discourse/models/transaction";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class SubscribeShowController extends Controller {
|
||||||
dialog: service(),
|
@service dialog;
|
||||||
router: service(),
|
@service router;
|
||||||
selectedPlan: null,
|
|
||||||
promoCode: null,
|
selectedPlan = null;
|
||||||
cardholderName: null,
|
promoCode = null;
|
||||||
cardholderAddress: {
|
cardholderName = null;
|
||||||
|
cardholderAddress = {
|
||||||
line1: null,
|
line1: null,
|
||||||
city: null,
|
city: null,
|
||||||
state: null,
|
state: null,
|
||||||
country: null,
|
country: null,
|
||||||
postalCode: null,
|
postalCode: null,
|
||||||
},
|
};
|
||||||
isAnonymous: not("currentUser"),
|
|
||||||
isCountryUS: false,
|
@not("currentUser") isAnonymous;
|
||||||
isCountryCA: false,
|
|
||||||
|
isCountryUS = false;
|
||||||
|
isCountryCA = false;
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
super.init(...arguments);
|
||||||
this.set(
|
this.set(
|
||||||
"stripe",
|
"stripe",
|
||||||
Stripe(this.siteSettings.discourse_subscriptions_public_key)
|
Stripe(this.siteSettings.discourse_subscriptions_public_key)
|
||||||
|
@ -36,11 +40,11 @@ export default Controller.extend({
|
||||||
|
|
||||||
this.set("isCountryUS", this.cardholderAddress.country === "US");
|
this.set("isCountryUS", this.cardholderAddress.country === "US");
|
||||||
this.set("isCountryCA", this.cardholderAddress.country === "CA");
|
this.set("isCountryCA", this.cardholderAddress.country === "CA");
|
||||||
},
|
}
|
||||||
|
|
||||||
alert(path) {
|
alert(path) {
|
||||||
this.dialog.alert(I18n.t(`discourse_subscriptions.${path}`));
|
this.dialog.alert(I18n.t(`discourse_subscriptions.${path}`));
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("model.product.repurchaseable", "model.product.subscribed")
|
@discourseComputed("model.product.repurchaseable", "model.product.subscribed")
|
||||||
canPurchase(repurchaseable, subscribed) {
|
canPurchase(repurchaseable, subscribed) {
|
||||||
|
@ -49,7 +53,7 @@ export default Controller.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
|
|
||||||
createSubscription(plan) {
|
createSubscription(plan) {
|
||||||
return this.stripe
|
return this.stripe
|
||||||
|
@ -77,7 +81,7 @@ export default Controller.extend({
|
||||||
return subscription.save();
|
return subscription.save();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
handleAuthentication(plan, transaction) {
|
handleAuthentication(plan, transaction) {
|
||||||
return this.stripe
|
return this.stripe
|
||||||
|
@ -94,7 +98,7 @@ export default Controller.extend({
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
_advanceSuccessfulTransaction(plan) {
|
_advanceSuccessfulTransaction(plan) {
|
||||||
this.alert("plans.success");
|
this.alert("plans.success");
|
||||||
|
@ -106,19 +110,21 @@ export default Controller.extend({
|
||||||
: "user.billing.payments",
|
: "user.billing.payments",
|
||||||
this.currentUser.username.toLowerCase()
|
this.currentUser.username.toLowerCase()
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
changeCountry(country) {
|
changeCountry(country) {
|
||||||
this.set("cardholderAddress.country", country);
|
this.set("cardholderAddress.country", country);
|
||||||
this.set("isCountryUS", country === "US");
|
this.set("isCountryUS", country === "US");
|
||||||
this.set("isCountryCA", country === "CA");
|
this.set("isCountryCA", country === "CA");
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
changeState(stateOrProvince) {
|
changeState(stateOrProvince) {
|
||||||
this.set("cardholderAddress.state", stateOrProvince);
|
this.set("cardholderAddress.state", stateOrProvince);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
stripePaymentHandler() {
|
stripePaymentHandler() {
|
||||||
this.set("loading", true);
|
this.set("loading", true);
|
||||||
const plan = this.get("model.plans")
|
const plan = this.get("model.plans")
|
||||||
|
@ -163,20 +169,15 @@ export default Controller.extend({
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
this.dialog.alert(result.error.message || result.error);
|
this.dialog.alert(result.error.message || result.error);
|
||||||
} else if (
|
} else if (result.status === "incomplete" || result.status === "open") {
|
||||||
result.status === "incomplete" ||
|
|
||||||
result.status === "open"
|
|
||||||
) {
|
|
||||||
const transactionId = result.id;
|
const transactionId = result.id;
|
||||||
const planId = this.selectedPlan;
|
const planId = this.selectedPlan;
|
||||||
this.handleAuthentication(plan, result).then(
|
this.handleAuthentication(plan, result).then(
|
||||||
(authenticationResult) => {
|
(authenticationResult) => {
|
||||||
if (authenticationResult && !authenticationResult.error) {
|
if (authenticationResult && !authenticationResult.error) {
|
||||||
return Transaction.finalize(transactionId, planId).then(
|
return Transaction.finalize(transactionId, planId).then(() => {
|
||||||
() => {
|
|
||||||
this._advanceSuccessfulTransaction(plan);
|
this._advanceSuccessfulTransaction(plan);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -190,6 +191,5 @@ export default Controller.extend({
|
||||||
);
|
);
|
||||||
this.set("loading", false);
|
this.set("loading", false);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
|
||||||
export default Controller.extend({});
|
export default class SubscribeController extends Controller {}
|
||||||
|
|
|
@ -3,16 +3,18 @@ import { computed } from "@ember/object";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class SubscriptionsController extends Controller {
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
super.init(...arguments);
|
||||||
if (this.currentUser) {
|
if (this.currentUser) {
|
||||||
this.currentUser
|
this.currentUser
|
||||||
.checkEmail()
|
.checkEmail()
|
||||||
.then(() => this.set("email", this.currentUser.email));
|
.then(() => this.set("email", this.currentUser.email));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
pricingTable: computed("email", function () {
|
|
||||||
|
@computed("email")
|
||||||
|
get pricingTable() {
|
||||||
try {
|
try {
|
||||||
const pricingTableId =
|
const pricingTableId =
|
||||||
this.siteSettings.discourse_subscriptions_pricing_table_id;
|
this.siteSettings.discourse_subscriptions_pricing_table_id;
|
||||||
|
@ -39,5 +41,5 @@ export default Controller.extend({
|
||||||
} catch {
|
} catch {
|
||||||
return I18n.t("discourse_subscriptions.subscribe.no_products");
|
return I18n.t("discourse_subscriptions.subscribe.no_products");
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@ import { ajax } from "discourse/lib/ajax";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class UserBillingSubscriptionsCardController extends Controller {
|
||||||
dialog: service(),
|
@service dialog;
|
||||||
|
|
||||||
loading: false,
|
loading = false;
|
||||||
saved: false,
|
saved = false;
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
super.init(...arguments);
|
||||||
this.set(
|
this.set(
|
||||||
"stripe",
|
"stripe",
|
||||||
Stripe(this.siteSettings.discourse_subscriptions_public_key)
|
Stripe(this.siteSettings.discourse_subscriptions_public_key)
|
||||||
);
|
);
|
||||||
const elements = this.get("stripe").elements();
|
const elements = this.get("stripe").elements();
|
||||||
this.set("cardElement", elements.create("card", { hidePostalCode: true }));
|
this.set("cardElement", elements.create("card", { hidePostalCode: true }));
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async updatePaymentMethod() {
|
async updatePaymentMethod() {
|
||||||
|
@ -56,5 +56,5 @@ export default Controller.extend({
|
||||||
this.set("loading", false);
|
this.set("loading", false);
|
||||||
this.cardElement?.clear();
|
this.cardElement?.clear();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -2,19 +2,8 @@ import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const AdminCoupon = EmberObject.extend({
|
export default class AdminCoupon extends EmberObject {
|
||||||
@discourseComputed("coupon.amount_off", "coupon.percent_off")
|
static list() {
|
||||||
discount(amount_off, percent_off) {
|
|
||||||
if (amount_off) {
|
|
||||||
return `${parseFloat(amount_off * 0.01).toFixed(2)}`;
|
|
||||||
} else if (percent_off) {
|
|
||||||
return `${percent_off}%`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
AdminCoupon.reopenClass({
|
|
||||||
list() {
|
|
||||||
return ajax("/s/admin/coupons", {
|
return ajax("/s/admin/coupons", {
|
||||||
method: "get",
|
method: "get",
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
|
@ -23,8 +12,9 @@ AdminCoupon.reopenClass({
|
||||||
}
|
}
|
||||||
return result.map((coupon) => AdminCoupon.create(coupon));
|
return result.map((coupon) => AdminCoupon.create(coupon));
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
save(params) {
|
|
||||||
|
static save(params) {
|
||||||
const data = {
|
const data = {
|
||||||
promo: params.promo,
|
promo: params.promo,
|
||||||
discount_type: params.discount_type,
|
discount_type: params.discount_type,
|
||||||
|
@ -36,9 +26,9 @@ AdminCoupon.reopenClass({
|
||||||
method: "post",
|
method: "post",
|
||||||
data,
|
data,
|
||||||
}).then((coupon) => AdminCoupon.create(coupon));
|
}).then((coupon) => AdminCoupon.create(coupon));
|
||||||
},
|
}
|
||||||
|
|
||||||
update(params) {
|
static update(params) {
|
||||||
const data = {
|
const data = {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
active: params.active,
|
active: params.active,
|
||||||
|
@ -48,9 +38,9 @@ AdminCoupon.reopenClass({
|
||||||
method: "put",
|
method: "put",
|
||||||
data,
|
data,
|
||||||
}).then((coupon) => AdminCoupon.create(coupon));
|
}).then((coupon) => AdminCoupon.create(coupon));
|
||||||
},
|
}
|
||||||
|
|
||||||
destroy(params) {
|
static destroy(params) {
|
||||||
const data = {
|
const data = {
|
||||||
coupon_id: params.coupon.id,
|
coupon_id: params.coupon.id,
|
||||||
};
|
};
|
||||||
|
@ -58,7 +48,14 @@ AdminCoupon.reopenClass({
|
||||||
method: "delete",
|
method: "delete",
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
||||||
export default AdminCoupon;
|
@discourseComputed("coupon.amount_off", "coupon.percent_off")
|
||||||
|
discount(amount_off, percent_off) {
|
||||||
|
if (amount_off) {
|
||||||
|
return `${parseFloat(amount_off * 0.01).toFixed(2)}`;
|
||||||
|
} else if (percent_off) {
|
||||||
|
return `${percent_off}%`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,13 +2,25 @@ import { ajax } from "discourse/lib/ajax";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
||||||
|
|
||||||
const AdminPlan = Plan.extend({
|
export default class AdminPlan extends Plan {
|
||||||
isNew: false,
|
static findAll(data) {
|
||||||
name: "",
|
return ajax("/s/admin/plans", { method: "get", data }).then((result) =>
|
||||||
interval: "month",
|
result.map((plan) => AdminPlan.create(plan))
|
||||||
unit_amount: 0,
|
);
|
||||||
intervals: ["day", "week", "month", "year"],
|
}
|
||||||
metadata: {},
|
|
||||||
|
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 = {};
|
||||||
|
|
||||||
@discourseComputed("trial_period_days")
|
@discourseComputed("trial_period_days")
|
||||||
parseTrialPeriodDays(trialDays) {
|
parseTrialPeriodDays(trialDays) {
|
||||||
|
@ -17,7 +29,7 @@ const AdminPlan = Plan.extend({
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -33,7 +45,7 @@ const AdminPlan = Plan.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
return ajax("/s/admin/plans", { method: "post", data });
|
return ajax("/s/admin/plans", { method: "post", data });
|
||||||
},
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -44,21 +56,5 @@ const AdminPlan = Plan.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
return ajax(`/s/admin/plans/${this.id}`, { method: "patch", data });
|
return ajax(`/s/admin/plans/${this.id}`, { method: "patch", data });
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
AdminPlan.reopenClass({
|
|
||||||
findAll(data) {
|
|
||||||
return ajax("/s/admin/plans", { method: "get", data }).then((result) =>
|
|
||||||
result.map((plan) => AdminPlan.create(plan))
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
find(id) {
|
|
||||||
return ajax(`/s/admin/plans/${id}`, { method: "get" }).then((plan) =>
|
|
||||||
AdminPlan.create(plan)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default AdminPlan;
|
|
||||||
|
|
|
@ -1,13 +1,28 @@
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
const AdminProduct = EmberObject.extend({
|
export default class AdminProduct extends EmberObject {
|
||||||
isNew: false,
|
static findAll() {
|
||||||
metadata: {},
|
return ajax("/s/admin/products", { method: "get" }).then((result) => {
|
||||||
|
if (result === null) {
|
||||||
|
return { unconfigured: true };
|
||||||
|
}
|
||||||
|
return result.map((product) => AdminProduct.create(product));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static find(id) {
|
||||||
|
return ajax(`/s/admin/products/${id}`, {
|
||||||
|
method: "get",
|
||||||
|
}).then((product) => AdminProduct.create(product));
|
||||||
|
}
|
||||||
|
|
||||||
|
isNew = false;
|
||||||
|
metadata = {};
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
return ajax(`/s/admin/products/${this.id}`, { method: "delete" });
|
return ajax(`/s/admin/products/${this.id}`, { method: "delete" });
|
||||||
},
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -21,7 +36,7 @@ const AdminProduct = EmberObject.extend({
|
||||||
method: "post",
|
method: "post",
|
||||||
data,
|
data,
|
||||||
}).then((product) => AdminProduct.create(product));
|
}).then((product) => AdminProduct.create(product));
|
||||||
},
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -35,24 +50,5 @@ const AdminProduct = EmberObject.extend({
|
||||||
method: "patch",
|
method: "patch",
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
AdminProduct.reopenClass({
|
|
||||||
findAll() {
|
|
||||||
return ajax("/s/admin/products", { method: "get" }).then((result) => {
|
|
||||||
if (result === null) {
|
|
||||||
return { unconfigured: true };
|
|
||||||
}
|
}
|
||||||
return result.map((product) => AdminProduct.create(product));
|
}
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
find(id) {
|
|
||||||
return ajax(`/s/admin/products/${id}`, {
|
|
||||||
method: "get",
|
|
||||||
}).then((product) => AdminProduct.create(product));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default AdminProduct;
|
|
||||||
|
|
|
@ -3,35 +3,8 @@ import { ajax } from "discourse/lib/ajax";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const AdminSubscription = EmberObject.extend({
|
export default class AdminSubscription extends EmberObject {
|
||||||
@discourseComputed("status")
|
static find() {
|
||||||
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,
|
|
||||||
};
|
|
||||||
return ajax(`/s/admin/subscriptions/${this.id}`, {
|
|
||||||
method: "delete",
|
|
||||||
data,
|
|
||||||
}).then((result) => AdminSubscription.create(result));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
AdminSubscription.reopenClass({
|
|
||||||
find() {
|
|
||||||
return ajax("/s/admin/subscriptions", {
|
return ajax("/s/admin/subscriptions", {
|
||||||
method: "get",
|
method: "get",
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
|
@ -43,8 +16,9 @@ AdminSubscription.reopenClass({
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
loadMore(lastRecord) {
|
|
||||||
|
static loadMore(lastRecord) {
|
||||||
return ajax(`/s/admin/subscriptions?last_record=${lastRecord}`, {
|
return ajax(`/s/admin/subscriptions?last_record=${lastRecord}`, {
|
||||||
method: "get",
|
method: "get",
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
|
@ -53,7 +27,30 @@ AdminSubscription.reopenClass({
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
||||||
export default AdminSubscription;
|
@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,
|
||||||
|
};
|
||||||
|
return ajax(`/s/admin/subscriptions/${this.id}`, {
|
||||||
|
method: "delete",
|
||||||
|
data,
|
||||||
|
}).then((result) => AdminSubscription.create(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,26 +1,24 @@
|
||||||
import EmberObject, { computed } from "@ember/object";
|
import EmberObject, { computed } from "@ember/object";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const Plan = EmberObject.extend({
|
export default class Plan extends EmberObject {
|
||||||
amountDollars: computed("unit_amount", {
|
@computed("unit_amount")
|
||||||
get() {
|
get amountDollars() {
|
||||||
return parseFloat(this.get("unit_amount") / 100).toFixed(2);
|
return parseFloat(this.get("unit_amount") / 100).toFixed(2);
|
||||||
},
|
}
|
||||||
set(key, value) {
|
|
||||||
|
set amountDollars(value) {
|
||||||
const decimal = parseFloat(value) * 100;
|
const decimal = parseFloat(value) * 100;
|
||||||
this.set("unit_amount", decimal);
|
this.set("unit_amount", decimal);
|
||||||
return value;
|
}
|
||||||
},
|
|
||||||
}),
|
|
||||||
@discourseComputed("recurring.interval")
|
@discourseComputed("recurring.interval")
|
||||||
billingInterval(interval) {
|
billingInterval(interval) {
|
||||||
return interval || "one-time";
|
return interval || "one-time";
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("amountDollars", "currency", "billingInterval")
|
@discourseComputed("amountDollars", "currency", "billingInterval")
|
||||||
subscriptionRate(amountDollars, currency, interval) {
|
subscriptionRate(amountDollars, currency, interval) {
|
||||||
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
export default Plan;
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
const Product = EmberObject.extend({});
|
export default class Product extends EmberObject {
|
||||||
|
static findAll() {
|
||||||
Product.reopenClass({
|
|
||||||
findAll() {
|
|
||||||
return ajax("/s", { method: "get" }).then((result) =>
|
return ajax("/s", { method: "get" }).then((result) =>
|
||||||
result.map((product) => Product.create(product))
|
result.map((product) => Product.create(product))
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
export default Product;
|
|
||||||
|
|
|
@ -2,11 +2,15 @@ import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const Subscription = EmberObject.extend({
|
export default class Subscription extends EmberObject {
|
||||||
|
static show(id) {
|
||||||
|
return ajax(`/s/${id}`, { method: "get" });
|
||||||
|
}
|
||||||
|
|
||||||
@discourseComputed("status")
|
@discourseComputed("status")
|
||||||
canceled(status) {
|
canceled(status) {
|
||||||
return status === "canceled";
|
return status === "canceled";
|
||||||
},
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -18,13 +22,5 @@ const Subscription = EmberObject.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
return ajax("/s/create", { method: "post", data });
|
return ajax("/s/create", { method: "post", data });
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Subscription.reopenClass({
|
|
||||||
show(id) {
|
|
||||||
return ajax(`/s/${id}`, { method: "get" });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Subscription;
|
|
||||||
|
|
|
@ -2,21 +2,17 @@ import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
const UserPayment = EmberObject.extend({
|
export default class UserPayment extends EmberObject {
|
||||||
@discourseComputed("amount")
|
static findAll() {
|
||||||
amountDollars(amount) {
|
|
||||||
return parseFloat(amount / 100).toFixed(2);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
UserPayment.reopenClass({
|
|
||||||
findAll() {
|
|
||||||
return ajax("/s/user/payments", { method: "get" }).then((result) =>
|
return ajax("/s/user/payments", { method: "get" }).then((result) =>
|
||||||
result.map((payment) => {
|
result.map((payment) => {
|
||||||
return UserPayment.create(payment);
|
return UserPayment.create(payment);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
||||||
export default UserPayment;
|
@discourseComputed("amount")
|
||||||
|
amountDollars(amount) {
|
||||||
|
return parseFloat(amount / 100).toFixed(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,11 +4,20 @@ import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
||||||
|
|
||||||
const UserSubscription = EmberObject.extend({
|
export default class UserSubscription extends EmberObject {
|
||||||
|
static findAll() {
|
||||||
|
return ajax("/s/user/subscriptions", { method: "get" }).then((result) =>
|
||||||
|
result.map((subscription) => {
|
||||||
|
subscription.plan = Plan.create(subscription.plan);
|
||||||
|
return UserSubscription.create(subscription);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@discourseComputed("status")
|
@discourseComputed("status")
|
||||||
canceled(status) {
|
canceled(status) {
|
||||||
return status === "canceled";
|
return status === "canceled";
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("current_period_end", "canceled_at")
|
@discourseComputed("current_period_end", "canceled_at")
|
||||||
endDate(current_period_end, canceled_at) {
|
endDate(current_period_end, canceled_at) {
|
||||||
|
@ -17,7 +26,7 @@ const UserSubscription = EmberObject.extend({
|
||||||
} else {
|
} else {
|
||||||
return I18n.t("discourse_subscriptions.user.subscriptions.cancelled");
|
return I18n.t("discourse_subscriptions.user.subscriptions.cancelled");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("discount")
|
@discourseComputed("discount")
|
||||||
discounted(discount) {
|
discounted(discount) {
|
||||||
|
@ -33,24 +42,11 @@ const UserSubscription = EmberObject.extend({
|
||||||
} else {
|
} else {
|
||||||
return I18n.t("no_value");
|
return I18n.t("no_value");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
return ajax(`/s/user/subscriptions/${this.id}`, {
|
return ajax(`/s/user/subscriptions/${this.id}`, {
|
||||||
method: "delete",
|
method: "delete",
|
||||||
}).then((result) => UserSubscription.create(result));
|
}).then((result) => UserSubscription.create(result));
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
UserSubscription.reopenClass({
|
|
||||||
findAll() {
|
|
||||||
return ajax("/s/user/subscriptions", { method: "get" }).then((result) =>
|
|
||||||
result.map((subscription) => {
|
|
||||||
subscription.plan = Plan.create(subscription.plan);
|
|
||||||
return UserSubscription.create(subscription);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default UserSubscription;
|
|
||||||
|
|
|
@ -2,13 +2,13 @@ import { action } from "@ember/object";
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import AdminCoupon from "discourse/plugins/discourse-subscriptions/discourse/models/admin-coupon";
|
import AdminCoupon from "discourse/plugins/discourse-subscriptions/discourse/models/admin-coupon";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsCouponsRoute extends Route {
|
||||||
model() {
|
model() {
|
||||||
return AdminCoupon.list();
|
return AdminCoupon.list();
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
reloadModel() {
|
reloadModel() {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsPlansIndexRoute extends Route {
|
||||||
model() {
|
model() {
|
||||||
return AdminPlan.findAll();
|
return AdminPlan.findAll();
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
|
||||||
export default Route.extend({});
|
export default class AdminPluginsDiscourseSubscriptionsPlansRoute extends Route {}
|
||||||
|
|
|
@ -4,12 +4,12 @@ import { service } from "@ember/service";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
|
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsProductsIndexRoute extends Route {
|
||||||
dialog: service(),
|
@service dialog;
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
return AdminProduct.findAll();
|
return AdminProduct.findAll();
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
destroyProduct(product) {
|
destroyProduct(product) {
|
||||||
|
@ -32,5 +32,5 @@ export default Route.extend({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { hash } from "rsvp";
|
||||||
import Group from "discourse/models/group";
|
import Group from "discourse/models/group";
|
||||||
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsProductsShowPlansShowRoute extends Route {
|
||||||
model(params) {
|
model(params) {
|
||||||
const id = params["plan-id"];
|
const id = params["plan-id"];
|
||||||
const product = this.modelFor(
|
const product = this.modelFor(
|
||||||
|
@ -35,7 +35,7 @@ export default Route.extend({
|
||||||
const groups = Group.findAll({ ignore_automatic: true });
|
const groups = Group.findAll({ ignore_automatic: true });
|
||||||
|
|
||||||
return hash({ plan, product, groups });
|
return hash({ plan, product, groups });
|
||||||
},
|
}
|
||||||
|
|
||||||
renderTemplate() {
|
renderTemplate() {
|
||||||
this.render(
|
this.render(
|
||||||
|
@ -47,5 +47,5 @@ export default Route.extend({
|
||||||
"adminPlugins.discourse-subscriptions.products.show.plans.show",
|
"adminPlugins.discourse-subscriptions.products.show.plans.show",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -6,8 +6,9 @@ import I18n from "I18n";
|
||||||
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
|
||||||
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
|
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsProductsShowRoute extends Route {
|
||||||
dialog: service(),
|
@service dialog;
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
const product_id = params["product-id"];
|
const product_id = params["product-id"];
|
||||||
let product;
|
let product;
|
||||||
|
@ -21,7 +22,7 @@ export default Route.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash({ plans, product });
|
return hash({ plans, product });
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
destroyPlan(plan) {
|
destroyPlan(plan) {
|
||||||
|
@ -42,5 +43,5 @@ export default Route.extend({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
|
||||||
export default Route.extend({});
|
export default class AdminPluginsDiscourseSubscriptionsProductsRoute extends Route {}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import AdminSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/admin-subscription";
|
import AdminSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/admin-subscription";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsSubscriptionsRoute extends Route {
|
||||||
model() {
|
model() {
|
||||||
return AdminSubscription.find();
|
return AdminSubscription.find();
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ import { action } from "@ember/object";
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class AdminPluginsDiscourseSubscriptionsRoute extends Route {
|
||||||
router: service(),
|
@service router;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
showSettings() {
|
showSettings() {
|
||||||
|
@ -15,5 +15,5 @@ export default Route.extend({
|
||||||
controller.set("_skipBounce", true);
|
controller.set("_skipBounce", true);
|
||||||
controller.filterContentNow("plugins");
|
controller.filterContentNow("plugins");
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ import Route from "@ember/routing/route";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import Product from "discourse/plugins/discourse-subscriptions/discourse/models/product";
|
import Product from "discourse/plugins/discourse-subscriptions/discourse/models/product";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class SubscribeIndexRoute extends Route {
|
||||||
router: service(),
|
@service router;
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
return Product.findAll();
|
return Product.findAll();
|
||||||
},
|
}
|
||||||
|
|
||||||
afterModel(products) {
|
afterModel(products) {
|
||||||
if (products.length === 1) {
|
if (products.length === 1) {
|
||||||
|
@ -22,5 +22,5 @@ export default Route.extend({
|
||||||
this.router.transitionTo("subscribe.show", product.id);
|
this.router.transitionTo("subscribe.show", product.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/pla
|
||||||
import Product from "discourse/plugins/discourse-subscriptions/discourse/models/product";
|
import Product from "discourse/plugins/discourse-subscriptions/discourse/models/product";
|
||||||
import Subscription from "discourse/plugins/discourse-subscriptions/discourse/models/subscription";
|
import Subscription from "discourse/plugins/discourse-subscriptions/discourse/models/subscription";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class SubscribeShowRoute extends Route {
|
||||||
model(params) {
|
model(params) {
|
||||||
const product_id = params["subscription-id"];
|
const product_id = params["subscription-id"];
|
||||||
|
|
||||||
|
@ -15,5 +15,5 @@ export default Route.extend({
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class UserBillingIndexRoute extends Route {
|
||||||
router: service(),
|
@service router;
|
||||||
templateName: "user/billing/index",
|
|
||||||
|
templateName = "user/billing/index";
|
||||||
|
|
||||||
redirect() {
|
redirect() {
|
||||||
this.router.transitionTo("user.billing.subscriptions.index");
|
this.router.transitionTo("user.billing.subscriptions.index");
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import UserPayment from "discourse/plugins/discourse-subscriptions/discourse/models/user-payment";
|
import UserPayment from "discourse/plugins/discourse-subscriptions/discourse/models/user-payment";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class UserBillingPaymentsRoute extends Route {
|
||||||
templateName: "user/billing/payments",
|
templateName = "user/billing/payments";
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
return UserPayment.findAll();
|
return UserPayment.findAll();
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class UserBillingSubscriptionsCardRoute extends Route {
|
||||||
model(params) {
|
model(params) {
|
||||||
return params["stripe-subscription-id"];
|
return params["stripe-subscription-id"];
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -4,17 +4,19 @@ import { service } from "@ember/service";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription";
|
import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class UserBillingSubscriptionsIndexRoute extends Route {
|
||||||
dialog: service(),
|
@service dialog;
|
||||||
router: service(),
|
@service router;
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
return UserSubscription.findAll();
|
return UserSubscription.findAll();
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
updateCard(subscriptionId) {
|
updateCard(subscriptionId) {
|
||||||
this.router.transitionTo("user.billing.subscriptions.card", subscriptionId);
|
this.router.transitionTo("user.billing.subscriptions.card", subscriptionId);
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
cancelSubscription(subscription) {
|
cancelSubscription(subscription) {
|
||||||
this.dialog.yesNoConfirm({
|
this.dialog.yesNoConfirm({
|
||||||
|
@ -36,5 +38,5 @@ export default Route.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
|
||||||
export default Route.extend();
|
export default class UserBillingSubscriptionsRoute extends Route {}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
|
|
||||||
export default Route.extend({
|
export default class UserBillingRoute extends Route {
|
||||||
router: service(),
|
@service router;
|
||||||
|
|
||||||
templateName: "user/billing",
|
templateName = "user/billing";
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
if (this.currentUser.id !== this.modelFor("user").id) {
|
if (this.currentUser.id !== this.modelFor("user").id) {
|
||||||
|
@ -12,5 +12,5 @@ export default Route.extend({
|
||||||
} else {
|
} else {
|
||||||
controller.setProperties({ model });
|
controller.setProperties({ model });
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
Loading…
Reference in New Issue