mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
|
const _ = require('lodash');
|
||
|
const logging = require('@tryghost/logging');
|
||
|
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({
|
||
|
logger: logging,
|
||
|
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, 600);
|
||
|
|
||
|
module.exports = {
|
||
|
async init() {
|
||
|
configureApi();
|
||
|
events.on('settings.edited', function (model) {
|
||
|
if (!stripeKeySettings.includes(model.get('key'))) {
|
||
|
return;
|
||
|
}
|
||
|
debouncedConfigureApi();
|
||
|
events.emit('services.stripe.reconfigured');
|
||
|
});
|
||
|
},
|
||
|
|
||
|
api
|
||
|
};
|