pricing - remove featrure toggles
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -1027,13 +1027,8 @@ export default class StripeBillingIntegration extends BillingIntegration {
}
private convertToBillingInvoiceItem(transaction: Transaction) : BillingInvoiceItem {
- if (FeatureToggles.isFeatureActive(Feature.PRICING_NEW_MODEL) && transaction.pricingModel) {
- // Built-in Pricing
return this.convertPricingDataToBillingInvoiceItem(transaction);
}
- // Simple Pricing - Do it the old way!
- return this.convertSimplePricingToBillingInvoiceItem(transaction);
- }
private convertPricingDataToBillingInvoiceItem(transaction: Transaction) : BillingInvoiceItem {
const transactionID = transaction.id;
@@ -1107,46 +1102,6 @@ export default class StripeBillingIntegration extends BillingIntegration {
return pricingConsumptionData;
}
- private convertSimplePricingToBillingInvoiceItem(transaction: Transaction) : BillingInvoiceItem {
- // Destructuring transaction.stop
- const { price: unitPrice, priceUnit: currency, roundedPrice, totalConsumptionWh, timestamp } = transaction.stop;
- const transactionID = transaction.id;
- const itemDescription = this.buildLineItemDescription(transaction);
- const quantity = Utils.createDecimal(transaction.stop.totalConsumptionWh).toNumber(); // Wh
- const amount = roundedPrice; // Total amount for the line item
- // -------------------------------------------------------------------------------
- const taxes = this.getTaxRateIds();
- // Build a billing invoice item based on the transaction
- const billingInvoiceItem: BillingInvoiceItem = {
- transactionID,
- currency,
- pricingData: [{
- energy: {
- unitPrice,
- itemDescription,
- amount,
- roundedAmount: Utils.createDecimal(amount).times(100).trunc().div(100).toNumber(),
- quantity,
- taxes
- }
- }],
- metadata: {
- // Let's keep track of the initial data for troubleshooting purposes
- tenantID: this.tenant.id,
- transactionID: transaction.id,
- userID: transaction.userID,
- unitPrice,
- roundedPrice,
- currency,
- totalConsumptionWh,
- begin: transaction.timestamp?.valueOf(),
- end: timestamp?.valueOf()
- }
- };
- // Returns a item representing the complete charging session (energy + parking information)
- return billingInvoiceItem ;
- }
-
public async billInvoiceItem(user: User, billingInvoiceItem: BillingInvoiceItem): Promise<BillingInvoice> {
// Let's collect the required information
let refreshDataRequired = false;

MODIFY
src/integration/pricing/PricingEngine.ts
src/integration/pricing/PricingEngine.ts
@@ -22,16 +22,12 @@ export default class PricingEngine {
public static async resolvePricingContext(tenant: Tenant, transaction: Transaction, chargingStation: ChargingStation): Promise<ResolvedPricingModel> {
// Merge the pricing definitions from the different contexts
const pricingDefinitions: ResolvedPricingDefinition[] = [];
- if (FeatureToggles.isFeatureActive(Feature.PRICING_CHECK_BACKWARD_COMPATIBILITY)) {
- // Do nothing - this should trigger a fallback to the simple pricing logic
- } else {
// pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, transaction.userID));
pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, transaction, chargingStation, PricingEntity.CHARGING_STATION, transaction.chargeBoxID.toString()));
pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, transaction, chargingStation, PricingEntity.SITE_AREA, transaction.siteAreaID.toString()));
pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, transaction, chargingStation, PricingEntity.SITE, transaction.siteID.toString()));
pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, transaction, chargingStation, PricingEntity.COMPANY, transaction.companyID.toString()));
pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, transaction, chargingStation, PricingEntity.TENANT, tenant.id));
- }
if (!transaction.timezone) {
await Logging.logWarning({
tenantID: tenant.id,

MODIFY
src/integration/pricing/PricingFactory.ts
src/integration/pricing/PricingFactory.ts
-import FeatureToggles, { Feature } from '../../utils/FeatureToggles';
import { PricingSetting, PricingSettingsType } from '../../types/Setting';
import Tenant, { TenantComponents } from '../../types/Tenant';
@@ -6,7 +5,6 @@ import BuiltInPricingIntegration from './simple-pricing/BuiltInPricingIntegratio
import PricingIntegration from './PricingIntegration';
import SapConvergentChargingPricingIntegration from './sap-convergent-charging/SapConvergentChargingPricingIntegration';
import SettingStorage from '../../storage/mongodb/SettingStorage';
-import SimplePricingIntegration from './simple-pricing/SimplePricingIntegration';
import Utils from '../../utils/Utils';
export default class PricingFactory {
@@ -25,13 +23,8 @@ export default class PricingFactory {
break;
// Simple Pricing
case PricingSettingsType.SIMPLE:
- if (FeatureToggles.isFeatureActive(Feature.PRICING_NEW_MODEL)) {
// Simple Pricing implementation
pricingIntegrationImpl = new BuiltInPricingIntegration(tenant, pricingSetting.simple);
- } else {
- // Built-in Pricing implementation
- pricingIntegrationImpl = new SimplePricingIntegration(tenant, pricingSetting.simple);
- }
break;
}
return pricingIntegrationImpl;

MODIFY
src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts
src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts
@@ -75,14 +75,10 @@ export default class BuiltInPricingIntegration extends PricingIntegration<Simple
cumulatedAmount: 0,
cumulatedRoundedAmount: 0,
};
- if (!FeatureToggles.isFeatureActive(Feature.PRICING_NEW_MODEL)) {
- throw new Error('Unexpected situation - this layer should not be called in that context');
- } else {
- // New logic - get the amount from the priced data to avoid rounding issues
+ // Get the amount from the priced data to avoid rounding issues
const { cumulatedAmount, cumulatedRoundedAmount } = this.computeCumulatedAmount(pricingModel);
pricedConsumption.cumulatedAmount = cumulatedAmount;
pricedConsumption.cumulatedRoundedAmount = cumulatedRoundedAmount;
- }
return Promise.resolve(pricedConsumption);
}

DELETE
src/integration/pricing/simple-pricing/SimplePricingIntegration.ts
-/* eslint-disable max-len */
-import { PricedConsumption, PricingSource } from '../../../types/Pricing';
-
-import Consumption from '../../../types/Consumption';
-import PricingIntegration from '../PricingIntegration';
-import { SimplePricingSetting } from '../../../types/Setting';
-import Tenant from '../../../types/Tenant';
-import Transaction from '../../../types/Transaction';
-import Utils from '../../../utils/Utils';
-
-export default class SimplePricingIntegration extends PricingIntegration<SimplePricingSetting> {
- constructor(tenant: Tenant, readonly settings: SimplePricingSetting) {
- super(tenant, settings);
- }
-
- public async startSession(transaction: Transaction, consumptionData: Consumption): Promise<PricedConsumption> {
- return this.computePrice(transaction, consumptionData);
- }
-
- public async updateSession(transaction: Transaction, consumptionData: Consumption): Promise<PricedConsumption> {
- return this.computePrice(transaction, consumptionData);
- }
-
- public async stopSession(transaction: Transaction, consumptionData: Consumption): Promise<PricedConsumption> {
- return this.computePrice(transaction, consumptionData);
- }
-
- // eslint-disable-next-line @typescript-eslint/require-await
- private async computePrice(transaction: Transaction, consumptionData: Consumption): Promise<PricedConsumption> {
- let amount: number;
- let roundedAmount: number;
- if (consumptionData.consumptionWh && typeof consumptionData.consumptionWh === 'number') {
- amount = Utils.computeSimplePrice(this.settings.price, consumptionData.consumptionWh);
- roundedAmount = Utils.truncTo(amount, 2);
- } else {
- amount = 0;
- roundedAmount = 0;
- }
- const cumulatedAmount = Utils.createDecimal(transaction.currentCumulatedPrice).plus(amount).toNumber();
- const cumulatedRoundedAmount = Utils.truncTo(cumulatedAmount, 2);
- const pricedConsumption: PricedConsumption = {
- pricingSource: PricingSource.SIMPLE,
- currencyCode: this.settings.currency,
- amount,
- roundedAmount,
- cumulatedAmount,
- cumulatedRoundedAmount
- };
- return pricedConsumption;
- }
-}

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -268,10 +268,8 @@ export default class OCPPUtils {
transaction.pricingSource = pricedConsumption.pricingSource;
transaction.currentCumulatedPrice = pricedConsumption.amount;
transaction.currentCumulatedRoundedPrice = pricedConsumption.roundedAmount;
- if (FeatureToggles.isFeatureActive(Feature.PRICING_NEW_MODEL)) {
transaction.pricingModel = pricedConsumption.pricingModel;
}
- }
break;
// Meter Values
case TransactionAction.UPDATE:

MODIFY
src/utils/FeatureToggles.ts
src/utils/FeatureToggles.ts
@@ -4,8 +4,6 @@ export enum Feature {
BILLING_SYNC_USERS,
BILLING_CHECK_THRESHOLD_ON_STOP,
BILLING_PREVENT_CUSTOMER_DELETION,
- PRICING_NEW_MODEL,
- PRICING_CHECK_BACKWARD_COMPATIBILITY,
BILLING_SHOW_PRICING_DETAIL,
}
@@ -15,8 +13,6 @@ export default class FeatureToggles {
// Feature.BILLING_SYNC_USERS, - When switched OFF the sync of the user should be implicit (LAZY mode)
Feature.BILLING_CHECK_THRESHOLD_ON_STOP,
Feature.BILLING_PREVENT_CUSTOMER_DELETION,
- Feature.PRICING_NEW_MODEL,
- // Feature.PRICING_CHECK_BACKWARD_COMPATIBILITY,
// Feature.BILLING_SHOW_PRICING_DETAIL,
];

MODIFY
test/api/BillingTestHelper.ts
test/api/BillingTestHelper.ts
@@ -450,10 +450,6 @@ export default class BillingTestHelper {
assert(billingDataStop?.invoiceNumber === null, `Invoice Number should not yet been set - Invoice Number is: ${billingDataStop?.invoiceNumber}`);
}
if (expectedPrice) {
- if (!FeatureToggles.isFeatureActive(Feature.PRICING_NEW_MODEL)
- || FeatureToggles.isFeatureActive(Feature.PRICING_CHECK_BACKWARD_COMPATIBILITY)) {
- expectedPrice = 32.32; // Expected price when using the Simple Pricing logic!
- }
// --------------------------------
// Check transaction rounded price
// --------------------------------

pricing - remove featrure toggles