billing - stripe - LAZY mode
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -688,8 +688,6 @@ export default abstract class BillingIntegration {
public abstract deleteUser(user: User): Promise<void>;
- public abstract isUserSynchronized(user: User): Promise<boolean>;
-
public abstract getTaxes(): Promise<BillingTax[]>;
public abstract billInvoiceItem(user: User, billingInvoiceItems: BillingInvoiceItem): Promise<BillingInvoice>;
@@ -718,6 +716,14 @@ export default abstract class BillingIntegration {
public abstract sendTransfer(transfer: BillingTransfer, user: User): Promise<string>;
+ public async isUserSynchronized(user: User): Promise<boolean> {
+ // Make sure to get fresh data
+ user = await UserStorage.getUser(this.tenant, user.id);
+ const customerID: string = user?.billingData?.customerID;
+ // returns true when the customerID is properly set!
+ return !!customerID;
+ }
+
public async dispatchCollectedFunds(taskConfig: DispatchFundsTaskConfig): Promise<ActionsResponse> {
const actionsDone: ActionsResponse = {
inSuccess: 0,

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -188,16 +188,6 @@ export default class StripeBillingIntegration extends BillingIntegration {
return billingUser;
}
- public async isUserSynchronized(user: User): Promise<boolean> {
- // Check Stripe
- await this.checkConnection();
- // Make sure to get fresh data
- user = await UserStorage.getUser(this.tenant, user.id);
- const customerID: string = user?.billingData?.customerID;
- // returns true when the customerID is properly set!
- return !!customerID;
- }
-
public async getUser(user: User): Promise<BillingUser> {
// Check Stripe
await this.checkConnection();

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -238,9 +238,7 @@ export default class UserService {
// Update User Admin Data
await UserService.updateUserAdminData(req.tenant, user, user.projectFields);
// Update Billing
- if (FeatureToggles.isFeatureActive(Feature.BILLING_SYNC_USER_ASAP)) {
- await UserService.updateUserBillingData(ServerAction.USER_UPDATE, req.tenant, req.user, user);
- }
+ await UserService.syncUserAndUpdateBillingData(ServerAction.USER_UPDATE, req.tenant, req.user, user);
// Log
await Logging.logInfo({
tenantID: req.tenant.id,
@@ -660,9 +658,7 @@ export default class UserService {
// Assign Site to new User
await UtilsService.assignCreatedUserToSites(req.tenant, newUser, authorizations);
// Update Billing
- if (FeatureToggles.isFeatureActive(Feature.BILLING_SYNC_USER_ASAP)) {
- await UserService.updateUserBillingData(ServerAction.USER_CREATE, req.tenant, req.user, newUser);
- }
+ await UserService.syncUserAndUpdateBillingData(ServerAction.USER_CREATE, req.tenant, req.user, newUser);
// Log
await Logging.logInfo({
tenantID: req.tenant.id,
@@ -921,8 +917,14 @@ export default class UserService {
}
}
- private static async updateUserBillingData(action: ServerAction, tenant: Tenant, loggedUser: UserToken, user: User) {
+ private static async syncUserAndUpdateBillingData(action: ServerAction, tenant: Tenant, loggedUser: UserToken, user: User): Promise<void> {
if (Utils.isComponentActiveFromToken(loggedUser, TenantComponents.BILLING)) {
+ if (!FeatureToggles.isFeatureActive(Feature.BILLING_SYNC_USER_ASAP)) {
+ if (!user.billingData?.customerID) {
+ // Nothing to do - user will be synchronized in a LAZY mode when adding a payment method
+ return;
+ }
+ }
const billingImpl = await BillingFactory.getBillingImpl(tenant);
if (billingImpl) {
try {

billing - stripe - LAZY mode