diff --git a/ghost/members-api/lib/migrations/index.js b/ghost/members-api/lib/migrations/index.js index b0cdccffa7..6a13d36c12 100644 --- a/ghost/members-api/lib/migrations/index.js +++ b/ghost/members-api/lib/migrations/index.js @@ -127,11 +127,11 @@ module.exports = class StripeMigrations { if (!defaultStripeProduct) { this._logging.info('Could not find Stripe Product - creating one'); - const stripeProduct = await this._stripeAPIService.createProduct({ - name: 'Ghost Product' - }); const productsPage = await this._Product.findPage({limit: 1}); const defaultProduct = productsPage.data[0]; + const stripeProduct = await this._stripeAPIService.createProduct({ + name: defaultProduct.get('name') + }); if (!defaultProduct) { this._logging.error('Could not find Product - skipping stripe_plans -> stripe_prices migration'); return; diff --git a/ghost/members-api/lib/repositories/product/index.js b/ghost/members-api/lib/repositories/product/index.js index 34b6ae3fac..51db3806f1 100644 --- a/ghost/members-api/lib/repositories/product/index.js +++ b/ghost/members-api/lib/repositories/product/index.js @@ -176,7 +176,7 @@ class ProductRepository { if (!product.related('stripeProducts').first()) { const stripeProduct = await this._stripeAPIService.createProduct({ - name: productData.name + name: product.get('name') }); await this._StripeProduct.add({ @@ -185,6 +185,13 @@ class ProductRepository { }, options); await product.related('stripeProducts').fetch(options); + } else { + if (product.attributes.name !== product._previousAttributes.name) { + const stripeProduct = product.related('stripeProducts').first(); + await this._stripeAPIService.updateProduct(stripeProduct.get('stripe_product_id'), { + name: product.get('name') + }); + } } const defaultStripeProduct = product.related('stripeProducts').first(); diff --git a/ghost/members-api/lib/services/stripe-api/index.js b/ghost/members-api/lib/services/stripe-api/index.js index 04c8967c2d..f143bd0d51 100644 --- a/ghost/members-api/lib/services/stripe-api/index.js +++ b/ghost/members-api/lib/services/stripe-api/index.js @@ -136,6 +136,22 @@ module.exports = class StripeAPIService { return price; } + /** + * @param {string} id + * @param {object} options + * @param {string} options.name + * + * @returns {Promise} + */ + async updateProduct(id, options) { + await this._rateLimitBucket.throttle(); + const product = await this._stripe.products.update(id, { + name: options.name + }); + + return product; + } + /** * ensureProduct. *