Browse Source

WIP: fixed some XSD issues, still nil pointer exception

master
Gerdriaan Mulder 6 years ago
parent
commit
426e5d0d0e
  1. 11
      pain/api.go
  2. 14
      pain/pain.go
  3. 3
      pain/pain_regexp.go
  4. 3
      pain/payment_information.go

11
pain/api.go

@ -1,7 +1,7 @@
package pain
import (
// "fmt"
"fmt"
"time"
)
@ -66,9 +66,6 @@ func (d *Document) SetMeta(creditorName, creditorAddr1, creditorAddr2, creditorI
func (d *Document) Finalize(msgId string) error {
// GroupHeader:
// Calculate CtrlSum
// Set Timestamp
// Set number of transactions
// Set msgId
/*
@ -80,8 +77,12 @@ func (d *Document) Finalize(msgId string) error {
}
*/
//csum := 0.0
csum := 0.0
d.Contents.GroupHeader.MessageId = msgId
d.Contents.GroupHeader.Timestamp = time.Now().Format("2006-01-02T15:04:05")
d.Contents.GroupHeader.NumTx = fmt.Sprintf("%d", len(d.Contents.PaymentInformation[0].Transactions))
d.Contents.GroupHeader.Sum = fmt.Sprintf("%.2f", csum)
d.Contents.PaymentInformation[0].Id = msgId
return d.Valid()
}

14
pain/pain.go

@ -47,6 +47,11 @@ func (p *PainXML) Valid() error {
if len(p.PaymentInformation) < 1 {
err = append(err, "no payment information")
}
for i, pi := range p.PaymentInformation {
if e := pi.Valid(); e != nil {
err = append(err, fmt.Sprintf("payment information at %d has errors: %v", i, e))
}
}
if len(err) > 0 {
return fmt.Errorf("pain XML not valid: %v", strings.Join(err, ", "))
@ -115,12 +120,13 @@ type PartyIdSEPA1 struct {
}
type PartyIdSEPA3 struct {
Id PartySEPA2 `xml:"Id"`
// Embed PartySEPA2, because we do not need another level of <Id>
PartySEPA2
}
func NewPartyIdSEPA3(id string) PartyIdSEPA3 {
return PartyIdSEPA3{
Id: PartySEPA2{
PartySEPA2{
PrivateId: PersonIdSEPA2{
Other: RestrictedPersonIdSEPA{
Id: id,
@ -134,7 +140,7 @@ func NewPartyIdSEPA3(id string) PartyIdSEPA3 {
}
func (p *PartyIdSEPA3) Valid() error {
return p.Id.Valid()
return p.Valid()
}
type PersonIdSEPA2 struct {
@ -166,7 +172,7 @@ func (r *RestrictedPersonIdSEPA) Valid() error {
}
type RestrictedPersonIdSchemeNameSEPA struct {
Party string `xml:"Prty"` // IdentificationSchemeNameSEPA
Party string `xml:"Prtry"` // IdentificationSchemeNameSEPA
}
func (r *RestrictedPersonIdSchemeNameSEPA) Valid() error {

3
pain/pain_regexp.go

@ -21,6 +21,8 @@ var (
IBAN2007Identifier = regexp.MustCompile(`[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}`)
RestrictedPersonIdentifierSEPA = regexp.MustCompile(`[a-zA-Z]{2,2}[0-9]{2,2}([A-Za-z0-9]|[\+|\?|/|\-|:|\(|\)|\.|,|']){3,3}([A-Za-z0-9]|[\+|\?|/|\-|:|\(|\)|\.|,|']){1,28}`)
BICIdentifier = regexp.MustCompile(`[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}`)
CountryCode = regexp.MustCompile(`[A-Z]{2,2}`)
)
var (
@ -28,6 +30,7 @@ var (
"BIC": BICIdentifier,
"CreDtTm": ISODateTime,
"CtrlSum": RestrictedDecimalNumber,
"Ctry": CountryCode,
"EndToEndId": RestrictedIdentificationSEPA1,
"IBAN": IBAN2007Identifier,
"Id": RestrictedPersonIdentifierSEPA,

3
pain/payment_information.go

@ -43,6 +43,9 @@ func (pmt *PmtInf) Valid() error {
if e := pmt.SchemeId.Valid(); e != nil {
err = append(err, fmt.Sprintf("payment scheme id not valid: %v", e))
}
if len(pmt.Transactions) == 0 {
err = append(err, fmt.Sprintf("need at least 1 transaction"))
}
if len(err) > 0 {
return fmt.Errorf("payment info (Id: %q) not valid: %v", pmt.Id, strings.Join(err, ", "))

Loading…
Cancel
Save