From 9fdaa327b98b5812cdde76c388237f01d107ed50 Mon Sep 17 00:00:00 2001 From: "Victor H. Avelar" Date: Wed, 2 Jun 2021 17:20:58 +0200 Subject: [PATCH] Add go-money to display amounts --- commands/displayers/helpers.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/commands/displayers/helpers.go b/commands/displayers/helpers.go index a94b8fe..953917a 100644 --- a/commands/displayers/helpers.go +++ b/commands/displayers/helpers.go @@ -1,9 +1,12 @@ package displayers import ( + "fmt" + "strconv" "strings" "time" + "github.com/Rhymond/go-money" "github.com/VictorAvelar/mollie-api-go/v2/mollie" ) @@ -50,7 +53,10 @@ func fallbackSafeAmount(a *mollie.Amount) string { return "--- ---" } - return stringCombinator(" ", a.Value, a.Currency) + clean := strings.Replace(a.Value, ".", "", -1) + + val, _ := strconv.ParseInt(clean, 10, 64) + return money.New(val, a.Currency).Display() } func fallbackSafePaymentMethod(pm mollie.PaymentMethod) string { @@ -69,6 +75,14 @@ func fallbackSafeAppFee(af *mollie.ApplicationFee) string { return fallbackSafeAmount(af.Amount) } +func fallbackSafeIssuers(i []*mollie.PaymentMethodIssuer) string { + if len(i) == 0 { + return "N/A" + } + + return fmt.Sprintf("%v", len(i)) +} + func stringCombinator(s string, parts ...string) string { for i, v := range parts { if v == "" {