2023-07-09 05:17:06 +08:00
|
|
|
import Controller from "@ember/controller";
|
2024-04-24 10:09:53 -06:00
|
|
|
import { computed } from "@ember/object";
|
2023-07-13 14:17:19 +08:00
|
|
|
import { htmlSafe } from "@ember/template";
|
2023-07-09 05:17:06 +08:00
|
|
|
import I18n from "I18n";
|
|
|
|
|
|
|
|
|
|
export default Controller.extend({
|
2023-07-13 14:17:19 +08:00
|
|
|
init() {
|
|
|
|
|
// Perform any initialization logic here
|
|
|
|
|
this._super(...arguments);
|
|
|
|
|
// Additional custom initialization code
|
|
|
|
|
if (this.currentUser) {
|
|
|
|
|
this.currentUser
|
|
|
|
|
.checkEmail()
|
|
|
|
|
.then(() => this.set("email", this.currentUser.email));
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-04-24 10:09:53 -06:00
|
|
|
pricingTable: computed("email", function () {
|
2023-07-13 14:17:19 +08:00
|
|
|
try {
|
|
|
|
|
const pricing_table_info = JSON.parse(
|
|
|
|
|
this.siteSettings.discourse_subscriptions_pricing_table
|
|
|
|
|
);
|
|
|
|
|
if (this.currentUser) {
|
|
|
|
|
return htmlSafe(`<stripe-pricing-table
|
2023-07-09 05:17:06 +08:00
|
|
|
pricing-table-id="${pricing_table_info.pricingTableId}"
|
|
|
|
|
publishable-key="${pricing_table_info.publishableKey}"
|
2023-07-13 14:17:19 +08:00
|
|
|
customer-email="${this.email}"></stripe-pricing-table>`);
|
|
|
|
|
} else {
|
|
|
|
|
return htmlSafe(`<stripe-pricing-table
|
2023-07-09 05:17:06 +08:00
|
|
|
pricing-table-id="${pricing_table_info.pricingTableId}"
|
|
|
|
|
publishable-key="${pricing_table_info.publishableKey}"
|
2023-07-13 14:17:19 +08:00
|
|
|
></stripe-pricing-table>`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return I18n.t("discourse_subscriptions.subscribe.no_products");
|
|
|
|
|
}
|
|
|
|
|
}),
|
2023-07-09 05:17:06 +08:00
|
|
|
});
|