From 4bbde4c542b7629bea1346b4de3d89cbd6cdda96 Mon Sep 17 00:00:00 2001 From: Gerdriaan Mulder Date: Sun, 5 Jan 2020 22:00:57 +0100 Subject: [PATCH] WIP of DrctDbtTxInf --- pain/pain_regexp.go | 2 ++ pain/payment_information_transactions.go | 36 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 pain/payment_information_transactions.go diff --git a/pain/pain_regexp.go b/pain/pain_regexp.go index 8debdd6..467fa7e 100644 --- a/pain/pain_regexp.go +++ b/pain/pain_regexp.go @@ -27,8 +27,10 @@ var ( "BIC": BICIdentifier, "CreDtTm": ISODateTime, "CtrlSum": RestrictedDecimalNumber, + "EndToEndId": RestrictionIdentificationSEPA1, "IBAN": IBAN2007Identifier, "Id": RestrictedPersonIdentifierSEPA, + "InstrId": RestrictionIdentificationSEPA1, "MsgId": RestrictedIdentificationSEPA1, "NbOfTxs": Max15NumericText, "Nm": Max70Text, diff --git a/pain/payment_information_transactions.go b/pain/payment_information_transactions.go new file mode 100644 index 0000000..7107973 --- /dev/null +++ b/pain/payment_information_transactions.go @@ -0,0 +1,36 @@ +package pain + +import ( + "fmt" + "strings" +) + +type DrctDbtTxInf struct { + Id PaymentId `xml:"PmtId"` + Amount CurrencyWithAmount `xml:"InstdAmt"` +} + +type CurrencyWithAmount struct { + Currency string `xml:"Ccy,attr"` + Value string `xml:",innerxml"` +} + +type PaymentId struct { + InstrumentId string `xml:"InstrId"` + EndToEndId string `xml:"EndToEndId"` +} + +func (p *PaymentId) Valid() error { + var err []string + if !SEPARegexps["InstrId"].MatchString(p.InstrumentId) { + err = append(err, "instrument id does not match format") + } + if !SEPARegexps["EndToEndId"].MatchString(p.EndToEndId) { + err = append(err, "end-to-end id does not match format") + } + + if len(err) > 0 { + return fmt.Errorf("payment id not valid: %v", strings.Join(err, ", ")) + } + return nil +}