Ghost/core/server/services/members/index.js
Fabien O'Carroll f63577fa4f
Implemented stripe checkout handling for members
no-issue

* Installed members-api@0.5.0 members-ssr@0.3.1
* Supported multiple members-forms
* Used members canary api
* Added GET handler to /members/ssr for id token
The identity token will be used to ensure that a payment is linked to the correct member
* Added stripe.js to ghost_head when members enabled
* Added basic support for linking to stripe checkout
* Removed listener to title and icon settings changes
* Added stripe subscription config
2019-09-06 15:14:21 +08:00

52 lines
1.6 KiB
JavaScript

const MembersSSR = require('@tryghost/members-ssr');
const createMembersApiInstance = require('./api');
const common = require('../../lib/common');
const urlUtils = require('../../lib/url-utils');
const settingsCache = require('../settings/cache');
let membersApi;
// Bind to events to automatically keep subscription info up-to-date from settings
common.events.on('settings.edited', function updateSettingFromModel(settingModel) {
if (!['members_subscription_settings'].includes(settingModel.get('key'))) {
return;
}
const reconfiguredMembersAPI = createMembersApiInstance();
reconfiguredMembersAPI.bus.on('ready', function () {
membersApi = reconfiguredMembersAPI;
});
reconfiguredMembersAPI.bus.on('error', function (err) {
common.logging.error(err);
});
});
const membersService = {
isPaymentConfigured() {
const settings = settingsCache.get('members_subscription_settings');
return !!settings && settings.isPaid && settings.paymentProcessors.length !== 0;
},
get api() {
if (!membersApi) {
membersApi = createMembersApiInstance();
membersApi.bus.on('error', function (err) {
common.logging.error(err);
});
}
return membersApi;
},
ssr: MembersSSR({
cookieSecure: urlUtils.isSSL(urlUtils.getSiteUrl()),
cookieKeys: [settingsCache.get('theme_session_secret')],
// This is passed as a function so that updates to the instance
// are picked up in the ssr module
membersApi: () => membersApi
})
};
module.exports = membersService;