modules
@epilot/pricing / Exports
@epilot/pricing
Table of contentsβ
Enumerationsβ
Interfacesβ
Type Aliasesβ
- AmountFormatter
- ComputeAggregatedAndPriceTotals
- Currency
- DineroConvertor
- PriceTierDisplayMode
- PricingDetails
- RelationAttributeValue
- Tax
- TaxAmountBreakdown
- TimeFrequency
- TimeFrequencyNormalizerMatrix
Variablesβ
- BillingPeriods
- DECIMAL_PRECISION
- DEFAULT_CURRENCY
- GENERIC_UNIT_DISPLAY_LABEL
- TaxRates
- timeFrequencyNormalizerMatrix
Functionsβ
- computeAggregatedAndPriceTotals
- computePriceComponent
- computePriceItemDetails
- computeQuantities
- extractPricingEntitiesBySlug
- formatAmount
- formatAmountFromString
- formatPriceUnit
- getDisplayTierByQuantity
- getTierDescription
- isPriceBuiltInUnit
- isTaxInclusivePrice
- normalizePriceMappingInput
- normalizeTimeFrequency
- normalizeTimeFrequencyToDinero
- parseDecimalValue
- toDinero
- toDineroFromInteger
- toIntegerAmount
Type Aliasesβ
AmountFormatterβ
Ζ¬ AmountFormatter: ({
amount,
currency,
format,
locale,
}
: { amount
: number
| string
; currency?
: Currency
; enableSubunitDisplay?
: boolean
; format?
: string
; locale?
: string
}) => string
Type declarationβ
βΈ ({
amount,
currency,
format,
locale,
}
): string
Parametersβ
Name | Type |
---|
| {
amount,
currency,
format,
locale,
}
| Object
|
| {
amount,
currency,
format,
locale,
}.amount
| number
| string
|
| {
amount,
currency,
format,
locale,
}.currency?
| Currency
|
| {
amount,
currency,
format,
locale,
}.enableSubunitDisplay?
| boolean
|
| {
amount,
currency,
format,
locale,
}.format?
| string
|
| {
amount,
currency,
format,
locale,
}.locale?
| string
|
Returnsβ
string
Defined inβ
ComputeAggregatedAndPriceTotalsβ
Ζ¬ ComputeAggregatedAndPriceTotals: (priceItems
: PriceItemsDto
) => PricingDetails
Type declarationβ
βΈ (priceItems
): PricingDetails
Parametersβ
Name | Type |
---|---|
priceItems | PriceItemsDto |
Returnsβ
Defined inβ
Currencyβ
Ζ¬ Currency: "AED"
| "AFN"
| "ALL"
| "AMD"
| "ANG"
| "AOA"
| "ARS"
| "AUD"
| "AWG"
| "AZN"
| "BAM"
| "BBD"
| "BDT"
| "BGN"
| "BHD"
| "BIF"
| "BMD"
| "BND"
| "BOB"
| "BOV"
| "BRL"
| "BSD"
| "BTN"
| "BWP"
| "BYN"
| "BZD"
| "CAD"
| "CDF"
| "CHE"
| "CHF"
| "CHW"
| "CLF"
| "CLP"
| "CNY"
| "COP"
| "COU"
| "CRC"
| "CUC"
| "CUP"
| "CVE"
| "CZK"
| "DJF"
| "DKK"
| "DOP"
| "DZD"
| "EGP"
| "ERN"
| "ETB"
| "EUR"
| "FJD"
| "FKP"
| "GBP"
| "GEL"
| "GHS"
| "GIP"
| "GMD"
| "GNF"
| "GTQ"
| "GYD"
| "HKD"
| "HNL"
| "HRK"
| "HTG"
| "HUF"
| "IDR"
| "ILS"
| "INR"
| "IQD"
| "IRR"
| "ISK"
| "JMD"
| "JOD"
| "JPY"
| "KES"
| "KGS"
| "KHR"
| "KMF"
| "KPW"
| "KRW"
| "KWD"
| "KYD"
| "KZT"
| "LAK"
| "LBP"
| "LKR"
| "LRD"
| "LSL"
| "LYD"
| "MAD"
| "MDL"
| "MGA"
| "MKD"
| "MMK"
| "MNT"
| "MOP"
| "MRU"
| "MUR"
| "MVR"
| "MWK"
| "MXN"
| "MXV"
| "MYR"
| "MZN"
| "NAD"
| "NGN"
| "NIO"
| "NOK"
| "NPR"
| "NZD"
| "OMR"
| "PAB"
| "PEN"
| "PGK"
| "PHP"
| "PKR"
| "PLN"
| "PYG"
| "QAR"
| "RON"
| "RSD"
| "RUB"
| "RWF"
| "SAR"
| "SBD"
| "SCR"
| "SDG"
| "SEK"
| "SGD"
| "SHP"
| "SLL"
| "SOS"
| "SRD"
| "SSP"
| "STN"
| "SVC"
| "SYP"
| "SZL"
| "THB"
| "TJS"
| "TMT"
| "TND"
| "TOP"
| "TRY"
| "TTD"
| "TWD"
| "TZS"
| "UAH"
| "UGX"
| "USD"
| "USN"
| "UYI"
| "UYU"
| "UYW"
| "UZS"
| "VES"
| "VND"
| "VUV"
| "WST"
| "XAF"
| "XAG"
| "XAU"
| "XBA"
| "XBB"
| "XBC"
| "XBD"
| "XCD"
| "XDR"
| "XOF"
| "XPD"
| "XPF"
| "XPT"
| "XSU"
| "XTS"
| "XUA"
| "XXX"
| "YER"
| "ZAR"
| "ZMW"
| "ZWL"
ISO 4217 CURRENCY CODES as specified in the documentation Taken from https://www.iso.org/iso-4217-currency-codes.html sorted and parsed
Defined inβ
node_modules/@types/dinero.js/index.d.ts:96
DineroConvertorβ
Ζ¬ DineroConvertor: (unitAmountDecimal
: string
, currency?
: Currency
) => dinero.Dinero
Type declarationβ
βΈ (unitAmountDecimal
, currency?
): dinero.Dinero
Parametersβ
Name | Type |
---|---|
unitAmountDecimal | string |
currency? | Currency |
Returnsβ
dinero.Dinero
Defined inβ
PriceTierDisplayModeβ
Ζ¬ PriceTierDisplayMode: Components.Schemas.PriceTierDisplayMode
Defined inβ
PricingDetailsβ
Ζ¬ PricingDetails: Components.Schemas.PricingDetails
Defined inβ
RelationAttributeValueβ
Ζ¬ RelationAttributeValue: Object
Type declarationβ
Name | Type |
---|---|
$relation | { _schema : string ; _tags : string [] ; entity_id : string }[] |
Defined inβ
Taxβ
Ζ¬ Tax: Components.Schemas.Tax
Defined inβ
TaxAmountBreakdownβ
Ζ¬ TaxAmountBreakdown: Components.Schemas.TaxAmountBreakdown
Defined inβ
TimeFrequencyβ
Ζ¬ TimeFrequency: Exclude
<BillingPeriod
, "one_time"
>
Defined inβ
TimeFrequencyNormalizerMatrixβ
Ζ¬ TimeFrequencyNormalizerMatrix: { [outputFrequency in TimeFrequency]: { [inputFrequency in TimeFrequency]: Object } }
A interface for a normalized time frequencies transformation matrix
Eg. Output must be monthly, input was yearly
timeFrequencyNormalizerMatrix.yearly.monthly
Defined inβ
src/normalizers/constants.ts:15
Variablesβ
BillingPeriodsβ
β’ Const
BillingPeriods: Set
<string
>
Defined inβ
DECIMAL_PRECISIONβ
β’ Const
DECIMAL_PRECISION: 12
Defined inβ
DEFAULT_CURRENCYβ
β’ Const
DEFAULT_CURRENCY: "EUR"
Defined inβ
GENERIC_UNIT_DISPLAY_LABELβ
β’ Const
GENERIC_UNIT_DISPLAY_LABEL: "unit"
Defined inβ
TaxRatesβ
β’ Const
TaxRates: Readonly
<{ nontaxable
: number
= 0; reduced
: number
= 0.07; standard
: number
= 0.19 }>
Defined inβ
timeFrequencyNormalizerMatrixβ
β’ Const
timeFrequencyNormalizerMatrix: TimeFrequencyNormalizerMatrix
A normalized time frequencies transformation matrix
See also TimeFrequencyNormalizerMatrix
Defined inβ
src/normalizers/constants.ts:29
Functionsβ
computeAggregatedAndPriceTotalsβ
βΈ computeAggregatedAndPriceTotals(priceItems
): PricingDetails
Computes all the integer amounts for the price items using the string decimal representation defined on prices unit_amount field. All totals are computed with a decimal precision of DECIMAL_PRECISION. After the calculations the integer amounts are scaled to a precision of 2.
This compute function computes both line items and aggregated totals.
Parametersβ
Name | Type |
---|---|
priceItems | PriceItemsDto |
Returnsβ
PricingDetails
Defined inβ
computePriceComponentβ
βΈ computePriceComponent(priceItemComponent
, priceMappings
, parentQuantity
): PriceItem
Parametersβ
Name | Type |
---|---|
priceItemComponent | PriceItemDto |
priceMappings | PriceInputMappings |
parentQuantity | number |
Returnsβ
PriceItem
Defined inβ
computePriceItemDetailsβ
βΈ computePriceItemDetails(priceItem
): PricingDetails
Computes the pricing details for a given PriceItem in isolation. The computed price item will be the only entry from the PricingDetails items array.
Parametersβ
Name | Type | Description |
---|---|---|
priceItem | PriceItemDto | CompositePriceItemDto | the price item to compute |
Returnsβ
PricingDetails
the pricing details
Defined inβ
computeQuantitiesβ
βΈ computeQuantities(price
, quantity?
, priceMapping?
): Object
Parametersβ
Name | Type |
---|---|
price | Price |
quantity? | number |
priceMapping? | PriceInputMapping |
Returnsβ
Object
Name | Type |
---|---|
isUsingPriceMappingToSelectTier | boolean |
quantityToSelectTier | number |
safeQuantity | number |
unitAmountMultiplier | number |
Defined inβ
extractPricingEntitiesBySlugβ
βΈ extractPricingEntitiesBySlug(priceItems
): PricingEntitiesExtractResult
Extracts the pricing entities from a list of price items.
Parametersβ
Name | Type | Description |
---|---|---|
priceItems | (PriceItem | CompositePriceItem )[] | a list of price items |
Returnsβ
the product and price relations from the price items grouped by their slug.
Defined inβ
formatAmountβ
βΈ formatAmount(Β«destructuredΒ»
): string
Parametersβ
Name | Type |
---|---|
Β«destructuredΒ» | Object |
βΊΒ amount | string | number |
βΊΒ currency? | Currency |
βΊΒ enableSubunitDisplay? | boolean |
βΊΒ format? | string |
βΊΒ locale? | string |
Returnsβ
string
Defined inβ
formatAmountFromStringβ
βΈ formatAmountFromString(Β«destructuredΒ»
): string
Formats a decimal amount (string) to the desired user-displayable format
Parametersβ
Name | Type |
---|---|
Β«destructuredΒ» | Object |
βΊΒ currency? | Currency |
βΊΒ decimalAmount | string |
βΊΒ enableSubunitDisplay? | boolean |
βΊΒ format? | string |
βΊΒ locale? | string |
βΊΒ precision? | number |
βΊΒ useRealPrecision? | boolean |
Returnsβ
string
- The user-displayable formatted amount
Defined inβ
formatPriceUnitβ
βΈ formatPriceUnit(unit
, hideGenericUnitLabel?
): string
Formats built-in price units into a displayable representation. Eg. kw -> kW
Parametersβ
Name | Type |
---|---|
unit | string |
hideGenericUnitLabel? | boolean |
Returnsβ
string
the formatted unit
Defined inβ
getDisplayTierByQuantityβ
βΈ getDisplayTierByQuantity(tiers
, quantity
, pricingModel
): PriceTier
This function returns the price tier that matches the input quantity.
Parametersβ
Name | Type | Description |
---|---|---|
tiers | PriceTier [] | The price tiers. |
quantity | number | The quantity. |
pricingModel | "per_unit" | "tiered_graduated" | "tiered_volume" | "tiered_flatfee" | PricingModel | The pricing model. |
Returnsβ
PriceTier
The selected tier.
Defined inβ
getTierDescriptionβ
βΈ getTierDescription(pricingModel
, tier
, unit
, locale
, currency
, t
, options?
): string
Get the tier description for a tiered price. This function will return a string describing the price, based on the tier and unit.
Parametersβ
Name | Type | Description |
---|---|---|
pricingModel | PricingModel | - |
tier | PriceTier | The price tier. |
unit | string | The price unit. |
locale | string | The locale to use when formatting the price. |
currency | Currency | The currency to use when formatting |
t | (key : string , options? : { defaultValue? : string ; ns : string }) => string | - |
options | Object | - |
options.enableSubunitDisplay? | boolean | - |
options.showStartsAt? | boolean | - |
Returnsβ
string
The tier description.
Defined inβ
isPriceBuiltInUnitβ
βΈ isPriceBuiltInUnit(unit
): unit is string
Checks whether a price unit is a built-in unit or not.
Parametersβ
Name | Type | Description |
---|---|---|
unit | string | the built-in unit code or user custom unit |
Returnsβ
unit is string
true if the unit is a built-in unit
Defined inβ
isTaxInclusivePriceβ
βΈ isTaxInclusivePrice(price
): boolean
Checks whether a price is tax inclusive or not.
Parametersβ
Name | Type | Description |
---|---|---|
price | Price | the price object |
Returnsβ
boolean
true if the price is tax inclusive, false otherwise. defaults to true.
Defined inβ
normalizePriceMappingInputβ
βΈ normalizePriceMappingInput(priceMapping
, price
): Dinero
This function takes in a quantity, block mapping number, block mapping frequency, price, and parent quantity and returns the normalized quantity. The block mapping number and block mapping frequency are used to calculate the normalized quantity. The normalized quantity is the quantity multiplied by the block mapping number and block mapping frequency. The block mapping number and block mapping frequency are converted to dinero objects and then multiplied with the quantity. The normalized quantity is then multiplied by the parent quantity and returned.
Parametersβ
Name | Type | Description |
---|---|---|
priceMapping | PriceInputMapping | - |
price | Price | The price to be used to calculate the normalized quantity |
Returnsβ
Dinero
The normalized quantity
Defined inβ
normalizeTimeFrequencyβ
βΈ normalizeTimeFrequency(timeValue
, timeValueFrequency
, targetTimeFrequency
, precision?
): number
This function will normalize an inputted value of a specific time frequency to the desired time frequency based on constant values defined here timeFrequencyNormalizerMatrix.
The default precision is set to 4 decimal places.
Parametersβ
Name | Type | Description |
---|---|---|
timeValue | number | the value in time that will be normalized |
timeValueFrequency | TimeFrequency | the current time frequency of the value |
targetTimeFrequency | TimeFrequency | the time frequency the value will be normalized to |
precision? | number | the precision of the normalized value |
Returnsβ
number
normalizedFrequencyInput
See also TimeFrequency
Defined inβ
normalizeTimeFrequencyToDineroβ
βΈ normalizeTimeFrequencyToDinero(timeValue
, timeValueFrequency
, targetTimeFrequency
, precision?
): Dinero
This function will normalize an inputted value of a specific time frequency to the desired time frequency based on constant values defined here timeFrequencyNormalizerMatrix.
The default dinerojs precision is set to 12 decimal places.
Parametersβ
Name | Type | Description |
---|---|---|
timeValue | number | the value in time that will be normalized |
timeValueFrequency | TimeFrequency | the current time frequency of the value |
targetTimeFrequency | TimeFrequency | the time frequency the value will be normalized to |
precision? | number | - |
Returnsβ
Dinero
a DineroJS object representing the normalized frequency input
See also TimeFrequency
Defined inβ
parseDecimalValueβ
βΈ parseDecimalValue(value
): string
Converts a decimal string value into a valid decimal amount value, without any thousand separators, using dot as the decimal separator.
Parametersβ
Name | Type | Description |
---|---|---|
value | string | The decimal string value to convert |
Returnsβ
string
A valid decimal amount value
Defined inβ
toDineroβ
βΈ toDinero(unitAmountDecimal
, currency?
): Dinero
Convert an amount decimal and currency into a dinero object.
Parametersβ
Name | Type |
---|---|
unitAmountDecimal | string |
currency? | Currency |
Returnsβ
Dinero
Defined inβ
toDineroFromIntegerβ
βΈ toDineroFromInteger(integerAmount
, currency?
): Dinero
Utility mapper from Integer amount into DineroJS object using DECIMAL_PRECISION (12).
Parametersβ
Name | Type |
---|---|
integerAmount | number |
currency? | Currency |
Returnsβ
Dinero
Defined inβ
toIntegerAmountβ
βΈ toIntegerAmount(decimalAmount
): number
Converts a string decimal amount to an integer amount with 2 digits precision.
Parametersβ
Name | Type | Description |
---|---|---|
decimalAmount | string | a string decimal amount |
Returnsβ
number
the decimal amount represent as an integer scaled to 2 decimal places precision.