Commit Graph

20 Commits

Author SHA1 Message Date
Simon Backx
e14df6479b
Added E2E tests for donations API (#17694)
fixes https://github.com/TryGhost/Product/issues/3722
2023-08-11 14:25:53 +02:00
Sag
f386a92f98
Fixed preset amount for donations (#17617)
refs https://github.com/TryGhost/Product/issues/3666
2023-08-07 16:19:19 +00:00
Sag
c201e4eb4f
Fixed preset amount in Stripe Checkout (#17615)
refs https://github.com/TryGhost/Product/issues/3666

- Stripe has a set of minimum charges per currency. This adds a basic
safeguard on the backend side, while the main validation should happen
in Portal
- Stripe docs:
https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
2023-08-07 16:48:25 +02:00
Sag
81c3555106
Added logic for currency and suggested amount for Tips & Donations (#17599)
closes https://github.com/TryGhost/Product/issues/3666

- added computed setting "donations_enabled"
- added logic to persist "donations_suggested_amount" and "donations_currency"
- used  "donations_suggested_amount" and "donations_currency" when initiating a new Stripe Checkout for donations
- added copy functionality to "your link" in Tips & Donations settings
2023-08-04 18:17:35 +00:00
Simon Backx
841e52ccfe
Added donations API (#17495)
refs https://github.com/TryGhost/Product/issues/3648

- Refactored Members API RouterController.createCheckoutSession: Split the method into smaller parts so we can reuse individual parts for the upcoming donation checkout session.
- Wired up donation checkout creation
- Added donation events
2023-07-31 16:00:52 +00:00
Fabien "egg" O'Carroll
104f84f252 Added eslint rule for file naming convention
As discussed with the product team we want to enforce kebab-case file names for
all files, with the exception of files which export a single class, in which
case they should be PascalCase and reflect the class which they export.

This will help find classes faster, and should push better naming for them too.

Some files and packages have been excluded from this linting, specifically when
a library or framework depends on the naming of a file for the functionality
e.g. Ember, knex-migrator, adapter-manager
2023-05-09 12:34:34 -04:00
Rishabh Garg
33458daae8
🐛 Fixed free trial applied alongside an offer in checkout (#15975)
refs https://github.com/TryGhost/Team/issues/2375

If a discount offer is associated with a tier that has a free trial enabled on full price / standard portal in membership settings, then the stripe checkout applied both the discount and free trial to the member, which is incorrect as we shouldn't be combining both.

- removes trial days from stripe checkout if a coupon is being applied, so only one of them is applied at a time
2022-12-09 18:47:05 +05:30
Simon Backx
9c12a2a043
Limited Stripe price lookups (#15823)
refs https://github.com/TryGhost/Team/issues/2262

Makes sure we only loop active Stripe prices. If we find an inactive
price, we also update it in our database now after this change.
2022-11-17 14:33:46 +01:00
Fabien "egg" O'Carroll
e255102976 Fixed check for existing Stripe Prices
Since we updated the currency variable to be lowercase we needed to
update the check for existing Stripe Price currencies to lowercase
too. Without this we will create extra Prices in Stripe, but the
functionality will still work.

We could consider using value objects for currency in future so that
we can provide an `equals` method which handles all of this for us.
2022-11-09 14:56:16 +07:00
Fabien "egg" O'Carroll
69aa52bd8e 🐛 Handled deleted Stripe objects in the Stripe Checkout flow
closes https://github.com/TryGhost/Team/issues/2222

Whilst we were checking for Stripe objects being active, we were not
checking for them existing in Stripe. This adds handling to all read
request to Stripe in the payment link flow, so that we can gracefully
handle deleted objects.

We've also included an automated test which fails without this fix.

We've also improved the query to find Stripe Prices which will result
in less request to the Stripe API to check if it is valid.
2022-11-08 16:03:07 +07:00
Fabien 'egg' O'Carroll
1ff1b75a69
🐛 Fixed errors with Stripe Checkout (#15749)
refs https://github.com/TryGhost/Ghost/commit/1f300fb781f0

The full customer object was not being passed to the StripeAPI service
when it already exists, this was resulting in inconsistent behaviour when
sending the customerEmail param to the API, causing `invalid_email`
errors to be thrown from Stripe and breaking the checkout.
2022-11-02 02:18:30 +07:00
Fabien "egg" O'Carroll
ba41f308c7 🐛 Fixed upgrading to a paid plan
closes https://github.com/TryGhost/Team/issues/2196

We were incorrectly assuming that all requests would have the
`customerEmail` passed in the body. Instead we were incorrectly
passing `undefined` or `''` as the `customerEmail` property to stripe,
which resulted in a validation error.

We've updated the code to pass `null` in the case of a falsy value,
which the Stripe API handles without error.
2022-11-02 00:11:33 +07:00
Fabien "egg" O'Carroll
1f300fb781 🐛 Fixed checkout sessions when using Offers
closes https://github.com/TryGhost/Team/issues/2195

The issue here is two-fold, and specific to using Offers so was not
caught by any automated tests. First, we were incorrectly comparing
the tier.id to the offer.tier.id - this is because the Tier objects id
property is an instance of ObjectID rather than a string.

Secondly we were passing through the cadence parameter from the
request body, but when using Offers this is not including in the
request, so we must pull the data off of the Offer object instead and
pass that to the payments service.
2022-11-02 00:11:33 +07:00
Fabien "egg" O'Carroll
6e862b42e7 Wired up Payments service to new Tiers package
refs https://github.com/TryGhost/Team/issues/2078

This adds handling to the Tier events to create Stripe Products & Prices when
Tiers are created and have their pricing changed. We also update the Stripe
Product names when the Tier name is edited.

We also add a method to generate a payment URL which will replace our current
implementation of creating a Stripe Checkout Session
2022-10-25 09:02:41 +07:00
Daniel Lockyer
727187df32
Added missing jsdoc imports for PaymentsService
- this helps with populating types in editors
2022-10-12 11:08:49 +07:00
Rishabh
843bbfa55d Handled stripe setup for free trial offers
refs https://github.com/TryGhost/Team/issues/1726

- free trial offers don't need a stripe coupon created for them
- checkout sessions for free trial offers ignore stripe coupon and directly pass the trial days value
- trial days of an offer take precedence over trial days added as default to a tier
2022-08-11 11:04:39 +05:30
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
Simon Backx
f74b00fea6 Stored offer_id in subscriptions (#389)
refs https://github.com/TryGhost/Team/issues/1519

- Added offer repository dependency to member repository (offerAPI didn't work because it creates a new transaction that resulted in a deadlock during tests)
- Store the offer id from the Stripe subscription metadata in the subscription (only if the discount is still active)
- Also added the offer id to the metadata for a Stripe coupon, this will make adding and removing coupons a bit more foolproof
- Prefer the usage of the offer metadata from a coupon if it is present
- When no discount is applied to a subscription, it always sets the offer id to null, even when the metadata still contains the offer
- The offer_id remains stored when a subscription is canceled/expired
2022-04-19 09:15:33 +02:00
Fabien O'Carroll
dbf564d137 Created Stripe Coupons when Offers are created
refs https://github.com/TryGhost/Team/issues/1166

We've moved the Stripe Coupon creation out of the Offers module as part
of the work for Stripe disconnect, so we have to make sure that we are
still creating coupons when an Offer is created.
2021-10-21 15:40:55 +02:00
Fabien O'Carroll
5db41169aa Added @tryghost/members-payments module
refs https://github.com/TryGhost/Team/issues/1166

This is a new module which will eventually handle all payment related
things. This allows the Offers module to focus exclusively on the Ghost
concepts, and the Payments module will handle the association between
Offer & Stripe Coupon, Tier & Stripe Product, Cadence & Stripe Price.

This decoupling allows us to not have to consider the lack of Stripe
data for an Offer, which is the case after a Stripe Disconnect. Instead
all of the population/repopulation/lazy-creating can be handled here.
2021-10-21 15:40:55 +02:00