Commit Graph

96 Commits

Author SHA1 Message Date
Simon Backx
6ab29c14e4 Fixed OfferCreatedEvent being dispatched before the transaction has been committed (#391)
refs https://github.com/TryGhost/Ghost/pull/14488

**Bug:**
When creating a new offer, sometimes no discount object is created in Stripe (only in MySQL). This issue causes tests to fail in https://github.com/TryGhost/Ghost/pull/14488

**Cause:**
When creating an offer with the OffersAPI, we create a new transaction to save the offer and check for uniqueness. Inside that transaction, we dispatch an OfferCreatedEvent event before the transaction is committed to the database.

When listening for this event in the `members-payments` package, we create the discount object in Stripe and save the stripe_coupon_id to the newly created offer. But because (in most cases) the offer doesn't yet exist in the database, that listener fails without warning and exits early.

**Solution:**
Creating a discount in Stripe should only happen after we succesfully committed the offer to the database. If we don't wait for the commit, the offer often (by chance) won't exist in the database, so the coupon won't be created inside Stripe. The solution is to wait for the transaction to succeed/be committed before dispatching the event.
2022-04-19 12:47:03 +02:00
Simon Backx
d04c34d829 Published new versions
- @tryghost/members-api@5.11.0
 - @tryghost/members-offers@0.11.0
 - @tryghost/members-payments@0.3.0
2022-04-19 11:23:04 +02:00
Simon Backx
41e0aa17ff Updated offer_id matching logic to use stripe_coupon_id instead of metadata (#390)
refs https://github.com/TryGhost/Team/issues/1519

- Removed offer metadata again from offer (added in one of the previous commits)
- Added `getByStripeCouponId` method in offer repository (required to find an offer based on the stripe_coupon_id)
- Match discounts from Stripe based on the stripe_coupon_id instead of metadata
2022-04-19 11:21:48 +02:00
Thibaut Patel
c37021c575 Published new versions
- @tryghost/domain-events@0.1.9
 - @tryghost/express-dynamic-redirects@0.2.7
 - @tryghost/magic-link@1.0.21
 - @tryghost/member-analytics-service@0.1.11
 - @tryghost/member-events@0.4.1
 - @tryghost/members-analytics-ingress@0.1.12
 - @tryghost/members-api@5.3.0
 - @tryghost/members-csv@1.2.7
 - @tryghost/members-events-service@0.3.2
 - @tryghost/members-importer@0.5.4
 - @tryghost/members-ssr@1.0.23
 - @tryghost/members-offers@0.10.9
 - @tryghost/members-payments@0.1.11
 - @tryghost/members-stripe-service@0.9.1
 - @tryghost/verification-trigger@0.1.6
2022-03-11 22:45:26 +01:00
Renovate Bot
0ad973c8b5 Update dependency mocha to v9.2.2 2022-03-11 18:04:58 +00:00
Thibaut Patel
dafda42e0a Published new versions
- @tryghost/domain-events@0.1.8
 - @tryghost/express-dynamic-redirects@0.2.6
 - @tryghost/magic-link@1.0.20
 - @tryghost/member-analytics-service@0.1.10
 - @tryghost/member-events@0.4.0
 - @tryghost/members-analytics-ingress@0.1.11
 - @tryghost/members-api@5.0.4
 - @tryghost/members-csv@1.2.6
 - @tryghost/members-events-service@0.1.0
 - @tryghost/members-importer@0.5.3
 - @tryghost/members-ssr@1.0.22
 - @tryghost/members-offers@0.10.8
 - @tryghost/members-payments@0.1.10
 - @tryghost/members-stripe-service@0.8.4
 - @tryghost/verification-trigger@0.1.5
2022-03-01 10:36:48 +01:00
Daniel Lockyer
db696a9272 Added --all to c8 command
refs https://github.com/TryGhost/Toolbox/issues/203

- without `--all`, c8 ignores files that should be included in the
  coverage score but aren't used in tests
- this means we have artificially high scores in places where this isn't
  used
- this commit adds `--all` where previously missing
- where this fails `--check-coverage`, that has been removed for now
2022-02-21 13:08:55 +01:00
Renovate Bot
d813510a07 Update dependency mocha to v9.2.1 2022-02-21 00:05:27 +00:00
Daniel Lockyer
a0f716f475 Published new versions
- @tryghost/domain-events@0.1.7
 - @tryghost/express-dynamic-redirects@0.2.5
 - @tryghost/magic-link@1.0.18
 - @tryghost/member-analytics-service@0.1.9
 - @tryghost/member-events@0.3.5
 - @tryghost/members-analytics-ingress@0.1.10
 - @tryghost/members-api@5.0.1
 - @tryghost/members-csv@1.2.4
 - @tryghost/members-importer@0.5.1
 - @tryghost/members-ssr@1.0.20
 - @tryghost/members-offers@0.10.7
 - @tryghost/members-payments@0.1.9
 - @tryghost/members-stripe-service@0.8.1
 - @tryghost/verification-trigger@0.1.4
2022-02-15 13:42:23 +01:00
Renovate Bot
463317eb76 Update dependency sinon to v13 2022-02-15 13:39:43 +01:00
Renovate Bot
5e91609abb Update Test & linting packages 2022-02-15 13:35:28 +01:00
Hannah Wolfe
3dcf85d5e4 Ensured correct usage of @tryghost/errors everywhere
refs: 23b383bedf

- @tryghost/error constructors take an object, not a string - the expectation is that message, context & help should all be set
- This does the bare minimum and just ensures message is set correctly
2022-02-15 12:30:36 +00:00
Hannah Wolfe
fbdbd7fd43 Removed @babel/eslint-parser, set ecmaVersion instead
refs: 3a1c51672c

- @babel/eslint-parser was added to enable support for static members on classes but this causes other problems as it fails on eslint ugprades etc
- a better solution is to set ecmaVersion to 2022, as our default is 2018 which does not support static, yet 2022 does
2022-02-15 12:30:17 +00:00
Thibaut Patel
bb1d5de381 Published new versions
- @tryghost/domain-events@0.1.6
 - @tryghost/magic-link@1.0.17
 - @tryghost/member-analytics-service@0.1.7
 - @tryghost/members-analytics-ingress@0.1.8
 - @tryghost/members-api@4.5.0
 - @tryghost/members-ssr@1.0.19
 - @tryghost/members-offers@0.10.6
 - @tryghost/members-payments@0.1.8
2022-01-21 17:57:25 +01:00
renovate[bot]
3b30c71235 Update dependency @babel/eslint-parser to v7.16.5 (#331)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-01-21 15:59:03 +02:00
Fabien "egg" O'Carroll
883945886c Published new versions
- @tryghost/domain-events@0.1.5
 - @tryghost/express-dynamic-redirects@0.2.4
 - @tryghost/magic-link@1.0.16
 - @tryghost/member-analytics-service@0.1.6
 - @tryghost/member-events@0.3.3
 - @tryghost/members-analytics-ingress@0.1.7
 - @tryghost/members-api@4.2.0
 - @tryghost/members-csv@1.2.3
 - @tryghost/members-importer@0.4.1
 - @tryghost/members-ssr@1.0.18
 - @tryghost/members-offers@0.10.5
 - @tryghost/members-payments@0.1.7
 - @tryghost/members-stripe-service@0.6.3
2022-01-20 17:49:29 +02:00
Renovate Bot
233bb828fa Pin dependencies 2022-01-20 15:42:33 +00:00
Renovate Bot
a2bcff314f Update dependency c8 to v7.11.0 2022-01-20 14:30:04 +00:00
Fabien "egg" O'Carroll
379fbc7f13 Published new versions
- @tryghost/domain-events@0.1.4
 - @tryghost/express-dynamic-redirects@0.2.3
 - @tryghost/magic-link@1.0.15
 - @tryghost/member-analytics-service@0.1.5
 - @tryghost/member-events@0.3.2
 - @tryghost/members-analytics-ingress@0.1.6
 - @tryghost/members-api@3.0.0
 - @tryghost/members-csv@1.2.1
 - @tryghost/members-importer@0.3.6
 - @tryghost/members-ssr@1.0.17
 - @tryghost/members-stripe-service@0.5.2
 - @tryghost/members-offers@0.10.4
 - @tryghost/members-payments@0.1.6
2022-01-10 17:56:12 +02:00
John O'Nolan
b7cd251d5c 2022 2022-01-06 10:09:25 +00:00
Fabien O'Carroll
2dc4f3209f Published new versions
- @tryghost/members-api@2.7.5
 - @tryghost/members-offers@0.10.3
 - @tryghost/members-payments@0.1.5
2021-11-25 12:39:34 +02:00
Fabien O'Carroll
3efb2f1f04 Required OfferName to be a maximum of 40 characters
refs https://github.com/TryGhost/Team/issues/1236

We want to be able to use the OfferName as the name property for a
Stripe Coupon - which has a maximum character length of 40.
2021-11-25 12:34:33 +02:00
Fabien O'Carroll
4b005da248 Published new versions
- @tryghost/members-api@2.7.3
 - @tryghost/members-offers@0.10.2
 - @tryghost/members-payments@0.1.4
2021-11-07 23:14:00 +02:00
Fabien O'Carroll
0b9c9968d0 Added initial tests for Offers
refs https://github.com/TryGhost/Team/issues/1198
2021-11-07 23:10:10 +02:00
Fabien O'Carroll
0144ad1f7e Published new versions
- @tryghost/members-api@2.4.4
 - @tryghost/members-offers@0.10.1
 - @tryghost/members-payments@0.1.3
2021-10-22 16:49:55 +02:00
Fabien O'Carroll
668a9d47ba Improved error messages for Offers API
no-issue
2021-10-22 16:48:52 +02:00
Fabien O'Carroll
af1a019f0e Published new versions
- @tryghost/members-api@2.4.3
 - @tryghost/members-offers@0.10.0
 - @tryghost/members-payments@0.1.2
2021-10-22 14:53:16 +02:00
Fabien O'Carroll
a953b530c3 Returned null when updateOffer does not find Offer
no-issue

This is another improvement for the API so that we can correctly handle
404's
2021-10-22 14:43:52 +02:00
Fabien O'Carroll
01a1a83c52 Published new versions
- @tryghost/members-api@2.4.2
 - @tryghost/members-offers@0.9.0
 - @tryghost/members-payments@0.1.1
2021-10-22 14:16:29 +02:00
Fabien O'Carroll
49f325dde4 Handled missing Offer when reading
no-issue

When attempting to read a non-existent offer we were running into issues
with calling toJSON() on `null`. This updates the handling to explicitly
return null - so that the controller can correctly throw a NotFoundError
2021-10-22 14:13:04 +02:00
Fabien O'Carroll
b6234d6e96 Allowed OfferTitle to be empty
refs https://github.com/TryGhost/Team/issues/1163

This allows users to not provide a title for an Offer. We store the lack
of a title as `NULL` in the DB, but we will always provide a string to
the API so that the title can safely be used in HTML.
2021-10-22 13:41:09 +02:00
Fabien O'Carroll
93a37f98be Published new versions
- @tryghost/domain-events@0.1.3
 - @tryghost/express-dynamic-redirects@0.2.1
 - @tryghost/magic-link@1.0.14
 - @tryghost/member-analytics-service@0.1.4
 - @tryghost/member-events@0.3.1
 - @tryghost/members-analytics-ingress@0.1.5
 - @tryghost/members-api@2.4.0
 - @tryghost/members-csv@1.1.8
 - @tryghost/members-importer@0.3.4
 - @tryghost/members-ssr@1.0.15
 - @tryghost/members-stripe-service@0.3.1
 - @tryghost/members-offers@0.8.0
 - @tryghost/members-payments@0.1.0
2021-10-21 15:44:21 +02:00
Fabien O'Carroll
ff2da8a417 Added and emitted events for Offer Created
refs https://github.com/TryGhost/Team/issues/1166

Since we removed the creation of coupons from the Offers module, we must
emit events so that the Payments module can handle creating Coupons when
Offers are created.

We also export the events from the module so that they can be listened
to by the Payments module.

We also export other internals of the module so that the types can be
used.
2021-10-21 15:40:55 +02:00
Fabien O'Carroll
947fa74b9e Removed stripe_coupon_id handling from Offers
refs https://github.com/TryGhost/Team/issues/1166

This will be handled by a payments module instead. In order to
disconnect Stripe we must delete all Stripe related data, which means an
Offer doesn't inherently have a stripe coupon id. Instead we can use a
payments service which will get/create the coupon for us when we need
it.
2021-10-21 15:40:55 +02:00
Renovate Bot
7a68dc2bd3 Update dependency mocha to v9.1.3 2021-10-20 13:45:40 +00:00
Daniel Lockyer
cc73c4585a Added codecov.io coverage uploader to CI
refs linear.app/tryghost/issue/CORE-74/improve-the-test-situation

- this commit adds the codecov GitHub Action into CI so we can upload
  coverage reports
- the coverage files need to be in XML for them to work with
  codecov, so this commit also adds cobertura (XML) as a reporter
2021-10-20 13:48:54 +02:00
Fabien O'Carroll
501f05aef6 Published new versions
- @tryghost/members-offers@0.7.2
2021-10-19 11:09:17 +02:00
Fabien O'Carroll
e744c0f82e Fixed issue with updating offer to empty description
no-issue

Because we were checking for truthyness rather than existence when
updating properties on an Offer - it was impossible to set the
description to a blank string, as this is falsy.
2021-10-19 11:00:18 +02:00
Fabien O'Carroll
8d544978eb Published new versions
- @tryghost/members-offers@0.7.1
2021-10-18 17:29:58 +02:00
Fabien O'Carroll
dec46383b7 Updated API to use snake_case for redemption_count
no-issue
2021-10-18 17:29:30 +02:00
Fabien O'Carroll
959fbae83d Published new versions
- @tryghost/member-analytics-service@0.1.3
 - @tryghost/member-events@0.3.0
 - @tryghost/members-analytics-ingress@0.1.4
 - @tryghost/members-api@2.3.0
 - @tryghost/members-offers@0.7.0
2021-10-18 17:28:06 +02:00
Fabien O'Carroll
05619a193c Included redemptions in OfferDTO
refs https://github.com/TryGhost/Team/issues/1132

The DTO is the object which we expose externally so this adds the
Redemptions property for consumption by our external API's
2021-10-18 17:26:34 +02:00
Fabien O'Carroll
dbf549b664 Fixed count for redemptions
no-issue

You must use `where` rather than `forge` when generating counts.
2021-10-18 17:26:34 +02:00
Fabien O'Carroll
3cd26bc11b Updated OfferRepository to handle redemptions
refs https://github.com/TryGhost/Team/issues/1132

The OfferRepository needs to read from the OfferRedemptionModel to get
this data.
2021-10-18 17:26:34 +02:00
Fabien O'Carroll
34c0a7f6af Added redemptionCount to Offer
refs https://github.com/TryGhost/Team/issues/1132

This is a read-only property for tracking how many times an Offer has
been redeemed
2021-10-18 15:17:31 +02:00
Fabien O'Carroll
30fa4158bd Published new versions
- @tryghost/members-api@2.2.3
 - @tryghost/members-offers@0.6.2
2021-10-18 14:33:00 +02:00
Fabien O'Carroll
47ad10629e Used correct methods for reading/writing to db
no-issue

Using `save` was a placeholder and isn't the correct way to interact
with our model layer.
2021-10-15 11:08:30 +02:00
Fabien O'Carroll
c2f85d3742 Used isEqual to compare ValueObjects
no-issue

This ensures that ValueObjects can contain non-primitive types.
2021-10-14 14:56:37 +02:00
Fabien O'Carroll
3fc4bf6239 Published new versions
- @tryghost/members-api@2.2.2
 - @tryghost/members-offers@0.6.1
2021-10-14 12:06:48 +02:00
Fabien O'Carroll
53d24e501d Fixed Stripe Checkout using Offers
refs https://github.com/TryGhost/Members/commit/5172e40646

When we updated to use the OffersAPI instead of OfferRepository this was
missed, and we were passing blank coupon to Stripe Checkout. This should
eventually be replaced with a call like `getCoupon(offerId)` from a
payments service.
2021-10-14 12:02:39 +02:00