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 +}