tariffs only.Expand description
An auditable pricing engine: what a charging session costs, and exactly why.
OCPI is the only protocol that carries both the tariff and the metering data, which means the cost of a session is computable from what crosses the wire. Doing that well is worth a lot: it is how an eMSP checks a CPO’s invoice, how a CPO checks its own, and how the Payments module’s financial advice confirmations get reconciled against the CDRs they belong to.
§What makes this engine different
The answer is auditable. CostBreakdown does not just say 12.28; it says which
quantity was billed for each dimension, what step_size did to it, which Tariff Element and
which Price Component priced it, and why that element was selected.
The arithmetic is exact. Every value is a Number, a decimal.
There is no f64 anywhere in this module.
The undefined parts are parameters. The specification says nothing about rounding, on
purpose, and OCPI 3.0 removes step_size altogether. Both are settings on
PricingPolicy rather than assumptions baked into the code.
§Example
use ocpi_kit::tariffs::{PricedPeriod, PricedSession, PricingEngine, TimeZone};
use ocpi_kit::types::DateTime;
let session = PricedSession::new("2024-01-15T10:00:00Z".parse()?, TimeZone::named("Europe/Berlin")?)
.with_period(PricedPeriod {
energy_kwh: "20".parse()?,
..PricedPeriod::new("2024-01-15T10:00:00Z".parse()?)
});
let breakdown = PricingEngine::new().price(&session, &[tariff])?;
assert_eq!(breakdown.total_excl_vat.to_string(), "5.00");
assert_eq!(breakdown.total_incl_vat.to_string(), "5.50");Spec: 2.3.0 §mod_tariffs_tariffs_module, §mod_cdrs_step_size
Structs§
- Applied
Component - The exact Price Component that priced a segment.
- Cost
Breakdown - The complete, auditable result of pricing a session.
- Dimension
Cost - What one dimension of a session cost, and how that was arrived at.
- Priced
Period - One charging period, reduced to what pricing needs.
- Priced
Segment - One stretch of a session priced at a single rate.
- Priced
Session - A session reduced to what the pricing engine needs.
- Pricing
Engine - Prices sessions against Tariffs.
- Pricing
Note - Something the engine wants the reader of a breakdown to know.
- Pricing
Policy - How and when to round money.
- TaxLine
- One tax line of the result.
- Time
Zone - The IANA time zone a Location is in, which the local-time restrictions are expressed in.
Enums§
- Price
Limit Applied - Why the total was clamped.
- Pricing
Error - Why a session could not be priced.
- Pricing
Note Code - What a
PricingNoteis about, without reading the English. - Quantisation
- Whether consumed quantities are billed in
step_sizeblocks.