2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Added price data to templates (#11259)

no-issue

This is p. damn hacky!!
This exports `{{@price.monthly}}` and `{{@price.yearly}}` to the theme
so that we can have dynamic payment pages
This commit is contained in:
Fabien O'Carroll 2019-10-21 17:50:54 +07:00 committed by GitHub
parent 1114f85d66
commit 95543b0461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}
});