0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-25 02:31:59 -05:00

Fixed checks for if Stripe is configured

no-issue
This commit is contained in:
Fabien O'Carroll 2021-01-26 11:26:28 +00:00
parent 0e0b2f3cb2
commit 0268bee13e
3 changed files with 17 additions and 11 deletions

View file

@ -33,7 +33,7 @@ module.exports = class RouterController {
}
async ensureStripe(_req, res, next) {
if (!this._stripeAPIService) {
if (!this._stripeAPIService.configured) {
res.writeHead(400);
return res.end('Stripe not configured');
}

View file

@ -125,8 +125,8 @@ module.exports = class MemberRepository {
}
async linkStripeCustomer(data, options) {
if (!this._stripeAPIService) {
return;
if (!this._stripeAPIService.configured) {
throw new Error('Cannot link Stripe Customer with no Stripe Connection');
}
const customer = await this._stripeAPIService.getCustomer(data.customer_id);
@ -151,8 +151,8 @@ module.exports = class MemberRepository {
}
async linkSubscription(data, options) {
if (!this._stripeAPIService) {
return;
if (!this._stripeAPIService.configured) {
throw new Error('Cannot link Stripe Subscription with no Stripe Connection');
}
const member = await this._Member.findOne({
id: data.id
@ -205,8 +205,8 @@ module.exports = class MemberRepository {
}
async updateSubscription(data, options) {
if (!this._stripeAPIService) {
return;
if (!this._stripeAPIService.configured) {
throw new Error('Cannot update Stripe Subscription with no Stripe Connection');
}
const member = await this._Member.findOne({
id: data.id
@ -241,8 +241,8 @@ module.exports = class MemberRepository {
}
async setComplimentarySubscription(data, options) {
if (!this._stripeAPIService) {
return;
if (!this._stripeAPIService.configured) {
throw new Error('Cannot update Stripe Subscription with no Stripe Connection');
}
const member = await this._Member.findOne({
id: data.id
@ -323,8 +323,8 @@ module.exports = class MemberRepository {
}
async cancelComplimentarySubscription(data) {
if (!this._stripeAPIService) {
return;
if (!this._stripeAPIService.configured) {
throw new Error('Cannot cancel Complimentary Subscription with no Stripe Connection');
}
const member = await this._Member.findOne({

View file

@ -47,11 +47,16 @@ module.exports = class StripeAPIService {
*/
constructor({config, logger}) {
this.logging = logger;
this._configured = false;
if (config.secretKey) {
this.configure(config);
}
}
get configured() {
return this._configured;
}
configure(config) {
this._stripe = new Stripe(config.secretKey);
this._config = config;
@ -61,6 +66,7 @@ module.exports = class StripeAPIService {
} else {
this._rateLimitBucket = new LeakyBucket(EXPECTED_API_EFFICIENCY * 100, 1);
}
this._configured = true;
}
/**