mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
🐛 Fixed upgrading Subscriptions to new Tiers
refs https://github.com/TryGhost/Team/issues/2204 This was found during Tiers flows testing, the logic for fetching price information from Tiers had not been updated to use the new Tiers package and Payments service. This only affects Tiers created since 5.22.x
This commit is contained in:
parent
6989d08b19
commit
65a4eb5eb6
@ -150,14 +150,6 @@ module.exports = function MembersAPI({
|
||||
getSubject
|
||||
});
|
||||
|
||||
const memberController = new MemberController({
|
||||
memberRepository,
|
||||
productRepository,
|
||||
StripePrice,
|
||||
tokenService,
|
||||
sendEmailWithMagicLink
|
||||
});
|
||||
|
||||
const paymentsService = new PaymentsService({
|
||||
StripeProduct,
|
||||
StripePrice,
|
||||
@ -167,6 +159,16 @@ module.exports = function MembersAPI({
|
||||
stripeAPIService
|
||||
});
|
||||
|
||||
const memberController = new MemberController({
|
||||
memberRepository,
|
||||
productRepository,
|
||||
paymentsService,
|
||||
tiersService,
|
||||
StripePrice,
|
||||
tokenService,
|
||||
sendEmailWithMagicLink
|
||||
});
|
||||
|
||||
const routerController = new RouterController({
|
||||
offersAPI,
|
||||
paymentsService,
|
||||
|
@ -5,6 +5,8 @@ module.exports = class MemberController {
|
||||
* @param {object} deps
|
||||
* @param {any} deps.memberRepository
|
||||
* @param {any} deps.productRepository
|
||||
* @param {any} deps.paymentsService
|
||||
* @param {any} deps.tiersService
|
||||
* @param {any} deps.StripePrice
|
||||
* @param {any} deps.tokenService
|
||||
* @param {any} deps.sendEmailWithMagicLink
|
||||
@ -12,12 +14,16 @@ module.exports = class MemberController {
|
||||
constructor({
|
||||
memberRepository,
|
||||
productRepository,
|
||||
paymentsService,
|
||||
tiersService,
|
||||
StripePrice,
|
||||
tokenService,
|
||||
sendEmailWithMagicLink
|
||||
}) {
|
||||
this._memberRepository = memberRepository;
|
||||
this._productRepository = productRepository;
|
||||
this._paymentsService = paymentsService;
|
||||
this._tiersService = tiersService;
|
||||
this._StripePrice = StripePrice;
|
||||
this._tokenService = tokenService;
|
||||
this._sendEmailWithMagicLink = sendEmailWithMagicLink;
|
||||
@ -108,17 +114,17 @@ module.exports = class MemberController {
|
||||
}
|
||||
|
||||
if (tierId && cadence) {
|
||||
const tier = await this._productRepository.get({id: tierId});
|
||||
if (tier) {
|
||||
if (cadence === 'month') {
|
||||
ghostPriceId = tier.get('monthly_price_id');
|
||||
} else {
|
||||
ghostPriceId = tier.get('yearly_price_id');
|
||||
}
|
||||
}
|
||||
}
|
||||
const tier = await this._tiersService.api.read(tierId);
|
||||
const stripePrice = await this._paymentsService.getPriceForTierCadence(tier, cadence);
|
||||
|
||||
if (ghostPriceId !== undefined) {
|
||||
await this._memberRepository.updateSubscription({
|
||||
email,
|
||||
subscription: {
|
||||
subscription_id: subscriptionId,
|
||||
price: stripePrice.id
|
||||
}
|
||||
});
|
||||
} else if (ghostPriceId !== undefined) {
|
||||
const price = await this._StripePrice.findOne({
|
||||
id: ghostPriceId
|
||||
});
|
||||
|
@ -27,6 +27,24 @@ describe('MemberController', function () {
|
||||
})
|
||||
};
|
||||
|
||||
const tier = {
|
||||
id: 'whatever'
|
||||
};
|
||||
|
||||
const price = {
|
||||
id: 'stripe_price_id'
|
||||
};
|
||||
|
||||
const tiersService = {
|
||||
api: {
|
||||
read: sinon.fake.resolves(tier)
|
||||
}
|
||||
};
|
||||
|
||||
const paymentsService = {
|
||||
getPriceForTierCadence: sinon.fake.resolves(price)
|
||||
};
|
||||
|
||||
const productRepository = {
|
||||
get: sinon.fake.resolves({
|
||||
get() {
|
||||
@ -38,6 +56,8 @@ describe('MemberController', function () {
|
||||
const controller = new MemberController({
|
||||
memberRepository,
|
||||
productRepository,
|
||||
tiersService,
|
||||
paymentsService,
|
||||
StripePrice,
|
||||
tokenService
|
||||
});
|
||||
@ -45,7 +65,8 @@ describe('MemberController', function () {
|
||||
const req = {
|
||||
body: {
|
||||
identity: 'token',
|
||||
priceId: 'plan_name'
|
||||
tierId: 'tier_id',
|
||||
cadence: 'yearly'
|
||||
},
|
||||
params: {
|
||||
id: 'subscription_id'
|
||||
|
Loading…
Reference in New Issue
Block a user