Skip to content

Commit

Permalink
Validate CcyAmt: add .00 to integer numbers
Browse files Browse the repository at this point in the history
fixes #8
  • Loading branch information
stapelberg committed Nov 25, 2023
1 parent fa23951 commit 77a4ad4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions qrbill.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ type QRCHCcyAmt struct {
Ccy string // Currency
}

func (a QRCHCcyAmt) Validate() QRCHCcyAmt {
c := a

if c.Amt != "" {
// Some banking apps are picky regarding integer numbers (e.g. 50) and
// require a separator plus two digits (e.g. 50.00).
if !strings.Contains(c.Amt, ".") {
c.Amt += ".00"
}
}

return c
}

type QRCHRmtInfAddInf struct {
Ustrd string // Unstructured message
Trailer string // Trailer
Expand Down Expand Up @@ -194,6 +208,8 @@ func (q *QRCH) Validate() *QRCH {

clone.UltmtDbtr = clone.UltmtDbtr.Validate()

clone.CcyAmt = clone.CcyAmt.Validate()

clone.RmtInf.Tp = nonAlphanumericRe.ReplaceAllString(clone.RmtInf.Tp, "")
if v := clone.RmtInf.Tp; len(v) > 4 {
clone.RmtInf.Tp = v[:4]
Expand Down

0 comments on commit 77a4ad4

Please sign in to comment.