Skip to main content

Module tariffs

Module tariffs 

Source
Available on crate feature 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§

AppliedComponent
The exact Price Component that priced a segment.
CostBreakdown
The complete, auditable result of pricing a session.
DimensionCost
What one dimension of a session cost, and how that was arrived at.
PricedPeriod
One charging period, reduced to what pricing needs.
PricedSegment
One stretch of a session priced at a single rate.
PricedSession
A session reduced to what the pricing engine needs.
PricingEngine
Prices sessions against Tariffs.
PricingNote
Something the engine wants the reader of a breakdown to know.
PricingPolicy
How and when to round money.
TaxLine
One tax line of the result.
TimeZone
The IANA time zone a Location is in, which the local-time restrictions are expressed in.

Enums§

PriceLimitApplied
Why the total was clamped.
PricingError
Why a session could not be priced.
PricingNoteCode
What a PricingNote is about, without reading the English.
Quantisation
Whether consumed quantities are billed in step_size blocks.