2024-04-29 12:47:58 -06:00
|
|
|
import Controller from "@ember/controller";
|
|
|
|
|
import { computed } from "@ember/object";
|
|
|
|
|
import { htmlSafe } from "@ember/template";
|
2025-02-06 16:57:53 +00:00
|
|
|
import { i18n } from "discourse-i18n";
|
2024-04-29 12:47:58 -06:00
|
|
|
|
2024-11-29 15:42:50 +00:00
|
|
|
export default class SubscriptionsController extends Controller {
|
2024-04-29 12:47:58 -06:00
|
|
|
init() {
|
2024-11-29 15:42:50 +00:00
|
|
|
super.init(...arguments);
|
2024-04-29 12:47:58 -06:00
|
|
|
if (this.currentUser) {
|
|
|
|
|
this.currentUser
|
|
|
|
|
.checkEmail()
|
|
|
|
|
.then(() => this.set("email", this.currentUser.email));
|
|
|
|
|
}
|
2024-11-29 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@computed("email")
|
|
|
|
|
get pricingTable() {
|
2024-04-29 12:47:58 -06:00
|
|
|
try {
|
|
|
|
|
const pricingTableId =
|
|
|
|
|
this.siteSettings.discourse_subscriptions_pricing_table_id;
|
|
|
|
|
const publishableKey =
|
|
|
|
|
this.siteSettings.discourse_subscriptions_public_key;
|
|
|
|
|
const pricingTableEnabled =
|
|
|
|
|
this.siteSettings.discourse_subscriptions_pricing_table_enabled;
|
|
|
|
|
|
|
|
|
|
if (!pricingTableEnabled || !pricingTableId || !publishableKey) {
|
|
|
|
|
throw new Error("Pricing table not configured");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.currentUser) {
|
|
|
|
|
return htmlSafe(`<stripe-pricing-table
|
|
|
|
|
pricing-table-id="${pricingTableId}"
|
|
|
|
|
publishable-key="${publishableKey}"
|
|
|
|
|
customer-email="${this.email}"></stripe-pricing-table>`);
|
|
|
|
|
} else {
|
|
|
|
|
return htmlSafe(`<stripe-pricing-table
|
|
|
|
|
pricing-table-id="${pricingTableId}"
|
|
|
|
|
publishable-key="${publishableKey}"
|
|
|
|
|
></stripe-pricing-table>`);
|
|
|
|
|
}
|
2024-11-19 10:31:14 +00:00
|
|
|
} catch {
|
2025-02-06 16:57:53 +00:00
|
|
|
return i18n("discourse_subscriptions.subscribe.no_products");
|
2024-04-29 12:47:58 -06:00
|
|
|
}
|
2024-11-29 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
}
|