billing - check whether access control is ON
MODIFY
src/assets/server/rest/v1/schemas/user/user-default-tag-car-get.json
src/assets/server/rest/v1/schemas/user/user-default-tag-car-get.json
"UserID": {
"$ref": "user#/definitions/id"
},
+ "ChargingStationID": {
+ "$ref": "common#/definitions/string-ids"
+ },
"ProjectFields": {
"$ref": "common#/definitions/projectFields"
}

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -769,6 +769,12 @@ export default class StripeBillingIntegration extends BillingIntegration {
withBillingActive: false
};
}
+ if (!transaction.chargeBox?.siteArea?.accessControl) {
+ return {
+ // Do not bill sessions where the Access Control is OFF
+ withBillingActive: false
+ };
+ }
// Check Stripe
await this.checkConnection();
// Check Transaction

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -367,7 +367,7 @@ export default class OCPPService {
// Enrich
this.enrichStartTransaction(tenant, startTransaction, chargingStation);
// Create Transaction
- const newTransaction = await this.createTransaction(tenant, startTransaction);
+ const newTransaction = await this.createTransaction(tenant, chargingStation, startTransaction);
// Check User
const { user, tag } = await Authorizations.isAuthorizedToStartTransaction(
tenant, chargingStation, startTransaction.tagID, newTransaction, ServerAction.OCPP_START_TRANSACTION, Action.START_TRANSACTION);
@@ -1704,11 +1704,12 @@ export default class OCPPService {
}
}
- private async createTransaction(tenant: Tenant, startTransaction: OCPPStartTransactionRequestExtended): Promise<Transaction> {
+ private async createTransaction(tenant: Tenant, chargingStation: ChargingStation, startTransaction: OCPPStartTransactionRequestExtended): Promise<Transaction> {
return {
id: await TransactionStorage.findAvailableID(tenant),
issuer: true,
chargeBoxID: startTransaction.chargeBoxID,
+ chargeBox: chargingStation, // TODO - Clarify if this is allowed!!!!
tagID: startTransaction.idTag,
timezone: startTransaction.timezone,
userID: startTransaction.userID,

MODIFY
src/server/rest/v1/router/api/UserRouter.ts
src/server/rest/v1/router/api/UserRouter.ts
@@ -64,7 +64,11 @@ export default class UserRouter {
private buildRouteUserDefaultCarTag(): void {
this.router.get(`/${ServerRoute.REST_USER_DEFAULT_TAG_CAR}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = req.params.id;
+ // TODO: Backward compatibility issue - remove it as soon as possible
+ if (!req.query.UserID) {
+ // UserID was passed as an URL parameter - URL /:id/ pattern was not resolved properly client-side!
+ req.query.UserID = req.params.id;
+ }
await RouterUtils.handleServerAction(UserService.handleGetUserDefaultTagCar.bind(this), ServerAction.USER_DEFAULT_TAG_CAR, req, res, next);
});
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -17,6 +17,7 @@ import Authorizations from '../../../../authorization/Authorizations';
import BillingFactory from '../../../../integration/billing/BillingFactory';
import CSVError from 'csvtojson/v2/CSVError';
import CarStorage from '../../../../storage/mongodb/CarStorage';
+import ChargingStationStorage from '../../../../storage/mongodb/ChargingStationStorage';
import Constants from '../../../../utils/Constants';
import EmspOCPIClient from '../../../../client/ocpi/EmspOCPIClient';
import JSONStream from 'JSONStream';
@@ -80,9 +81,22 @@ export default class UserService {
);
}
}
+ let withBillingChecks = true ;
+ if (filteredRequest.ChargingStationID) {
+ // TODO - The ChargingStationID is optional but only for backward compatibility reasons - make it mandatory as soon as possible
+ const chargingStation = await ChargingStationStorage.getChargingStation(req.tenant, filteredRequest.ChargingStationID,
+ { withSiteArea: true },
+ ['id', 'siteArea.id', 'siteArea.accessControl']);
+ if (!chargingStation.siteArea.accessControl) {
+ // The access control is switched off - so billing checks are useless
+ withBillingChecks = false;
+ }
+ }
const errorCodes: Array<StartTransactionErrorCode> = [];
- // Check Billing errors
+ if (withBillingChecks) {
+ // Check for the billing prerequisites (such as the user's payment method)
await UserService.checkBillingErrorCodes(action, req.tenant, req.user, user, errorCodes);
+ }
res.json({
tag, car, errorCodes
});

MODIFY
src/types/requests/HttpUserRequest.ts
src/types/requests/HttpUserRequest.ts
@@ -102,4 +102,5 @@ export interface HttpEulaRequest {
export interface HttpUserDefaultTagCar {
UserID: string;
+ ChargingStationID?: string; // TODO: Backward-compatibility issue - This should be mandatory! - change it as soon as possible
}

billing - check whether access control is ON