0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Removed unused stripe-plans service

no-issue

This module is no longer used!
This commit is contained in:
Fabien O'Carroll 2021-05-10 15:40:47 +01:00
parent 45d338730c
commit 15b535fd45
3 changed files with 2 additions and 112 deletions

View file

@ -4,7 +4,6 @@ const MagicLink = require('@tryghost/magic-link');
const common = require('./lib/common');
const StripeAPIService = require('./lib/services/stripe-api');
const StripePlansService = require('./lib/services/stripe-plans');
const StripeWebhookService = require('./lib/services/stripe-webhook');
const TokenService = require('./lib/services/token');
const GeolocationSerice = require('./lib/services/geolocation');
@ -77,10 +76,6 @@ module.exports = function MembersApi({
logger
});
const stripePlansService = new StripePlansService({
stripeAPIService
});
const productRepository = new ProductRepository({
Product,
StripeProduct,
@ -90,7 +85,6 @@ module.exports = function MembersApi({
const memberRepository = new MemberRepository({
stripeAPIService,
stripePlansService,
logger,
productRepository,
Member,
@ -114,7 +108,7 @@ module.exports = function MembersApi({
const stripeWebhookService = new StripeWebhookService({
StripeWebhook,
stripeAPIService,
stripePlansService,
productRepository,
memberRepository,
eventRepository,
sendEmailWithMagicLink
@ -161,11 +155,6 @@ module.exports = function MembersApi({
});
const ready = paymentConfig.stripe ? Promise.all([
stripePlansService.configure({
product: stripeConfig.product,
plans: stripeConfig.plans,
mode: process.env.NODE_ENV || 'development'
}),
stripeMigrations.populateProductsAndPrices().then(() => {
return stripeMigrations.populateStripePricesFromStripePlansSetting(stripeConfig.plans);
}).then(() => {

View file

@ -204,6 +204,7 @@ class ProductRepository {
}, options);
}
const stripePrice = await this._StripePrice.findOne({stripe_price_id: existingPrice.stripe_price_id}, options);
if (!stripePrice) {
await this._StripePrice.add({
stripe_price_id: existingPrice.stripe_price_id,

View file

@ -1,100 +0,0 @@
/**
* @typedef {'usd'|'aud'|'cad'|'gbp'|'eur'|'inr'} Currency
*/
module.exports = class StripeService {
/**
* @param {object} deps
* @param {import('../stripe-api')} deps.stripeAPIService
*/
constructor({
stripeAPIService
}) {
this._stripeAPIService = stripeAPIService;
this._configured = false;
/** @type {import('stripe').Stripe.Product} */
this._product = null;
/** @type {import('stripe').Stripe.Plan[]} */
this._plans = null;
}
/**
* @returns {import('stripe').Stripe.Product}
*/
getProduct() {
if (!this._configured) {
throw new Error('StripeService has not been configured');
}
return this._product;
}
/**
* @returns {import('stripe').Stripe.Plan[]}
*/
getPlans() {
if (!this._configured) {
throw new Error('StripeService has not been configured');
}
return this._plans;
}
/**
* @param {string} nickname
* @returns {import('stripe').Stripe.Plan}
*/
getPlan(nickname) {
if (!this._configured) {
throw new Error('StripeService has not been configured');
}
return this.getPlans().find((plan) => {
return plan.nickname.toLowerCase() === nickname.toLowerCase();
});
}
/**
* @param {Currency} currency
* @returns {import('stripe').Stripe.Plan}
*/
getComplimentaryPlan(currency) {
if (!this._configured) {
throw new Error('StripeService has not been configured');
}
return this.getPlans().find((plan) => {
return plan.nickname.toLowerCase() === 'complimentary' && plan.currency === currency;
});
}
/**
* @param {object} config
* @param {object} config.product - The name for the product
* @param {string} config.product.name - The name for the product
*
* @param {object[]} config.plans
* @param {string} config.plans[].name
* @param {Currency} config.plans[].currency
* @param {'year'|'month'} config.plans[].interval
* @param {string} config.plans[].amount
*
* @returns {Promise<void>}
*/
async configure(config) {
if (config.mode !== 'production' && this._stripeAPIService.mode === 'live') {
const error = new Error('Cannot use live Stripe keys in development mode. Please restart in production mode.');
error.fatal = true;
throw error;
}
try {
const product = await this._stripeAPIService.ensureProduct(config.product.name);
this._product = product;
this._plans = [];
for (const planSpec of config.plans) {
const plan = await this._stripeAPIService.ensurePlan(planSpec, product);
this._plans.push(plan);
}
this._configured = true;
} catch (err) {
console.log(err);
}
}
};