cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

commit 4c628cc57596e4d75eedab2e19848ee28b18267b
parent c11e29d793fdc1c2871938b9734d54752dc7509d
Author: Joel-Haeberli <haebu@rubigen.ch>
Date:   Mon,  3 Jun 2024 18:15:13 +0200

fix: db query

Diffstat:
Mc2ec/amount_test.go | 27+++++++++++++++++++++++++++
Mc2ec/wallee-client.go | 4+++-
Mc2ec/wallee-models.go | 2+-
3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/c2ec/amount_test.go b/c2ec/amount_test.go @@ -21,6 +21,7 @@ package main import ( "fmt" + "strconv" "testing" ) @@ -297,3 +298,29 @@ func TestFeesSub(t *testing.T) { fmt.Println("refundable amount:", amnt) } } + +func TestFloat64ToAmount(t *testing.T) { + + type tuple struct { + a string + b int + } + + floats := map[float64]tuple{ + 2.345: {"2.345", 3}, + 4.204: {"4.204", 3}, + 1293.2: {"1293.2", 1}, + 1294.2: {"1294.20", 2}, + 1295.02: {"1295.02", 2}, + 2424.003: {"2424.003", 3}, + } + + for k, v := range floats { + + str := strconv.FormatFloat(k, 'f', v.b, 64) + if str != v.a { + fmt.Println("failed! expected", v.a, "got", str) + t.FailNow() + } + } +} diff --git a/c2ec/wallee-client.go b/c2ec/wallee-client.go @@ -192,7 +192,9 @@ func (w *WalleeClient) Refund(transactionId string) error { return err } - amountWithFeesStr := fmt.Sprintf("%s:%s", CONFIG.Server.Currency, decodedWalleeTransaction.CompletedAmount) + amountFloatFrmt := strconv.FormatFloat(decodedWalleeTransaction.CompletedAmount, 'f', CONFIG.Server.CurrencyFractionDigits, 64) + LogInfo("wallee-client", fmt.Sprintf("converted %f (float) to %s (string)", decodedWalleeTransaction.CompletedAmount, amountFloatFrmt)) + amountWithFeesStr := fmt.Sprintf("%s:%s", CONFIG.Server.Currency, amountFloatFrmt) amountWithFees, err := ParseAmount(amountWithFeesStr, CONFIG.Server.CurrencyFractionDigits) if err != nil { LogError("wallee-client", err) diff --git a/c2ec/wallee-models.go b/c2ec/wallee-models.go @@ -189,7 +189,7 @@ type WalleeTransaction struct { AutoConfirmationEnabled bool `json:"autoConfirmationEnabled"` BillingAddress interface{} `json:"billingAddress"` ChargeRetryEnabled bool `json:"chargeRetryEnabled"` - CompletedAmount string `json:"completedAmount"` + CompletedAmount float64 `json:"completedAmount"` CompletedOn interface{} `json:"completedOn"` CompletionBehavior string `json:"completionBehavior"` CompletionTimeoutOn interface{} `json:"completionTimeoutOn"`