mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
6ce441f760
refs https://github.com/TryGhost/Team/issues/1322 We no longer restart the Members service based on the Stripe service being updated, which meant that if it was initially configured with missing URL's and later Stripe connected, it would not get the new config until a server restart. This moves the last of Stripe config into the Stripe service, so that all things concerning Stripe can be handled in one place and updated together.
87 lines
2.8 KiB
JavaScript
87 lines
2.8 KiB
JavaScript
const WebhookManager = require('./WebhookManager');
|
|
const StripeAPI = require('./StripeAPI');
|
|
const StripeMigrations = require('./Migrations');
|
|
const WebhookController = require('./WebhookController');
|
|
|
|
module.exports = class StripeService {
|
|
constructor({
|
|
membersService,
|
|
StripeWebhook,
|
|
models
|
|
}) {
|
|
const api = new StripeAPI();
|
|
const webhookManager = new WebhookManager({
|
|
StripeWebhook,
|
|
api
|
|
});
|
|
const migrations = new StripeMigrations({
|
|
models,
|
|
api
|
|
});
|
|
const webhookController = new WebhookController({
|
|
webhookManager,
|
|
api,
|
|
get memberRepository(){
|
|
return membersService.api.members;
|
|
},
|
|
get productRepository() {
|
|
return membersService.api.productRepository;
|
|
},
|
|
get eventRepository() {
|
|
return membersService.api.events;
|
|
},
|
|
sendSignupEmail(email){
|
|
return membersService.api.sendEmailWithMagicLink({
|
|
email,
|
|
requestedType: 'signup-paid',
|
|
options: {
|
|
forceEmailType: true
|
|
},
|
|
tokenData: {}
|
|
});
|
|
}
|
|
});
|
|
|
|
this.models = models;
|
|
this.api = api;
|
|
this.webhookManager = webhookManager;
|
|
this.migrations = migrations;
|
|
this.webhookController = webhookController;
|
|
}
|
|
|
|
async connect() {
|
|
}
|
|
|
|
async disconnect() {
|
|
await this.models.Product.forge().query().update({
|
|
monthly_price_id: null,
|
|
yearly_price_id: null
|
|
});
|
|
await this.models.StripePrice.forge().query().del();
|
|
await this.models.StripeProduct.forge().query().del();
|
|
await this.models.MemberStripeCustomer.forge().query().del();
|
|
await this.models.Offer.forge().query().update({
|
|
stripe_coupon_id: null
|
|
});
|
|
await this.webhookManager.stop();
|
|
}
|
|
|
|
async configure(config) {
|
|
this.api.configure({
|
|
secretKey: config.secretKey,
|
|
publicKey: config.publicKey,
|
|
enablePromoCodes: config.enablePromoCodes,
|
|
checkoutSessionSuccessUrl: config.checkoutSessionSuccessUrl,
|
|
checkoutSessionCancelUrl: config.checkoutSessionCancelUrl,
|
|
checkoutSetupSessionSuccessUrl: config.checkoutSetupSessionSuccessUrl,
|
|
checkoutSetupSessionCancelUrl: config.checkoutSetupSessionCancelUrl
|
|
});
|
|
|
|
await this.webhookManager.configure({
|
|
webhookSecret: config.webhookSecret,
|
|
webhookHandlerUrl: config.webhookHandlerUrl
|
|
});
|
|
await this.webhookManager.start();
|
|
}
|
|
};
|