diff --git a/ghost/payments/lib/payments.js b/ghost/payments/lib/payments.js index e6c40f1021..b24df82a02 100644 --- a/ghost/payments/lib/payments.js +++ b/ghost/payments/lib/payments.js @@ -214,8 +214,9 @@ class PaymentsService { stripe_product_id: product.id, currency, interval: cadence, - amount - }).query().select('stripe_price_id'); + amount, + active: true + }).query().select('id', 'stripe_price_id'); for (const row of rows) { try { @@ -224,9 +225,15 @@ class PaymentsService { return { id: price.id }; + } else { + // Update the database model to prevent future Stripe fetches when it is not needed + await this.StripePriceModel.edit({ + active: !!price.active + }, {id: row.id}); } } catch (err) { - logging.warn(err); + logging.error(`Failed to lookup Stripe Price ${row.stripe_price_id}`); + logging.error(err); } } diff --git a/ghost/stripe/lib/StripeAPI.js b/ghost/stripe/lib/StripeAPI.js index 7a09083402..b5ae3be4ed 100644 --- a/ghost/stripe/lib/StripeAPI.js +++ b/ghost/stripe/lib/StripeAPI.js @@ -1,5 +1,5 @@ const {VersionMismatchError} = require('@tryghost/errors'); -const debug = require('@tryghost/debug'); +const debug = require('@tryghost/debug')('stripe'); const Stripe = require('stripe').Stripe; const LeakyBucket = require('leaky-bucket'); const EXPECTED_API_EFFICIENCY = 0.95;