From e78b2f80bc7c2cd8abdfdc3cd5540b7c416af098 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Thu, 21 Oct 2021 18:06:36 +0200 Subject: [PATCH] Fixed issues with checkout when not using coupon no-issue We were incorrectly checking for the existence of a coupon id - instead we simplify the signature, and make sure the check is correct. --- ghost/members-api/lib/controllers/router.js | 4 ++-- ghost/members-stripe-service/lib/StripeService.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ghost/members-api/lib/controllers/router.js b/ghost/members-api/lib/controllers/router.js index 2b76cfbfcf..98a48969c6 100644 --- a/ghost/members-api/lib/controllers/router.js +++ b/ghost/members-api/lib/controllers/router.js @@ -196,7 +196,7 @@ module.exports = class RouterController { if (!member) { const customer = null; const session = await this._stripeAPIService.createCheckoutSession(priceId, customer, { - coupon: {id: couponId}, + coupon: couponId, successUrl: req.body.successUrl || this._config.checkoutSuccessUrl, cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl, customerEmail: req.body.customerEmail, @@ -241,7 +241,7 @@ module.exports = class RouterController { try { const session = await this._stripeAPIService.createCheckoutSession(priceId, stripeCustomer, { - coupon: {id: couponId}, + coupon: couponId, successUrl: req.body.successUrl || this._config.checkoutSuccessUrl, cancelUrl: req.body.cancelUrl || this._config.checkoutCancelUrl, metadata: metadata diff --git a/ghost/members-stripe-service/lib/StripeService.js b/ghost/members-stripe-service/lib/StripeService.js index 6d3362c07e..0b0363c903 100644 --- a/ghost/members-stripe-service/lib/StripeService.js +++ b/ghost/members-stripe-service/lib/StripeService.js @@ -351,6 +351,7 @@ module.exports = class StripeService { * @param {string} options.successUrl * @param {string} options.cancelUrl * @param {string} options.customerEmail + * @param {string} [options.coupon] * * @returns {Promise} */ @@ -360,7 +361,7 @@ module.exports = class StripeService { await this._rateLimitBucket.throttle(); let discounts; if (options.coupon) { - discounts = [{coupon: options.coupon.id}]; + discounts = [{coupon: options.coupon}]; } const session = await this._stripe.checkout.sessions.create({ payment_method_types: ['card'],