billing - precheckStartTransactionPrerequisites
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -1444,18 +1444,41 @@ export default class StripeBillingIntegration extends BillingIntegration {
}
public async precheckStartTransactionPrerequisites(user: User): Promise<StartTransactionCheck> {
- let precheckStatus = StartTransactionCheck.OK;
- if (this.settings.billing.isTransactionBillingActivated && !this.isUserInternal(user)) {
// Check billing prerequisites
- try {
+ if (!this.settings.billing.isTransactionBillingActivated) {
+ // Nothing to check - billing of transaction is not yet ON
+ return StartTransactionCheck.OK;
+ }
+ if (this.isUserInternal(user)) {
+ // Nothing to check - we do not bill internal user's transactions
+ return StartTransactionCheck.OK;
+ }
// Make sure the STRIPE connection is ok
+ try {
await this.checkConnection();
- // Make sure the taxID is still valid
- await this.checkActivationPrerequisites();
} catch (error) {
- precheckStatus = StartTransactionCheck.BILLING_NO_SETTINGS;
+ await Logging.logError({
+ tenantID: this.tenant.id,
+ action: ServerAction.BILLING_TRANSACTION,
+ module: MODULE_NAME, method: 'precheckStartTransactionPrerequisites',
+ message: 'Stripe Prerequisites to start a transaction are not met',
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ return StartTransactionCheck.BILLING_NO_SETTINGS;
+ }
+ // Check that all settings that are necessary to bill a transaction are properly set
+ try {
+ await this.checkActivationPrerequisites(); // Makes sure the taxID is still valid
+ } catch (error) {
+ await Logging.logError({
+ tenantID: this.tenant.id,
+ action: ServerAction.BILLING_TRANSACTION,
+ module: MODULE_NAME, method: 'precheckStartTransactionPrerequisites',
+ message: 'Billing setting prerequisites to start a transaction are not met',
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ return StartTransactionCheck.BILLING_NO_TAX;
}
- if (precheckStatus === StartTransactionCheck.OK) {
// Check user prerequisites
const customerID: string = user?.billingData?.customerID;
if (FeatureToggles.isFeatureActive(Feature.BILLING_CHECK_CUSTOMER_ID)) {
@@ -1465,11 +1488,17 @@ export default class StripeBillingIntegration extends BillingIntegration {
// Check whether the customer has a default payment method
this.checkStripePaymentMethod(customer);
} catch (error) {
- precheckStatus = StartTransactionCheck.BILLING_NO_PAYMENT_METHOD;
- }
- }
+ await Logging.logError({
+ tenantID: this.tenant.id,
+ action: ServerAction.BILLING_TRANSACTION,
+ module: MODULE_NAME, method: 'precheckStartTransactionPrerequisites',
+ message: `User prerequisites to start a transaction are not met - user: ${user.id}`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ return StartTransactionCheck.BILLING_NO_PAYMENT_METHOD;
}
}
- return precheckStatus;
+ // Everything is fine!
+ return StartTransactionCheck.OK;
}
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -119,6 +119,14 @@ export default class UserService {
status = await billingImpl.precheckStartTransactionPrerequisites(user);
}
} catch (error) {
+ await Logging.logError({
+ tenantID: req.user.tenantID,
+ module: MODULE_NAME,
+ method: 'handleGetUserDefaultTagCar',
+ action: action,
+ message: `Start Transaction checks failed for ${user.id}`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
status = StartTransactionCheck.BILLING_INCONSISTENT_SETTINGS;
}
}

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -35,6 +35,7 @@ export enum TransactionAction {
export enum StartTransactionCheck {
OK = 'ok',
BILLING_NO_PAYMENT_METHOD = 'no_payment_method', // start transaction is not possible - user has no payment method
+ BILLING_NO_TAX = 'billing_no_tax', // start transaction is not possible - the tax ID is not set or inconsistent
BILLING_NO_SETTINGS = 'billing_no_settings', // start transaction not possible - billing settings are not set (or partially set)
BILLING_INCONSISTENT_SETTINGS = 'billing_inconsistent_settings', // start transaction not possible - billing settings are inconsistent
}

billing - precheckStartTransactionPrerequisites