0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/services/stripe/index.js
Sam Lord 97451a93cb
Extract logging from DI patterns, only use @tryghost/logging package
refs: https://github.com/TryGhost/Toolbox/issues/146

Switched to @tryghost/logging instead of passing around the library. The main sticking points of this change are jobs. When jobs are launched we don't want them to use a separate @tryghost/logging instance because they would start parallel rotation jobs. @tryghost/logging v2.x passes all logs to the parent process if run in a child process, so that we can use the same patterns in jobs and the rest of the codebase.
2021-12-06 18:00:55 +00:00

45 lines
1 KiB
JavaScript

const _ = require('lodash');
const StripeAPIService = require('@tryghost/members-stripe-service');
const config = require('../../../shared/config');
const settings = require('../../../shared/settings-cache');
const events = require('../../lib/common/events');
const {getConfig} = require('./config');
const api = new StripeAPIService({
config: {}
});
const stripeKeySettings = [
'stripe_publishable_key',
'stripe_secret_key',
'stripe_connect_publishable_key',
'stripe_connect_secret_key'
];
function configureApi() {
const cfg = getConfig(settings, config);
if (cfg) {
api.configure(cfg);
}
}
const debouncedConfigureApi = _.debounce(() => {
configureApi();
events.emit('services.stripe.reconfigured');
}, 600);
module.exports = {
async init() {
configureApi();
events.on('settings.edited', function (model) {
if (!stripeKeySettings.includes(model.get('key'))) {
return;
}
debouncedConfigureApi();
});
},
api
};