From c0512e30bb6e5e3f2d3d86a3ca04b0273d405447 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Wed, 4 Mar 2020 13:15:21 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20custom=20currency=20support?= =?UTF-8?q?=20for=20Memer's=20plans?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - Multiple currencies for membe plans were supported under the hood but never had a clear interface to manage them. This change allows to reference currently used currency and it's symbol from the theme layer with following syntax: `{{@price.currency}}` and `{{@price.currency_symbol}} --- core/frontend/services/themes/middleware.js | 16 +++++++++++++++- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/frontend/services/themes/middleware.js b/core/frontend/services/themes/middleware.js index 78ec2e18cd..06b682739e 100644 --- a/core/frontend/services/themes/middleware.js +++ b/core/frontend/services/themes/middleware.js @@ -46,7 +46,18 @@ function ensureActiveTheme(req, res, next) { * members settings as publicly readable */ function haxGetMembersPriceData() { - const defaultPriceData = {monthly: 0, yearly: 0}; + const CURRENCY_SYMBOLS = { + USD: '$', + AUD: '$', + CAD: '$', + GBP: '£', + EUR: '€' + }; + const defaultPriceData = { + monthly: 0, + yearly: 0 + }; + try { const membersSettings = settingsCache.get('members_subscription_settings'); const stripeProcessor = membersSettings.paymentProcessors.find( @@ -61,6 +72,9 @@ function haxGetMembersPriceData() { }); }, {}); + priceData.currency = String.prototype.toUpperCase.call(stripeProcessor.config.currency || 'usd'); + priceData.currency_symbol = CURRENCY_SYMBOLS[priceData.currency]; + if (Number.isInteger(priceData.monthly) && Number.isInteger(priceData.yearly)) { return priceData; } diff --git a/package.json b/package.json index 016bd60b48..6bd4d4a18b 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@nexes/nql": "0.3.0", "@sentry/node": "5.13.1", "@tryghost/helpers": "1.1.22", - "@tryghost/members-api": "0.17.0", + "@tryghost/members-api": "0.18.0", "@tryghost/members-ssr": "0.7.4", "@tryghost/social-urls": "0.1.5", "@tryghost/string": "^0.1.3", diff --git a/yarn.lock b/yarn.lock index eb94e77e75..6e97ca3af3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -330,10 +330,10 @@ jsonwebtoken "^8.5.1" lodash "^4.17.15" -"@tryghost/members-api@0.17.0": - version "0.17.0" - resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.17.0.tgz#effa17432e6f46e29b7b6091513acc391bede51e" - integrity sha512-p0PLHKyBDWcq6hxrhbf02hR3MLYFDfTI3YnEAGkN9FAC7Q9b44zuTJIxh4MEurlJBFB3Fl5eidQOaO1sfSv15Q== +"@tryghost/members-api@0.18.0": + version "0.18.0" + resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.18.0.tgz#7a7bd1b36d793c65f3cb687ff52649c79c6c7114" + integrity sha512-aymN/i26GHCQI8TtoAyHejJjPrsl+PYSaFTvIq+O57F/Gg8uAH7EJCXKQYUoZKz/95VbpwE3o7QdRWpRMBjEDg== dependencies: "@tryghost/magic-link" "^0.4.1" bluebird "^3.5.4"