| 1 |
package segment |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"strconv" |
| 6 |
|
| 7 |
"github.com/mitch000001/go-hbci/charset" |
| 8 |
"github.com/mitch000001/go-hbci/domain" |
| 9 |
"github.com/mitch000001/go-hbci/element" |
| 10 |
) |
| 11 |
|
| 12 |
type BusinessTransactionParamsSegment struct { |
| 13 |
Segment |
| 14 |
id string |
| 15 |
version int |
| 16 |
MaxJobs *element.NumberDataElement |
| 17 |
MinSignatures *element.NumberDataElement |
| 18 |
Params element.DataElementGroup |
| 19 |
} |
| 20 |
|
| 21 |
func (b *BusinessTransactionParamsSegment) Version() int { return b.version } |
| 22 |
func (b *BusinessTransactionParamsSegment) ID() string { return b.id } |
| 23 |
func (b *BusinessTransactionParamsSegment) referencedId() string { return ProcessingPreparationID } |
| 24 |
func (b *BusinessTransactionParamsSegment) sender() string { return senderBank } |
| 25 |
|
| 26 |
func (b *BusinessTransactionParamsSegment) elements() []element.DataElement { |
| 27 |
return []element.DataElement{ |
| 28 |
b.MaxJobs, |
| 29 |
b.MinSignatures, |
| 30 |
b.Params, |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
func (b *BusinessTransactionParamsSegment) UnmarshalHBCI(value []byte) error { |
| 35 |
elements, err := ExtractElements(value) |
| 36 |
if err != nil { |
| 37 |
return err |
| 38 |
} |
| 39 |
seg, err := SegmentFromHeaderBytes(elements[0], b) |
| 40 |
if err != nil { |
| 41 |
return err |
| 42 |
} |
| 43 |
b.Segment = seg |
| 44 |
if len(elements) < 4 { |
| 45 |
return fmt.Errorf("%T: Malformed marshaled value", b) |
| 46 |
} |
| 47 |
maxJobs, err := strconv.Atoi(charset.ToUTF8(elements[1])) |
| 48 |
if err != nil { |
| 49 |
return fmt.Errorf("%T: Malformed max jobs: %v", b, err) |
| 50 |
} |
| 51 |
b.MaxJobs = element.NewNumber(maxJobs, 4) |
| 52 |
minSignatures, err := strconv.Atoi(charset.ToUTF8(elements[2])) |
| 53 |
if err != nil { |
| 54 |
return fmt.Errorf("%T: Malformed min signatures: %v", b, err) |
| 55 |
} |
| 56 |
b.MinSignatures = element.NewNumber(minSignatures, 2) |
| 57 |
return nil |
| 58 |
} |
| 59 |
|
| 60 |
const PinTanBusinessTransactionParamsID string = "DIPINS" |
| 61 |
|
| 62 |
type PinTanBusinessTransactionParams interface { |
| 63 |
BankSegment |
| 64 |
PinTanBusinessTransactions() []domain.PinTanBusinessTransaction |
| 65 |
} |
| 66 |
|
| 67 |
type PinTanBusinessTransactionParamsSegment struct { |
| 68 |
*BusinessTransactionParamsSegment |
| 69 |
} |
| 70 |
|
| 71 |
func (p *PinTanBusinessTransactionParamsSegment) Version() int { return 1 } |
| 72 |
func (p *PinTanBusinessTransactionParamsSegment) ID() string { |
| 73 |
return PinTanBusinessTransactionParamsID |
| 74 |
} |
| 75 |
|
| 76 |
func (p *PinTanBusinessTransactionParamsSegment) UnmarshalHBCI(value []byte) error { |
| 77 |
businessTransactionSegment := &BusinessTransactionParamsSegment{} |
| 78 |
err := businessTransactionSegment.UnmarshalHBCI(value) |
| 79 |
if err != nil { |
| 80 |
return err |
| 81 |
} |
| 82 |
p.BusinessTransactionParamsSegment = businessTransactionSegment |
| 83 |
elements, err := ExtractElements(value) |
| 84 |
if err != nil { |
| 85 |
return err |
| 86 |
} |
| 87 |
pinTanParams := &element.PinTanBusinessTransactionParameters{} |
| 88 |
err = pinTanParams.UnmarshalHBCI(elements[3]) |
| 89 |
if err != nil { |
| 90 |
return err |
| 91 |
} |
| 92 |
p.BusinessTransactionParamsSegment.Params = pinTanParams |
| 93 |
return nil |
| 94 |
} |
| 95 |
|
| 96 |
func (p *PinTanBusinessTransactionParamsSegment) PinTanBusinessTransactions() []domain.PinTanBusinessTransaction { |
| 97 |
var transactions []domain.PinTanBusinessTransaction |
| 98 |
for _, transactionDe := range p.Params.GroupDataElements() { |
| 99 |
transactions = append(transactions, transactionDe.(*element.PinTanBusinessTransactionParameter).Val()) |
| 100 |
} |
| 101 |
return transactions |
| 102 |
} |