From c8933c9abde8b0c8a6d9d214ba5e7d8b76f03e6d Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Thu, 7 Oct 2021 18:13:17 +0200 Subject: [PATCH] Fixed handling of null currency & used duration no-issue Currency is not always present on an offer so we need to handle it. Duration was incorrectly not passed to Stripe when creating the coupon. --- ghost/offers/lib/OfferRepository.js | 4 ++-- ghost/offers/lib/domain/models/Offer.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ghost/offers/lib/OfferRepository.js b/ghost/offers/lib/OfferRepository.js index ad91f780fb..b1d7af614b 100644 --- a/ghost/offers/lib/OfferRepository.js +++ b/ghost/offers/lib/OfferRepository.js @@ -123,7 +123,7 @@ class OfferRepository { interval: offer.cadence.value, product_id: offer.tier.id, duration: offer.duration.value, - currency: offer.currency.value + currency: offer.currency ? offer.currency.value : null }); if (offer.codeChanged || offer.isNew) { @@ -139,7 +139,7 @@ class OfferRepository { /** @type {import('stripe').Stripe.CouponCreateParams} */ const coupon = { name: offer.name.value, - duration: 'once' + duration: offer.duration.value }; if (offer.type.value === 'percent') { diff --git a/ghost/offers/lib/domain/models/Offer.js b/ghost/offers/lib/domain/models/Offer.js index 63595bf1f9..2bcdc78a2e 100644 --- a/ghost/offers/lib/domain/models/Offer.js +++ b/ghost/offers/lib/domain/models/Offer.js @@ -22,7 +22,7 @@ const OfferCurrency = require('./OfferCurrency'); * @prop {OfferType} type * @prop {OfferAmount} amount * @prop {OfferDuration} duration - * @prop {OfferCurrency} currency + * @prop {OfferCurrency} [currency] * @prop {string} [stripe_coupon_id] * @prop {OfferTier} tier */