diff --git a/core/frontend/services/themes/middleware.js b/core/frontend/services/themes/middleware.js index 1e9fd8f28e..1ffca7f8f8 100644 --- a/core/frontend/services/themes/middleware.js +++ b/core/frontend/services/themes/middleware.js @@ -39,6 +39,37 @@ function ensureActiveTheme(req, res, next) { next(); } +/* + * @TODO + * This should be definitely refactored and we need to consider _some_ + * members settings as publicly readable + */ +function haxGetMembersPriceData() { + const defaultPriceData = {monthly: 0, yearly: 0}; + try { + const membersSettings = settingsCache.get('members_subscription_settings'); + const stripeProcessor = membersSettings.paymentProcessors.find( + processor => processor.adapter === 'stripe' + ); + + const priceData = stripeProcessor.config.plans.reduce((prices, plan) => { + const numberAmount = 0 + plan.amount; + const dollarAmount = numberAmount ? Math.round(numberAmount / 100) : 0; + return Object.assign(prices, { + [plan.name.toLowerCase()]: dollarAmount + }); + }, {}); + + if (Number.isInteger(priceData.monthly) && Number.isInteger(priceData.yearly)) { + return priceData; + } + + return defaultPriceData; + } catch (err) { + return defaultPriceData; + } +} + function updateGlobalTemplateOptions(req, res, next) { // Static information, same for every request unless the settings change // @TODO: bind this once and then update based on events? @@ -49,6 +80,7 @@ function updateGlobalTemplateOptions(req, res, next) { posts_per_page: activeTheme.get().config('posts_per_page'), image_sizes: activeTheme.get().config('image_sizes') }; + const priceData = haxGetMembersPriceData(); // @TODO: only do this if something changed? // @TODO: remove blog if we drop v2 (Ghost 4.0) @@ -57,7 +89,8 @@ function updateGlobalTemplateOptions(req, res, next) { blog: siteData, site: siteData, labs: labsData, - config: themeData + config: themeData, + price: priceData } });