forked from kurtulussahin/iyzipay-go
/
pki_builder.go
66 lines (50 loc) · 1.69 KB
/
pki_builder.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
package iyzipay
import (
"fmt"
"strconv"
)
type PkiBuilder struct {
request_string string
}
func (pkiBuilder *PkiBuilder) append(key string, value string) {
if value != "" {
pkiBuilder.appendKeyValue(key, value)
}
}
func (pkiBuilder *PkiBuilder) appendArray(key string, array []string) {
if array != nil {
appended_value := ""
for _, value := range array {
appended_value = appended_value + value + ", "
}
pkiBuilder.appendKeyValueArray(key, appended_value)
}
}
func (pkiBuilder *PkiBuilder) appendKeyValue(key string, value string) {
pkiBuilder.request_string = pkiBuilder.request_string + key + "=" + value + ","
}
func (pkiBuilder *PkiBuilder) appendKeyValueArray(key string, appended_value string) {
appended_value = appended_value[:len(appended_value)-2]
pkiBuilder.request_string = pkiBuilder.request_string + key + "=[" + appended_value + "],"
}
func (pkiBuilder *PkiBuilder) appendPrice(key string, value string) {
if value != "" {
value_to_float, _ := strconv.ParseFloat(value, 64)
raunded_string_value := string(fmt.Sprintf("%.2f", value_to_float))
if (raunded_string_value[len(raunded_string_value)-1:]) == "0" {
raunded_string_value = raunded_string_value[:len(raunded_string_value)-1]
}
pkiBuilder.appendKeyValue(key, raunded_string_value)
}
}
func (pkiBuilder *PkiBuilder) getRequestString() string {
pkiBuilder.removeTrailingComma()
pkiBuilder.appendPrefix()
return pkiBuilder.request_string
}
func (pkiBuilder *PkiBuilder) removeTrailingComma() {
pkiBuilder.request_string = pkiBuilder.request_string[:len(pkiBuilder.request_string)-1]
}
func (pkiBuilder *PkiBuilder) appendPrefix() {
pkiBuilder.request_string = "[" + pkiBuilder.request_string + "]"
}