Class: AmountDiscount

timapi.AmountDiscount(value, currency, exponent, discountId)

AmountDiscount represents a discount amount, identified with a discount id.

Extends

Overview

Members-Overview

Methods-Overview

Constructor

new AmountDiscount(value, currency, exponent, discountId)

Create amount discount using minor units.
Throws:
  • Will throw error if it's a floating point number. To make sure it's an integer you can either use Math.floor (8.6 -> 8) or Math.round (8.6 -> 9)
  • Will throw error if amount is not representable as a 52bit value. Use Number.isSafeInteger(value) to check wether value is safe or not
  • Will throw error if amount is 0
Example:
  • An amount of CHF 12.30 amount would be 1230 in minor units since CHF has an exponent of 2.
Parameters:
Name Type Description
value Number Amount in minor units as an integer value
currency timapi.constants.Currency Currency of given amount
exponent Number Optional: specific exponent (otherwise defined by currency)
discountId String Discount type.

Member-List

currency :timapi.constants.Currency

Currency to use for transaction.
Overrides:

discountId :String

Discount type.

exponent :Number

Exponent.
Overrides:

value :Number

Amount in minor units as integer value.
Overrides:

Methods

(static) copy(amountDiscount) → {timapi.AmountDiscount}

Creates a copy of a timapi.AmountDiscount object.
Parameters:
Name Type Description
amountDiscount timapi.AmountDiscount Original
Returns:
Copy of original

Type: timapi.AmountDiscount

(static) fromMajorUnits(valueMajor, currency, exponent, discountId) → {timapi.AmountDiscount}

Create amount discount from major amount-value.
Parameters:
Name Type Description
valueMajor Number Amount-value in major units as an floating point value
currency timapi.constants.Currency Currency of given amount
exponent Number Optional: specific exponent (otherwise defined by currency)
discountId String Discount type.
Throws:
  • Will throw error if amount in minor units is not representable as a 52bit value
  • Will throw error if amount is 0
Returns:
Created discount amount

Type: timapi.AmountDiscount

Example
An amount of CHF 12.30 amount would be 12.3 in major units (1230 in minor units) since CHF has an exponent of 2.

getDecimalValue() → {Number}

Get amount-value in major units as floating point value.
Overrides:
Returns:
Amount-value in major units as floating point value

Type: Number

setCurrency(currency)

Set currency to use for transaction. Also sets the exponent. Assign to currency property directly if you want to keep the exponent unchanged.
Parameters:
Name Type Description
currency timapi.constants.Currency Currency
Overrides:

setDecimalValue(value)

Set amount-value in major units as floating point value
Parameters:
Name Type Description
value Number Amount-value in major units as floating point value (e.g. 10.5)
Overrides:
Throws:
  • Will throw error if amount in minor units is not representable as a 52bit value
  • Will throw error if amount is 0

setValue(value)

Set value of amount.
Parameters:
Name Type Description
value Number Value of amount as an integer value
Overrides:
Throws:
  • Will throw error if it's a floating point number. To make sure it's an integer you can either use Math.floor (8.6 -> 8) or Math.round (8.6 -> 9)
  • Will throw error if amount is not representable as a 52bit value. Use Number.isSafeInteger(value) to check wether value is safe or not
  • Will throw error if amount is 0

toString() → {String}

String representation for debugging purpose.
Overrides:
Returns:
String representation for debugging purpose

Type: String