stripe - checkConnection minor changes
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -45,7 +45,10 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
public async checkConnection(): Promise<void> {
// Initialize Stripe
- await this.initializeStripe();
+ if (!this.stripe) {
+ // STRIPE not yet initialized - let's do it!
+ this.settings.currency = this.stripeSettings.currency;
+ this.settings.secretKey = await Cypher.decrypt(this.tenantID, this.stripeSettings.secretKey);
// Check Key
if (!this.settings.secretKey) {
throw new BackendError({
@@ -55,10 +58,19 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
message: 'No secret key provided for connection to Stripe'
});
}
+ this.stripe = new Stripe(this.settings.secretKey);
+ // Let's check if the connection is working properly
+ if (!this.stripe) {
+ throw new BackendError({
+ source: Constants.CENTRAL_SERVER,
+ module: MODULE_NAME, method: 'checkConnection',
+ action: ServerAction.CHECK_CONNECTION,
+ message: 'Failed to connect to Stripe'
+ });
+ }
// Validate the connection
let isKeyValid = false;
try {
- this.stripe = new Stripe(this.settings.secretKey);
// Get one customer
const list = await this.stripe.customers.list(
{ limit: 1 }
@@ -85,6 +97,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
});
}
}
+ }
public async getUsers(): Promise<BillingUser[]> {
const users = [];

stripe - checkConnection minor changes