Commit Graph

3 Commits

Author SHA1 Message Date
Daniel Lockyer
21ec26ea08 Removed used of ghost-ignition dependency
no issue

- we're killing off `ghost-ignition` in favor of explicit packages
  containing its individual components
- this commit switches the Members repo to using the
  `@tryghost/ignition-errors` and `@tryghost/debug` dependencies,
  updates the code with relevant changes and removes the `ghost-ignition`
  dependency
2021-06-29 21:43:05 +01:00
Naz Gargol
ff5fceafc8 Added subscription update middleware (#107)
refs #https://github.com/TryGhost/Ghost/pull/11434

- Added method to allow updating single subscription. Only `cancel_at_period_end` field can be updated. 
- Middleware is needed to allow Ghost Core to cancel/uncancel member's subscription. 
- Relies on the request containing identity information to be able to verify if subscription belongs to the user
- When member could not be identified by the identity information present in the request we should throw instead of continuing processing
- Handling and messaging inspired by https://github.com/TryGhost/Ghost/blob/3.1.1/core/server/services/mega/mega.js#L132
- When the user initiates subscription cancellation we can safely mark the subscription as canceled so that it's not shown in the interface on subsequent request. Otherwise, we end up in a situation where we still return the subscription in the period until Stripe triggers the webhook.
- Added boolean coercion for cancel_at_period_end parameter. If anything but boolean is passed to Stripe API it throws an error.  Coercing the value on our side is a gives a better dev experience
2019-12-12 15:19:36 +07:00
Fabien O'Carroll
1fb969ad36 Refactored to improve logging and error handling
* Installed stripe@7.4.0

refs #38

We were relying on stripe being installed in Ghost, this moves the dep
to the correct package.

* Created exponentialBackoff wrapper for stripe api

refs #38

https://stripe.com/docs/testing#rate-limits The stripe docs suggest to
use exponential backoff when recieving a rate limit error. This wrapper
will wrap stripe api calls, and retry them after 1s,2s,4s,8s,16s until
eventually failing. This gives a total of 5 retries over 31s.

* Added wrappers around the stripe api calls

refs #38

* Ensured all calls to stripe api go via exp backoff

refs #38

* Scaffolding out the error handling for stripe api

* Forwarding all errors

* Refactored stripe api into modules

* Ensured the ready promise object is not replaced

* Added logging setup

- Sets up common logger structure with custom logger passed through

* Ensure logger is kept in module state

* Renamed updateLogger to setLogger

* Removed `logger` param and exposed setLogger method

* Ensured different ids used for test mode

* Ensure setLogger works for prototype methods

* Removed reconfigureSettings method

* Updated payment processer service to keep static ready promise

* Added eventemitter to member api instance to handle errors

* Moved logging of errors to http level
2019-07-17 18:20:13 +08:00