billing - cleanup of unused constants
MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -8,7 +8,7 @@ import { BillingSettings } from '../../types/Setting';
import BillingStorage from '../../storage/mongodb/BillingStorage';
import Constants from '../../utils/Constants';
import { DataResult } from '../../types/DataResult';
-import Decimal from 'decimal.js';
+import { Decimal } from 'decimal.js';
import Logging from '../../utils/Logging';
import NotificationHandler from '../../notification/NotificationHandler';
import { Request } from 'express';
@@ -204,7 +204,7 @@ export default abstract class BillingIntegration {
await Logging.logWarning({
tenantID: this.tenant.id,
source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_CHARGE_INVOICE,
+ action: ServerAction.BILLING_PERFORM_OPERATIONS,
actionOnUser: invoice.user,
module: MODULE_NAME, method: 'chargeInvoices',
message: `Invoice is too new - Operation has been skipped - '${invoice.id}'`
@@ -219,7 +219,7 @@ export default abstract class BillingIntegration {
await Logging.logInfo({
tenantID: this.tenant.id,
source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_CHARGE_INVOICE,
+ action: ServerAction.BILLING_PERFORM_OPERATIONS,
actionOnUser: invoice.user,
module: MODULE_NAME, method: 'chargeInvoices',
message: `Successfully charged invoice '${invoice.id}'`
@@ -230,7 +230,7 @@ export default abstract class BillingIntegration {
await Logging.logError({
tenantID: this.tenant.id,
source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_CHARGE_INVOICE,
+ action: ServerAction.BILLING_PERFORM_OPERATIONS,
actionOnUser: invoice.user,
module: MODULE_NAME, method: 'chargeInvoices',
message: `Failed to charge invoice '${invoice.id}'`,

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -427,7 +427,7 @@ export default class StripeBillingIntegration extends BillingIntegration {
await Logging.logError({
tenantID: this.tenant.id,
source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_PERFORM_OPERATIONS,
+ action: ServerAction.BILLING_CHARGE_INVOICE,
actionOnUser: billingInvoice.user,
module: MODULE_NAME, method: 'chargeInvoice',
message: `Payment attempt failed - stripe invoice: '${billingInvoice.invoiceID}'`,

MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -57,7 +57,6 @@ class RequestMapper {
[ServerAction.BILLING_FORCE_SYNCHRONIZE_USER]: BillingService.handleForceSynchronizeUser.bind(this),
[ServerAction.BILLING_SYNCHRONIZE_INVOICES]: BillingService.handleSynchronizeInvoices.bind(this),
[ServerAction.BILLING_FORCE_SYNCHRONIZE_USER_INVOICES]: BillingService.handleForceSynchronizeUserInvoices.bind(this),
- [ServerAction.BILLING_CREATE_TRANSACTION_INVOICE]: BillingService.handleCreateTransactionInvoice.bind(this),
[ServerAction.BILLING_SETUP_PAYMENT_METHOD]: BillingService.handleBillingSetupPaymentMethod.bind(this),
[ServerAction.OCPI_ENDPOINT_CREATE]: OCPIEndpointService.handleCreateOcpiEndpoint.bind(this),
[ServerAction.OCPI_ENDPOINT_PING]: OCPIEndpointService.handlePingOcpiEndpoint.bind(this),
@@ -191,7 +190,6 @@ class RequestMapper {
[ServerAction.SYNCHRONIZE_CAR_CATALOGS]: CarService.handleSynchronizeCarCatalogs.bind(this),
[ServerAction.CAR_UPDATE]: CarService.handleUpdateCar.bind(this),
[ServerAction.TAG_UPDATE]: TagService.handleUpdateTag.bind(this),
- [ServerAction.BILLING_CHARGE_INVOICE]: BillingService.handleBillingChargeInvoice.bind(this),
[ServerAction.REGISTRATION_TOKEN_UPDATE]: RegistrationTokenService.handleUpdateRegistrationToken.bind(this),
});
break;

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -509,67 +509,6 @@ export default class BillingService {
next();
}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
- public static async handleCreateTransactionInvoice(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // TODO - no use-case for this endpoint so far!
- throw new Error('Method not implemented.');
- // // Check if component is active
- // UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
- // Action.CREATE, Entity.INVOICE, MODULE_NAME, 'handleCreateTransactionInvoice');
- // // Check Auth
- // if (!await Authorizations.canCreateTransactionInvoice(req.user)) {
- // throw new AppAuthError({
- // errorCode: HTTPAuthError.FORBIDDEN,
- // user: req.user,
- // entity: Entity.INVOICE, action: Action.CREATE,
- // module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
- // });
- // }
- // const filteredRequest = BillingSecurity.filterLinkTransactionToInvoiceRequest(req.body);
- // // Get Billing impl
- // const billingImpl = await BillingFactory.getBillingImpl(req.tenant);
- // if (!billingImpl) {
- // throw new AppError({
- // source: Constants.CENTRAL_SERVER,
- // errorCode: HTTPError.GENERAL_ERROR,
- // message: 'Billing service is not configured',
- // module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
- // action: action,
- // user: req.user
- // });
- // }
- // // Get the Transaction
- // const transaction = await TransactionStorage.getTransaction(req.user.tenantID,
- // Utils.convertToInt(filteredRequest.transactionID));
- // UtilsService.assertObjectExists(action, transaction, `Transaction ID '${filteredRequest.transactionID}' does not exist`,
- // MODULE_NAME, 'handleCreateTransactionInvoice', req.user);
- // Create an invoice for the transaction
- // ----------------------------------------------------------------------
- // TODO - Rethink that part!
- // Calling StopTransaction without calling startTransaction may have
- // unpredictable side-effects.
- // ----------------------------------------------------------------------
- // const billingDataStop = await billingImpl.stopTransaction(transaction);
- // // Update transaction billing data
- // if (transaction.billingData) {
- // transaction.billingData.stop = billingDataStop;
- // transaction.billingData.lastUpdate = new Date();
- // }
- // // Save it
- // await TransactionStorage.saveTransaction(req.user.tenantID, transaction);
- // // Ok
- // await Logging.logInfo({
- // tenantID: req.user.tenantID,
- // user: req.user, actionOnUser: transaction.userID,
- // module: MODULE_NAME, method: 'handleCreateTransactionInvoice',
- // message: `Transaction ID '${transaction.id}' has been billed successfully`,
- // action: action,
- // });
- // Ok
- // res.json(Object.assign(Constants.REST_RESPONSE_SUCCESS));
- // next();
- }
-
public static async handleBillingSetupPaymentMethod(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
@@ -751,49 +690,6 @@ export default class BillingService {
res.end(buffer, 'binary');
}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
- public static async handleBillingChargeInvoice(action: ServerAction, req: Request, res: Response): Promise<void> {
- // TODO - no use-case for this endpoint so far! - only used for troubleshooting!
- throw new Error('Method not implemented.');
- // // Check if component is active
- // UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
- // Action.BILLING_CHARGE_INVOICE, Entity.INVOICE, MODULE_NAME, 'handleBillingChargeInvoice');
- // // Filter
- // const filteredRequest = BillingSecurity.filterChargeInvoiceRequest(req.body);
- // // Get the Invoice
- // const invoice = await BillingStorage.getInvoice(req.user.tenantID, filteredRequest.ID); // ID of the Billing Invoice (not the stripe invoice)
- // UtilsService.assertObjectExists(action, invoice, `Invoice ID '${filteredRequest.ID}' does not exist`,
- // MODULE_NAME, 'handleDownloadInvoice', req.user);
- // // Check Auth
- // // if (!await Authorizations.canChargeInvoice(req.user, invoice.userID)) {
- // // throw new AppAuthError({
- // // errorCode: HTTPAuthError.ERROR,
- // // user: req.user,
- // // entity: Entity.INVOICE, action: Action.CHARGE_INVOICE,
- // // module: MODULE_NAME, method: 'handleBillingChargeInvoice',
- // // });
- // // }
- // // Get the billing impl
- // const billingImpl = await BillingFactory.getBillingImpl(req.tenant);
- // if (!billingImpl) {
- // throw new AppError({
- // source: Constants.CENTRAL_SERVER,
- // errorCode: HTTPError.GENERAL_ERROR,
- // message: 'Billing service is not configured',
- // module: MODULE_NAME, method: 'handleBillingChargeInvoice',
- // action: action,
- // user: req.user
- // });
- // }
- // // Invoke the billing implementation (stripe)
- // let billingInvoice:BillingInvoice = await billingImpl.getInvoice(invoice.invoiceID);
- // billingInvoice = await billingImpl.chargeInvoice(billingInvoice);
- // res.json({
- // succeeded: true,
- // status: billingInvoice.status
- // });
- }
-
public static async handleBillingWebHook(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -403,11 +403,7 @@ export enum ServerAction {
NOTIFICATIONS = 'Notifications',
BILLING = 'Billing',
- BILLING_TAX = 'BillingTax',
BILLING_TRANSACTION = 'BillingTransaction',
- BILLING_SEND_INVOICE = 'BillingSendInvoice',
- BILLING_CREATE_INVOICE = 'BillingCreateInvoice',
- BILLING_CREATE_INVOICE_ITEM = 'BillingCreateInvoiceItem',
BILLING_SYNCHRONIZE_USERS = 'BillingSynchronizeUsers',
BILLING_SYNCHRONIZE_USER = 'BillingSynchronizeUser',
BILLING_FORCE_SYNCHRONIZE_USER = 'BillingForceSynchronizeUser',
@@ -419,10 +415,7 @@ export enum ServerAction {
BILLING_PERFORM_OPERATIONS = 'BillingPeriodicOperations',
BILLING_FORCE_SYNCHRONIZE_USER_INVOICES = 'BillingForceSynchronizeUserInvoices',
BILLING_DOWNLOAD_INVOICE = 'BillingDownloadInvoice',
- BILLING_CREATE_TRANSACTION_INVOICE = 'BillingCreateTransactionInvoice',
BILLING_NEW_INVOICE = 'BillingNewInvoice',
- BILLING_NEW_INVOICE_PAID = 'BillingNewInvoicePaid',
- BILLING_NEW_INVOICE_OPEN = 'BillingNewInvoiceOpen',
BILLING_SETUP_PAYMENT_METHOD = 'BillingSetupPaymentMethod',
BILLING_PAYMENT_METHODS = 'BillingPaymentMethods',
BILLING_DELETE_PAYMENT_METHOD = 'BillingDeletePaymentMethod',

billing - cleanup of unused constants