2020-05-22 11:20:05 -05:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
|
import I18n from "I18n";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "setup-subscriptions",
|
|
|
|
|
initialize(container) {
|
2020-09-16 09:53:50 -05:00
|
|
|
withPluginApi("0.8.11", (api) => {
|
2024-01-16 17:51:44 +01:00
|
|
|
const siteSettings = container.lookup("service:site-settings");
|
2020-05-22 11:20:05 -05:00
|
|
|
const isNavLinkEnabled =
|
|
|
|
|
siteSettings.discourse_subscriptions_extra_nav_subscribe;
|
|
|
|
|
if (isNavLinkEnabled) {
|
|
|
|
|
api.addNavigationBarItem({
|
|
|
|
|
name: "subscribe",
|
|
|
|
|
displayName: I18n.t("discourse_subscriptions.navigation.subscribe"),
|
2023-07-09 05:17:06 +08:00
|
|
|
href: "/subscriptions",
|
2020-05-22 11:20:05 -05:00
|
|
|
});
|
|
|
|
|
}
|
2022-08-10 13:05:54 +01:00
|
|
|
|
|
|
|
|
const user = api.getCurrentUser();
|
|
|
|
|
if (user) {
|
|
|
|
|
api.addQuickAccessProfileItem({
|
|
|
|
|
icon: "far-credit-card",
|
|
|
|
|
href: `/u/${user.username}/billing/subscriptions`,
|
|
|
|
|
content: "Billing",
|
|
|
|
|
});
|
2023-07-09 05:17:06 +08:00
|
|
|
|
|
|
|
|
if(user.admin){
|
|
|
|
|
api.modifyClassStatic('model:site-setting', {
|
|
|
|
|
pluginId: 'discourse-subscriptions',
|
|
|
|
|
update(key, value, opts = {}) {
|
|
|
|
|
if(key ==="discourse_subscriptions_pricing_table"){
|
|
|
|
|
const inputString = value;
|
|
|
|
|
// Extract pricing-table-id
|
|
|
|
|
const pricingTableIdRegex = /pricing-table-id="([^"]+)"/;
|
|
|
|
|
const pricingTableIdMatch = inputString.match(pricingTableIdRegex);
|
|
|
|
|
const pricingTableId = pricingTableIdMatch ? pricingTableIdMatch[1] : null;
|
|
|
|
|
|
|
|
|
|
// Extract publishable-key
|
|
|
|
|
const publishableKeyRegex = /publishable-key="([^"]+)"/;
|
|
|
|
|
const publishableKeyMatch = inputString.match(publishableKeyRegex);
|
|
|
|
|
const publishableKey = publishableKeyMatch ? publishableKeyMatch[1] : null;
|
|
|
|
|
if(pricingTableId && publishableKey){
|
|
|
|
|
value = JSON.stringify({pricingTableId,publishableKey})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this._super(key, value, opts);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-10 13:05:54 +01:00
|
|
|
}
|
2020-05-22 11:20:05 -05:00
|
|
|
});
|
2020-09-16 09:53:50 -05:00
|
|
|
},
|
2020-05-22 11:20:05 -05:00
|
|
|
};
|