diff --git a/ghost/members-api/lib/services/stripe-api/index.js b/ghost/members-api/lib/services/stripe-api/index.js index 06fbf330f2..67ed57d822 100644 --- a/ghost/members-api/lib/services/stripe-api/index.js +++ b/ghost/members-api/lib/services/stripe-api/index.js @@ -1,19 +1,19 @@ const debug = require('ghost-ignition').debug('services/stripe'); -const Stripe = require('stripe'); +const Stripe = require('stripe').Stripe; const LeakyBucket = require('leaky-bucket'); const EXPECTED_API_EFFICIENCY = 0.95; /** @type {(data: string) => string} */ const hash = data => require('crypto').createHash('sha256').update(data).digest('hex'); -const STRIPE_API_VERSION = '2019-09-09'; +const STRIPE_API_VERSION = '2020-08-27'; /** - * @typedef {import('stripe').IDataOptions} IDataOptions - * @typedef {import('stripe').customers.ICustomer} ICustomer - * @typedef {import('stripe').products.IProduct} IProduct - * @typedef {import('stripe').plans.IPlan} IPlan - * @typedef {import('stripe').webhookEndpoints.IWebhookEndpoint} IWebhookEndpoint + * @typedef {import('stripe').Stripe.Customer} ICustomer + * @typedef {import('stripe').Stripe.Product} IProduct + * @typedef {import('stripe').Stripe.Plan} IPlan + * @typedef {import('stripe').Stripe.Price} IPrice + * @typedef {import('stripe').Stripe.WebhookEndpoint} IWebhookEndpoint */ /** @@ -62,7 +62,9 @@ module.exports = class StripeAPIService { } configure(config) { - this._stripe = new Stripe(config.secretKey); + this._stripe = new Stripe(config.secretKey, { + apiVersion: STRIPE_API_VERSION + }); this._config = config; this._testMode = config.secretKey && config.secretKey.startsWith('sk_test_'); if (this._testMode) { @@ -161,7 +163,7 @@ module.exports = class StripeAPIService { /** * @param {string} id - * @param {IDataOptions} options + * @param {import('stripe').Stripe.CustomerRetrieveParams} options * * @returns {Promise} */ @@ -206,7 +208,7 @@ module.exports = class StripeAPIService { } /** - * @param {IDataOptions} options + * @param {import('stripe').Stripe.CustomerCreateParams} options * * @returns {Promise} */ @@ -246,7 +248,7 @@ module.exports = class StripeAPIService { * createWebhook. * * @param {string} url - * @param {import('stripe').events.EventType[]} events + * @param {import('stripe').Stripe.WebhookEndpointUpdateParams.EnabledEvent[]} events * * @returns {Promise} */ @@ -288,7 +290,7 @@ module.exports = class StripeAPIService { /** * @param {string} id * @param {string} url - * @param {import('stripe').events.EventType[]} events + * @param {import('stripe').Stripe.WebhookEndpointUpdateParams.EnabledEvent[]} events * * @returns {Promise} */ @@ -318,7 +320,7 @@ module.exports = class StripeAPIService { * @param {string} signature * @param {string} secret * - * @returns {import('stripe').events.IEvent} + * @returns {import('stripe').Stripe.Event} */ parseWebhook(body, signature, secret) { debug(`parseWebhook(${body}, ${signature}, ${secret})`); @@ -337,7 +339,7 @@ module.exports = class StripeAPIService { * @param {ICustomer} customer * @param {object} options * - * @returns {Promise} + * @returns {Promise} */ async createCheckoutSession(plan, customer, options) { const metadata = options.metadata || undefined; @@ -366,7 +368,7 @@ module.exports = class StripeAPIService { * @param {ICustomer} customer * @param {object} options * - * @returns {Promise} + * @returns {Promise} */ async createCheckoutSetupSession(customer, options) { await this._rateLimitBucket.throttle(); @@ -394,9 +396,9 @@ module.exports = class StripeAPIService { * getSubscription. * * @param {string} id - * @param {IDataOptions} options + * @param {import('stripe').Stripe.SubscriptionRetrieveParams} options * - * @returns {Promise} + * @returns {Promise} */ async getSubscription(id, options = {}) { debug(`getSubscription(${id}, ${JSON.stringify(options)})`); @@ -416,7 +418,7 @@ module.exports = class StripeAPIService { * * @param {string} id * - * @returns {Promise} + * @returns {Promise} */ async cancelSubscription(id) { debug(`cancelSubscription(${id})`); @@ -435,7 +437,7 @@ module.exports = class StripeAPIService { * @param {string} id - The ID of the Subscription to modify * @param {string} [reason=''] - The user defined cancellation reason * - * @returns {Promise} + * @returns {Promise} */ async cancelSubscriptionAtPeriodEnd(id, reason = '') { await this._rateLimitBucket.throttle(); @@ -451,7 +453,7 @@ module.exports = class StripeAPIService { /** * @param {string} id - The ID of the Subscription to modify * - * @returns {Promise} + * @returns {Promise} */ async continueSubscriptionAtPeriodEnd(id) { await this._rateLimitBucket.throttle(); @@ -468,7 +470,7 @@ module.exports = class StripeAPIService { * @param {string} id - The ID of the Subscription to modify * @param {string} plan - The ID of the new Plan * - * @returns {Promise} + * @returns {Promise} */ async changeSubscriptionPlan(id, plan) { await this._rateLimitBucket.throttle(); @@ -486,7 +488,7 @@ module.exports = class StripeAPIService { * @param {string} customer - The ID of the Customer to create the subscription for * @param {string} plan - The ID of the new Plan * - * @returns {Promise} + * @returns {Promise} */ async createSubscription(customer, plan) { await this._rateLimitBucket.throttle(); @@ -499,9 +501,9 @@ module.exports = class StripeAPIService { /** * @param {string} id - * @param {IDataOptions} options + * @param {import('stripe').Stripe.SetupIntentRetrieveParams} options * - * @returns {Promise} + * @returns {Promise} */ async getSetupIntent(id, options = {}) { await this._rateLimitBucket.throttle(); @@ -523,7 +525,7 @@ module.exports = class StripeAPIService { /** * @param {string} id * - * @returns {Promise} + * @returns {Promise} */ async getCardPaymentMethod(id) { await this._rateLimitBucket.throttle(); @@ -531,7 +533,7 @@ module.exports = class StripeAPIService { if (paymentMethod.type !== 'card') { return null; } - /** @type {import('stripe').paymentMethods.ICardPaymentMethod} */ + return paymentMethod; } @@ -539,7 +541,7 @@ module.exports = class StripeAPIService { * @param {string} subscription * @param {string} paymentMethod * - * @returns {Promise} + * @returns {Promise} */ async updateSubscriptionDefaultPaymentMethod(subscription, paymentMethod) { await this._rateLimitBucket.throttle(); diff --git a/ghost/members-api/lib/services/stripe-plans/index.js b/ghost/members-api/lib/services/stripe-plans/index.js index 932e53738b..14d0998795 100644 --- a/ghost/members-api/lib/services/stripe-plans/index.js +++ b/ghost/members-api/lib/services/stripe-plans/index.js @@ -12,14 +12,14 @@ module.exports = class StripeService { }) { this._stripeAPIService = stripeAPIService; this._configured = false; - /** @type {import('stripe').products.IProduct} */ + /** @type {import('stripe').Stripe.Product} */ this._product = null; - /** @type {import('stripe').plans.IPlan[]} */ + /** @type {import('stripe').Stripe.Plan[]} */ this._plans = null; } /** - * @returns {import('stripe').products.IProduct} + * @returns {import('stripe').Stripe.Product} */ getProduct() { if (!this._configured) { @@ -29,7 +29,7 @@ module.exports = class StripeService { } /** - * @returns {import('stripe').plans.IPlan[]} + * @returns {import('stripe').Stripe.Plan[]} */ getPlans() { if (!this._configured) { @@ -40,7 +40,7 @@ module.exports = class StripeService { /** * @param {string} nickname - * @returns {import('stripe').plans.IPlan} + * @returns {import('stripe').Stripe.Plan} */ getPlan(nickname) { if (!this._configured) { @@ -53,7 +53,7 @@ module.exports = class StripeService { /** * @param {Currency} currency - * @returns {import('stripe').plans.IPlan} + * @returns {import('stripe').Stripe.Plan} */ getComplimentaryPlan(currency) { if (!this._configured) { diff --git a/ghost/members-api/lib/services/stripe-webhook/index.js b/ghost/members-api/lib/services/stripe-webhook/index.js index 04753a026d..2688401ca3 100644 --- a/ghost/members-api/lib/services/stripe-webhook/index.js +++ b/ghost/members-api/lib/services/stripe-webhook/index.js @@ -50,7 +50,7 @@ module.exports = class StripeWebhookService { throw error; } - /** @type {import('stripe').events.EventType[]} */ + /** @type {import('stripe').Stripe.WebhookEndpointCreateParams.EnabledEvent[]} */ const events = [ 'checkout.session.completed', 'customer.subscription.deleted', @@ -109,14 +109,14 @@ module.exports = class StripeWebhookService { /** * @param {string} body * @param {string} signature - * @returns {import('stripe').events.IEvent} + * @returns {import('stripe').Stripe.Event} */ parseWebhook(body, signature) { return this._stripeAPIService.parseWebhook(body, signature, this._webhookSecret); } /** - * @param {import('stripe').events.IEvent} event + * @param {import('stripe').Stripe.Event} event * * @returns {Promise} */ @@ -142,7 +142,7 @@ module.exports = class StripeWebhookService { } /** - * @param {import('stripe').invoices.IInvoice} invoice + * @param {import('stripe').Stripe.Invoice} invoice * * @returns {Promise} */ diff --git a/ghost/members-api/package.json b/ghost/members-api/package.json index 36d8424b5f..eef32d2873 100644 --- a/ghost/members-api/package.json +++ b/ghost/members-api/package.json @@ -17,7 +17,6 @@ "gateway" ], "devDependencies": { - "@types/stripe": "7.13.24", "jsdom": "15.2.1", "mocha": "6.2.3", "nock": "12.0.3", @@ -37,7 +36,7 @@ "leaky-bucket": "2.2.0", "lodash": "^4.17.11", "node-jose": "^1.1.3", - "stripe": "^7.4.0" + "stripe": "^8.142.0" }, "publishConfig": { "access": "public"