From 65ba799825a8ad2589e88d65d0462568a54e1558 Mon Sep 17 00:00:00 2001 From: Gerdriaan Mulder Date: Fri, 24 Jan 2020 00:11:40 +0100 Subject: [PATCH] AddTransaction: add preliminary structure --- pain/api.go | 6 +++++- pain/payment_information_transactions.go | 25 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pain/api.go b/pain/api.go index fe6a043..0b34ee1 100644 --- a/pain/api.go +++ b/pain/api.go @@ -87,6 +87,10 @@ func (d *Document) Finalize(msgId string) error { return d.Valid() } -func (d *Document) AddTransaction() { +func (d *Document) AddTransaction(tx *DrctDbtTxInf) error { + if len(d.Contents.PaymentInformation) == 0 { + return fmt.Errorf("payment information not yet initialized") + } + return nil } diff --git a/pain/payment_information_transactions.go b/pain/payment_information_transactions.go index 7349fb2..b8c2e0f 100644 --- a/pain/payment_information_transactions.go +++ b/pain/payment_information_transactions.go @@ -15,6 +15,31 @@ type DrctDbtTxInf struct { Info RmtInf `xml:"RmtInf"` } +func NewDirectDebitTransaction(debtor Dbtr, account DbtrAcct, mandateInfo MndtRltdInf, amount float64, additionalInfo string) DrctDbtTxInf { + e2eid := fmt.Sprintf("%v%4d", time.Now().Format("20060102"), 4) // TODO: inform this function of current number of transactions + return DrctDbtTxInf{ + Id: PaymentId{ + InstrumentId: "asdfasdf", + EndToEndId: e2eid, + }, + Amount: CurrencyWithAmount{ + Currency: "EUR", + Value: fmt.Sprintf("%.2f", amount), + }, + Transaction: DrctDbtTx{ + MandateRelatedInfo: mandateInfo, + }, + Agent: DbtrAgt{ + InstitutionId: FinInstnId{ + BIC: "KNABNL2H", // fixme + }, + }, + Debtor: debtor, + Account: account, + Info: additionalInfo, + } +} + func (d *DrctDbtTxInf) Valid() error { var err []string if e := d.Id.Valid(); e != nil {