Commit Graph

18 Commits

Author SHA1 Message Date
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
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
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
04b9944e67 Defaulted to 'active' status when creating Offers
refs https://github.com/TryGhost/Team/issues/1131

This ensures that Offers are active by default.
2021-10-12 17:10:51 +02:00
Fabien O'Carroll
1f936357d9 Added concept of OfferStatus to domain model
refs https://github.com/TryGhost/Team/issues/1131

This allows us to model the behaviour of archived & active offers, as
well as allowing us to set their status on the model.
2021-10-12 15:27:27 +02:00
Fabien O'Carroll
1312943f5b Updated Offer to only change code once
no-issue

This simplifies the handling of updating redirects for a code, and
doesn't affect our application layer because we never have the need to
change a code twice.

In future this should be replaced with events at the domain level - so
that we do not have to track changed properties and instead a redirect
service can listen to events, which would be dispatched on a successful
save by the repository.
2021-10-08 13:02:22 +02:00
Fabien O'Carroll
08d3e6e99c Allowed for OfferDescription to be null/empty
refs https://github.com/TryGhost/Team/issues/1083

OfferDescription is not a required field, so we must not throw when it
is falsy or not present.
2021-10-08 12:40:57 +02:00
Fabien O'Carroll
35f150bcf4 Moved errors to domain/errors
no-issue

More cleanup to pull files into their appropriate responsibility
2021-10-08 12:31:11 +02:00
Fabien O'Carroll
78be4b55c9 Moved ValueObject to domain/models/shared
no-issue

This is only ever used in this directory so it makes sense to be
colocated.
2021-10-08 12:23:40 +02:00
Fabien O'Carroll
4a27ef68df Moved events into domain directory
no-issue

Events are a domain concern and as such should live in this directory
2021-10-08 12:21:27 +02:00
Fabien O'Carroll
9f7a922415 Added support for "repeating" duration Offers
refs https://github.com/TryGhost/Team/issues/1083

We combine the duration and duration_in_months into a single value
object which can be validated together, meaning we will never have
properties which are out of sync (e.g. forever durations with 2 months).
2021-10-08 12:10:36 +02:00
Fabien O'Carroll
c8933c9abd 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.
2021-10-07 18:18:53 +02:00
Fabien O'Carroll
170591a113 Improved types for Offer
no-issue

This splits out the types of the Offers properties from the types of the
expected values to be passed to create.
2021-10-07 17:37:48 +02:00
Fabien O'Carroll
2b58ecd82e Added support for creating fixed offers with currency
refs https://github.com/TryGhost/Team/issues/1083

We now allow creating offers for a fixed amount, rather than a
percentage. These require a currency to be passed as a fixed amount is
meaningless without one.
2021-10-07 17:37:48 +02:00
Fabien O'Carroll
2c04afe810 Updated types of Offers to "fixed" and "percent"
no-issue

This is inline with the language used elsewhere to describe these types.
2021-10-07 17:35:34 +02:00
Fabien O'Carroll
6d383c2d0e Added support for "once" and "forever" Offer duration
refs https://github.com/TryGhost/Team/issues/1083

Instead of Offers being hardcoded to the "once" duration this will allow
Admins to start creating offers of variable durations.
2021-10-07 17:13:23 +02:00
Fabien O'Carroll
504fb1bfa1 Used Value Objects to validate outside of Offer factory
no-issue

This adds the concept of "Value Objects" to an Offers properties,
allowing us to move validation out and ensure that an Offer will only
ever have valid properties, without having to duplicate checks - or
leave them to the persistent layer. This means we can fail early, as
well as write unit tests for all of our validation.
2021-10-07 16:46:08 +02:00