Skip to content

Commit

Permalink
Add go-money to display amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorAvelar committed Jun 2, 2021
1 parent 4b5b144 commit 9fdaa32
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion commands/displayers/helpers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package displayers

import (
"fmt"
"strconv"
"strings"
"time"

"github.com/Rhymond/go-money"
"github.com/VictorAvelar/mollie-api-go/v2/mollie"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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 == "" {
Expand Down

0 comments on commit 9fdaa32

Please sign in to comment.