Calculates graduated pricing totals and breakdowns for tiered unit pricing.
// Source: https://github.com/louispy/stripemeter | License: MIT | Copyright 2025 StripeMeter Contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Graduated pricing calculator
* Similar to tiered but with flat fees per tier
*/
import Decimal from 'decimal.js';
import { PriceTier, toDecimal, roundToCurrency } from '../models/pricing-models';
export function calculateGraduatedPrice(
quantity: number,
tiers: PriceTier[]
): {
total: number;
breakdown: Array<{
tier: number;
units: number;
unitPrice: number;
flatFee: number;
subtotal: number;
}>;
} {
const breakdown: Array<{
tier: number;
units: number;
unitPrice: number;
flatFee: number;
subtotal: number;
}> = [];
let remaining = toDecimal(quantity);
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key