File: hbci_version.go

package info (click to toggle)
golang-github-mitch000001-go-hbci 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,468 kB
  • sloc: java: 1,092; makefile: 5
file content (104 lines) | stat: -rw-r--r-- 4,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package segment

import (
	"fmt"
	"time"

	"github.com/mitch000001/go-hbci/domain"
)

// SupportedHBCIVersions maps integer version codes to HBCIVersions
var SupportedHBCIVersions = map[int]HBCIVersion{
	220: HBCI220,
	300: FINTS300,
}

// HBCIVersion defines segment constructors for a HBCI version
type HBCIVersion struct {
	version                       int
	PinTanEncryptionHeader        func(clientSystemId string, keyName domain.KeyName) *EncryptionHeaderSegment
	RDHEncryptionHeader           func(clientSystemId string, keyName domain.KeyName, key []byte) *EncryptionHeaderSegment
	SignatureHeader               func() *SignatureHeaderSegment
	PinTanSignatureHeader         func(controlReference string, clientSystemId string, keyName domain.KeyName) *SignatureHeaderSegment
	RDHSignatureHeader            func(controlReference string, signatureId int, clientSystemId string, keyName domain.KeyName) *SignatureHeaderSegment
	SignatureEnd                  func() *SignatureEndSegment
	SynchronisationRequest        func(modus SyncMode) *SynchronisationRequestSegment
	AccountBalanceRequest         func(account domain.AccountConnection, allAccounts bool) AccountBalanceRequest
	AccountTransactionRequest     func(account domain.AccountConnection, allAccounts bool) *AccountTransactionRequestSegment
	SepaAccountTransactionRequest func(account domain.InternationalAccountConnection, allAccounts bool) *AccountTransactionRequestSegment
	StatusProtocolRequest         func(from, to time.Time, maxEntries int, continuationReference string) StatusProtocolRequest
	TanProcess4Request            func(referencingSegmentID string) *TanRequestSegment
}

// Version returns the HBCI version as integer
func (v HBCIVersion) Version() int {
	return v.version
}

// Builder represents a builder which returns certain builders based on the
// provided versions
type Builder interface {
	AccountBalanceRequest(account domain.AccountConnection, allAccounts bool) (AccountBalanceRequest, error)
	AccountTransactionRequest(account domain.AccountConnection, allAccounts bool) (*AccountTransactionRequestSegment, error)
	SepaAccountTransactionRequest(account domain.InternationalAccountConnection, allAccounts bool) (*AccountTransactionRequestSegment, error)
	StatusProtocolRequest(from, to time.Time, maxEntries int, continuationReference string) (StatusProtocolRequest, error)
}

// NewBuilder returns a new Builder which uses the supported segments to
// identify which segment to use
func NewBuilder(supportedSegments []VersionedSegment) Builder {
	segments := make(map[string][]int)
	for _, s := range supportedSegments {
		segments[s.ID] = append(segments[s.ID], s.Version)
	}
	return &builder{segments}
}

type builder struct {
	supportedSegments map[string][]int
}

func (b *builder) AccountBalanceRequest(account domain.AccountConnection, allAccounts bool) (AccountBalanceRequest, error) {
	versions, ok := b.supportedSegments["HISALS"]
	if !ok {
		return nil, fmt.Errorf("Segment %s not supported", "HKSAL")
	}
	request, err := AccountBalanceRequestBuilder(versions)
	if err != nil {
		return nil, err
	}
	return request(account, allAccounts), nil
}
func (b *builder) AccountTransactionRequest(account domain.AccountConnection, allAccounts bool) (*AccountTransactionRequestSegment, error) {
	versions, ok := b.supportedSegments["HIKAZS"]
	if !ok {
		return nil, fmt.Errorf("Segment %s not supported", "HKKAZ")
	}
	request, err := AccountTransactionRequestBuilder(versions)
	if err != nil {
		return nil, err
	}
	return request(account, allAccounts), nil
}
func (b *builder) SepaAccountTransactionRequest(account domain.InternationalAccountConnection, allAccounts bool) (*AccountTransactionRequestSegment, error) {
	versions, ok := b.supportedSegments["HIKAZS"]
	if !ok {
		return nil, fmt.Errorf("Segment %s not supported", "HKKAZ")
	}
	request, err := SepaAccountTransactionRequestBuilder(versions)
	if err != nil {
		return nil, err
	}
	return request(account, allAccounts), nil
}
func (b *builder) StatusProtocolRequest(from, to time.Time, maxEntries int, continuationReference string) (StatusProtocolRequest, error) {
	versions, ok := b.supportedSegments["HIPRO"]
	if !ok {
		return nil, fmt.Errorf("Segment %s not supported", "HKPRO")
	}
	request, err := StatusProtocolRequestBuilder(versions)
	if err != nil {
		return nil, err
	}
	return request(from, to, maxEntries, continuationReference), nil
}