billing - eslint - public/private order
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
import { BillingChargeInvoiceAction, BillingDataTransactionStart, BillingDataTransactionStop, BillingDataTransactionUpdate, BillingInvoice, BillingInvoiceDocument, BillingInvoiceItem, BillingInvoiceStatus, BillingOperationResult, BillingPaymentMethod, BillingTax, BillingUser, BillingUserSynchronizeAction } from '../../types/Billing';
import FeatureToggles, { Feature } from '../../utils/FeatureToggles';
-/* eslint-disable @typescript-eslint/member-ordering */
import User, { UserStatus } from '../../types/User';
import BackendError from '../../exception/BackendError';
@@ -32,16 +31,6 @@ export default abstract class BillingIntegration {
this.settings = settings;
}
- private async _getUsersWithNoBillingData(): Promise<User[]> {
- const newUsers = await UserStorage.getUsers(this.tenantID,
- { 'statuses': [UserStatus.ACTIVE], 'notSynchronizedBillingData': true },
- { ...Constants.DB_PARAMS_MAX_LIMIT, sort: { 'userID': 1 } });
- if (newUsers.count > 0) {
- return newUsers.result;
- }
- return [];
- }
-
public async synchronizeUsers(): Promise<BillingUserSynchronizeAction> {
await this.checkConnection();
// Check
@@ -167,39 +156,6 @@ export default abstract class BillingIntegration {
return billingUser;
}
- private async _synchronizeUser(user: User, forceMode = false): Promise<BillingUser> {
- // Check if we need to create or update a STRIPE customer
- let billingUser: BillingUser = null;
- if (!forceMode) {
- // ------------------
- // Regular Situation
- // ------------------
- const exists = await this.isUserSynchronized(user); // returns false when the customerID is not set
- if (!exists) {
- billingUser = await this.createUser(user);
- } else {
- billingUser = await this.updateUser(user);
- }
- } else {
- // ----------------------------------------------------------------------------------------------
- // Specific use-case - Trying to REPAIR inconsistencies
- // e.g.: CustomerID is set, but the corresponding data does not exist anymore on the STRIPE side
- // ----------------------------------------------------------------------------------------------
- try {
- billingUser = await this.getUser(user);
- if (!billingUser) {
- billingUser = await this.createUser(user);
- } else {
- billingUser = await this.updateUser(user);
- }
- } catch (error) {
- // Let's repair it
- billingUser = await this.repairUser(user);
- }
- }
- return billingUser;
- }
-
public async synchronizeInvoices(user?: User): Promise<BillingUserSynchronizeAction> {
const actionsDone: BillingUserSynchronizeAction = {
inSuccess: 0,
@@ -330,6 +286,49 @@ export default abstract class BillingIntegration {
}
}
+ private async _getUsersWithNoBillingData(): Promise<User[]> {
+ const newUsers = await UserStorage.getUsers(this.tenantID,
+ { 'statuses': [UserStatus.ACTIVE], 'notSynchronizedBillingData': true },
+ { ...Constants.DB_PARAMS_MAX_LIMIT, sort: { 'userID': 1 } });
+ if (newUsers.count > 0) {
+ return newUsers.result;
+ }
+ return [];
+ }
+
+ private async _synchronizeUser(user: User, forceMode = false): Promise<BillingUser> {
+ // Check if we need to create or update a STRIPE customer
+ let billingUser: BillingUser = null;
+ if (!forceMode) {
+ // ------------------
+ // Regular Situation
+ // ------------------
+ const exists = await this.isUserSynchronized(user); // returns false when the customerID is not set
+ if (!exists) {
+ billingUser = await this.createUser(user);
+ } else {
+ billingUser = await this.updateUser(user);
+ }
+ } else {
+ // ----------------------------------------------------------------------------------------------
+ // Specific use-case - Trying to REPAIR inconsistencies
+ // e.g.: CustomerID is set, but the corresponding data does not exist anymore on the STRIPE side
+ // ----------------------------------------------------------------------------------------------
+ try {
+ billingUser = await this.getUser(user);
+ if (!billingUser) {
+ billingUser = await this.createUser(user);
+ } else {
+ billingUser = await this.updateUser(user);
+ }
+ } catch (error) {
+ // Let's repair it
+ billingUser = await this.repairUser(user);
+ }
+ }
+ return billingUser;
+ }
+
abstract checkConnection(): Promise<void>;
abstract startTransaction(transaction: Transaction): Promise<BillingDataTransactionStart>;
@@ -375,4 +374,6 @@ export default abstract class BillingIntegration {
abstract getPaymentMethods(user: User): Promise<BillingPaymentMethod[]>;
abstract deletePaymentMethod(user: User, paymentMethodId: string): Promise<BillingOperationResult>;
+
+
}

billing - eslint - public/private order