libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 77918308e35c3cc9ed2f03332ac95b5ec52023eb
parent 211de5e71511e0b3f4fbcadd7aa1c4ebf4403ae2
Author: MS <ms@taler.net>
Date:   Thu, 14 Sep 2023 16:14:35 +0200

Collecting currency after amount parsing.

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/Database.kt | 12+++++++++++-
Mbank/src/main/kotlin/tech/libeufin/bank/Helpers.kt | 3++-
Mbank/src/test/kotlin/AmountTest.kt | 3+--
3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt @@ -22,9 +22,19 @@ data class Customer( ) fun Customer.expectRowId(): Long = this.dbRowId ?: throw internalServerError("Cutsomer '${this.login}' had no DB row ID") +/** + * Represents a Taler amount. This type can be used both + * to hold database records and amounts coming from the parser. + */ data class TalerAmount( val value: Long, - val frac: Int + val frac: Int, + /** + * The currency is likely null when the object is defined + * from database records. It is instead not null when the + * object comes from the parsing of serialized amounts. + */ + val currency: String? = null ) // BIC got removed, because it'll be expressed in the internal_payto_uri. diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/Helpers.kt @@ -154,6 +154,7 @@ fun parseTalerAmount( } return TalerAmount( value = value, - frac = fraction + frac = fraction, + currency = match.destructured.component1() ) } \ No newline at end of file diff --git a/bank/src/test/kotlin/AmountTest.kt b/bank/src/test/kotlin/AmountTest.kt @@ -5,10 +5,9 @@ import tech.libeufin.bank.parseTalerAmount class AmountTest { @Test fun parseTalerAmountTest() { - parseTalerAmount("KUDOS:11") val one = "EUR:1" var obj = parseTalerAmount(one) - assert(obj.value == 1L && obj.frac == 0) + assert(obj.value == 1L && obj.frac == 0 && obj.currency == "EUR") val onePointZero = "EUR:1.00" obj = parseTalerAmount(onePointZero) assert(obj.value == 1L && obj.frac == 0)