mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
daf5a41af0
no issue - Added new API to delete members - Added methods to handle e2e member deletion - Deleting member via Admin leads to - Removal of member from payment processor and cancelling all active subscriptions immediately - Removal of member information from DB
88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
const stripe = require('./payment-processors/stripe');
|
|
|
|
const adapters = {
|
|
stripe
|
|
};
|
|
|
|
module.exports = class PaymentProcessorService {
|
|
constructor(config) {
|
|
this._ready = new Promise(() => {});
|
|
process.nextTick(() => this.configure(config));
|
|
}
|
|
|
|
configure({processors}) {
|
|
this._processors = {};
|
|
this._ready = Promise.all(processors.map(({
|
|
adapter,
|
|
config
|
|
}) => {
|
|
this._processors[adapter] = new adapters[adapter];
|
|
return this._processors[adapter].configure(config);
|
|
})).then(() => {
|
|
return Object.keys(this._processors);
|
|
});
|
|
|
|
return this._ready;
|
|
}
|
|
|
|
getAdapters() {
|
|
return this._ready;
|
|
}
|
|
|
|
getConfig(adapter) {
|
|
if (!adapter) {
|
|
return Promise.reject(new Error('getConfig(adapter) requires an adapter'));
|
|
}
|
|
|
|
return this._ready.then(() => {
|
|
return this._processors[adapter].getConfig();
|
|
});
|
|
}
|
|
|
|
getPublicConfig(adapter) {
|
|
if (!adapter) {
|
|
return Promise.reject(new Error('getPublicConfig(adapter) requires an adapter'));
|
|
}
|
|
|
|
return this._ready.then(() => {
|
|
return this._processors[adapter].getPublicConfig();
|
|
});
|
|
}
|
|
|
|
createSubscription(member, metadata) {
|
|
if (!metadata.adapter) {
|
|
return Promise.reject(new Error('createSubscription(member, { adapter }) requires an adapter'));
|
|
}
|
|
return this._ready.then(() => {
|
|
return this._processors[metadata.adapter].createSubscription(member, metadata);
|
|
});
|
|
}
|
|
|
|
getSubscription(member, metadata) {
|
|
if (!metadata.adapter) {
|
|
return Promise.reject(new Error('getSubscription(member, { adapter }) requires an adapter'));
|
|
}
|
|
return this._ready.then(() => {
|
|
return this._processors[metadata.adapter].getSubscription(member, metadata);
|
|
});
|
|
}
|
|
|
|
removeSubscription(member, metadata) {
|
|
if (!metadata.adapter) {
|
|
return Promise.reject(new Error('removeSubscription(member, { adapter }) requires an adapter'));
|
|
}
|
|
return this._ready.then(() => {
|
|
return this._processors[metadata.adapter].removeSubscription(member, metadata);
|
|
});
|
|
}
|
|
|
|
removeCustomer(member, metadata) {
|
|
if (!metadata.adapter) {
|
|
return Promise.reject(new Error('removeCustomer(member, { adapter }) requires an adapter'));
|
|
}
|
|
return this._ready.then(() => {
|
|
return this._processors[metadata.adapter].removeCustomer(member, metadata);
|
|
});
|
|
}
|
|
};
|