5 changed files with 170 additions and 5 deletions
@ -0,0 +1,2 @@ |
|||
createbatch |
|||
config.go |
|||
@ -0,0 +1,27 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"encoding/xml" |
|||
"fmt" |
|||
"log" |
|||
"time" |
|||
|
|||
"src.wolkict.net/sepa/pain" |
|||
) |
|||
|
|||
func main() { |
|||
d := pain.NewDocument("PayPro B.V") |
|||
d.SetMeta(CREDITOR_NAME, CREDITOR_ADDR1, CREDITOR_ADDR2, CREDITOR_IBAN, CREDITOR_BIC, CREDITOR_ID, |
|||
time.Date(2020, time.January, 30, 12, 0, 0, 0, time.UTC), "RCUR") |
|||
err := d.Finalize("asdfasdf") |
|||
if err != nil { |
|||
log.Fatalf("finalizing failed: %v", err) |
|||
} |
|||
|
|||
xml, err := xml.Marshal(d) |
|||
if err != nil { |
|||
log.Fatalf("marshaling failed: %v", err) |
|||
} |
|||
|
|||
fmt.Printf("%v", string(xml)) |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
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), |
|||
TransactionInformation: make([]TxInf, 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:
|
|||
// Calculate CtrlSum
|
|||
// Set Timestamp
|
|||
// Set number of transactions
|
|||
// 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
|
|||
|
|||
return d.Valid() |
|||
} |
|||
|
|||
func (d *Document) AddTransaction() { |
|||
|
|||
} |
|||
Loading…
Reference in new issue