package pain import ( "fmt" "time" ) func NewDocument(initParty string) *Document { return &Document{ XmlnsXsi: PAIN_XMLNS_XSI, Namespace: PAIN_XMLNS, Contents: &PainXML{ GroupHeader: NewGrpHdr(initParty), PaymentInformation: make([]PmtInf, 0), }, } } func (d *Document) SetMeta(creditorName, creditorAddr1, creditorAddr2, creditorIBAN, creditorBIC, creditorId string, collectionDate time.Time, sequenceType string) { creditor := Cdtr{ Name: creditorName, PostalAddress: PstlAdr{ Country: "NL", // XXX: make customizable? AddressLines: []AdrLine{ AdrLine(creditorAddr1), AdrLine(creditorAddr2), }, }, } creditorAccount := CdtrAcct{ Id: IBAN{ IBAN: creditorIBAN, }, } creditorAgent := CdtrAgt{ InstitutionId: FinInstnId{ BIC: creditorBIC, }, } creditorSchemeId := CdtrSchmeId{ Id: NewPartyIdSEPA3(creditorId), } paymentInfo := PmtInf{ //Id: set in Finalize() Method: "DD", PaymentMeta: PmtTpInf{ ServiceLevel: Code{ Code: "SEPA", }, LocalInstrument: Code{ Code: "CORE", }, SequenceType: sequenceType, }, CollectionDate: collectionDate.Format("2006-01-02"), Creditor: creditor, CreditorAccount: creditorAccount, CreditorAgent: creditorAgent, SchemeId: creditorSchemeId, Transactions: make([]DrctDbtTxInf, 0), } d.Contents.PaymentInformation = append(d.Contents.PaymentInformation, paymentInfo) } func (d *Document) Finalize(msgId string) error { // GroupHeader: // Set msgId /* if len(d.Contents.PaymentInformation) == 0 { return fmt.Errorf("no payment information, aborting") } if len(d.Contents.TransactionInformation) == 0 { return fmt.Errorf("no transaction information, aborting") } */ 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() } func (d *Document) AddTransaction() { }