Ghost/core/server/services/offers/service.js
Fabien 'egg' O'Carroll a565da06b2
🐛 Fixed Offer Redemptions being over counted (#13988)
refs https://github.com/TryGhost/Team/issues/1257

Offer Redemptions were being overcounted due to the way we were updating
Stripe configuration for the Members service. We would create a new
instance of the members-api, which would have event handlers for
creating Offer Redemptions - by creating a new instance each time Stripe
config changed, we would overcount them.

Here we've pulled out Stripe related logic into the Stripe service, and
updated it internally - rather than creating a new instance. This means
that we've been able to remove all of the logic for re-instantiating the
members-api.

- Bumped members-api & stripe-service
- Removed reinstantiation of members-api
- Used stripe service to execute migrations
- Updated Stripe Service to handle webhooks & migrations
- Used webhook controller from stripe service
- Used disconnect method from stripe service
- Removed unused stripe dependency
- Removed Stripe webhook config from members-api
2022-01-18 17:56:47 +02:00

32 lines
909 B
JavaScript

const DynamicRedirectManager = require('@tryghost/express-dynamic-redirects');
const OffersModule = require('@tryghost/members-offers');
const config = require('../../../shared/config');
const urlUtils = require('../../../shared/url-utils');
const models = require('../../models');
const redirectManager = new DynamicRedirectManager({
permanentMaxAge: config.get('caching:customRedirects:maxAge'),
getSubdirectoryURL: (pathname) => {
return urlUtils.urlJoin(urlUtils.getSubdir(), pathname);
}
});
module.exports = {
async init() {
const offersModule = OffersModule.create({
OfferModel: models.Offer,
OfferRedemptionModel: models.OfferRedemption,
redirectManager: redirectManager
});
this.api = offersModule.api;
await offersModule.init();
},
api: null,
middleware: redirectManager.handleRequest
};