Added StripeLiveEnabledEvent
and StripeLiveDisabledEvent
to Stripe service
no issue - This is preparation work to be able to listen to events whenever Stripe gets enabled in live mode or disabled again. - This creates two new event types, which are being dispatched with `DomainEvents` from the Stripe service on the `connect()` and - vice versa - the `disconnect()` methods.
This commit is contained in:
parent
974ce0b25b
commit
f3e0cec0d2
23
ghost/stripe/lib/StripeLiveDisabledEvent.js
Normal file
23
ghost/stripe/lib/StripeLiveDisabledEvent.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @typedef {object} StripeLiveDisabledEventData
|
||||
* @prop {string?} message
|
||||
*/
|
||||
|
||||
module.exports = class StripeLiveDisabledEvent {
|
||||
/**
|
||||
* @param {StripeLiveDisabledEventData} data
|
||||
* @param {Date} timestamp
|
||||
*/
|
||||
constructor(data, timestamp) {
|
||||
this.data = data;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {StripeLiveDisabledEventData} data
|
||||
* @param {Date} [timestamp]
|
||||
*/
|
||||
static create(data, timestamp) {
|
||||
return new StripeLiveDisabledEvent(data, timestamp || new Date);
|
||||
}
|
||||
};
|
23
ghost/stripe/lib/StripeLiveEnabledEvent.js
Normal file
23
ghost/stripe/lib/StripeLiveEnabledEvent.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @typedef {object} StripeLiveEnabledEventData
|
||||
* @prop {string} message
|
||||
*/
|
||||
|
||||
module.exports = class StripeLiveEnabledEvent {
|
||||
/**
|
||||
* @param {StripeLiveEnabledEventData} data
|
||||
* @param {Date} timestamp
|
||||
*/
|
||||
constructor(data, timestamp) {
|
||||
this.data = data;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {StripeLiveEnabledEventData} data
|
||||
* @param {Date} [timestamp]
|
||||
*/
|
||||
static create(data, timestamp) {
|
||||
return new StripeLiveEnabledEvent(data, timestamp || new Date);
|
||||
}
|
||||
};
|
@ -2,6 +2,9 @@ const WebhookManager = require('./WebhookManager');
|
||||
const StripeAPI = require('./StripeAPI');
|
||||
const StripeMigrations = require('./StripeMigrations');
|
||||
const WebhookController = require('./WebhookController');
|
||||
const DomainEvents = require('@tryghost/domain-events');
|
||||
const StripeLiveEnabledEvent = require('./StripeLiveEnabledEvent');
|
||||
const StripeLiveDisabledEvent = require('./StripeLiveDisabledEvent');
|
||||
|
||||
module.exports = class StripeService {
|
||||
constructor({
|
||||
@ -50,6 +53,7 @@ module.exports = class StripeService {
|
||||
}
|
||||
|
||||
async connect() {
|
||||
DomainEvents.dispatch(StripeLiveEnabledEvent.create({message: 'Stripe Live Mode Enabled'}));
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
@ -66,6 +70,8 @@ module.exports = class StripeService {
|
||||
await this.webhookManager.stop();
|
||||
|
||||
this.api.configure(null);
|
||||
|
||||
DomainEvents.dispatch(StripeLiveDisabledEvent.create({message: 'Stripe Live Mode Disabled'}));
|
||||
}
|
||||
|
||||
async configure(config) {
|
||||
|
Loading…
Reference in New Issue
Block a user