-
Notifications
You must be signed in to change notification settings - Fork 0
/
onetimepayment.go
74 lines (63 loc) · 1.39 KB
/
onetimepayment.go
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
package bsqrbuilder
import (
"regexp"
"strings"
"time"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
type OneTimePayment struct {
IBAN string
BIC string
Amount string
CurrencyCode string
DueDate time.Time
VariableSymbol string
ConstantSymbol string
SpecificSymbol string
Note string
BeneficiaryName string
BeneficiaryAddressLine1 string
BeneficiaryAddressLine2 string
}
func (p OneTimePayment) BuildSequenceDataModelText() string {
return strings.Join(
[]string{
"",
"1",
"1",
p.Amount,
p.CurrencyCode,
p.DueDate.Format("20060102"),
p.VariableSymbol,
p.ConstantSymbol,
p.SpecificSymbol,
"",
safeString(p.Note),
"1", // one BankAccounts
p.IBAN,
p.BIC,
"0", // not StandingOrderExt
"0", // not DirectDebitExt
safeString(p.BeneficiaryName),
safeString(p.BeneficiaryAddressLine1),
safeString(p.BeneficiaryAddressLine2),
},
"\t",
)
}
func safeString(text string) string {
text = removeDiacritics(text)
text = removeUnsafeCharacters(text)
return text
}
func removeUnsafeCharacters(text string) string {
return regexp.MustCompile("[^-a-zA-Z0-9 .:]").ReplaceAllString(text, "")
}
func removeDiacritics(text string) string {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
text, _, _ = transform.String(t, text)
return text
}