From f2123d07db9e2eb0eb02f2acff95cc870f184e46 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Fri, 7 May 2021 12:20:43 +0100 Subject: [PATCH] Added support for un/archiving Prices https://github.com/TryGhost/Team/issues/665 We update both Stripe and our database based on the `active` flag for existing stripe prices. --- .../lib/repositories/product/index.js | 10 ++++++++-- .../lib/services/stripe-api/index.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ghost/members-api/lib/repositories/product/index.js b/ghost/members-api/lib/repositories/product/index.js index ff8afb1dad..7876e4577c 100644 --- a/ghost/members-api/lib/repositories/product/index.js +++ b/ghost/members-api/lib/repositories/product/index.js @@ -217,13 +217,19 @@ class ProductRepository { interval: existingPrice.interval }, options); } else { - await this._StripePrice.edit({ + const updated = await this._StripePrice.edit({ nickname: existingPrice.nickname, - description: existingPrice.description + description: existingPrice.description, + active: existingPrice.active }, { ...options, id: stripePrice.id }); + + await this._stripeAPIService.updatePrice(updated.get('stripe_price_id'), { + nickname: updated.get('nickname'), + active: updated.get('active') + }); } } diff --git a/ghost/members-api/lib/services/stripe-api/index.js b/ghost/members-api/lib/services/stripe-api/index.js index 985ec9ed98..04c8967c2d 100644 --- a/ghost/members-api/lib/services/stripe-api/index.js +++ b/ghost/members-api/lib/services/stripe-api/index.js @@ -118,6 +118,24 @@ module.exports = class StripeAPIService { return price; } + /** + * @param {string} id + * @param {object} options + * @param {boolean} options.active + * @param {string} options.nickname + * + * @returns {Promise} + */ + async updatePrice(id, options) { + await this._rateLimitBucket.throttle(); + const price = await this._stripe.prices.update(id, { + active: options.active, + nickname: options.nickname + }); + + return price; + } + /** * ensureProduct. *