-
Notifications
You must be signed in to change notification settings - Fork 0
/
moka.go
54 lines (41 loc) · 850 Bytes
/
moka.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
package moka
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"net/http"
)
type (
Moka struct {
baseURL string
Dealer PaymentDealerAuthentication
Client *http.Client
}
)
func New(code, username, password string, isTest bool) (m *Moka) {
m = new(Moka)
url := "https://service.moka.com"
if isTest {
url = "https://service.testmoka.com"
}
m.baseURL = url
m.Dealer = PaymentDealerAuthentication{
Code: code,
Username: username,
Password: password,
}
m.createCheckKey()
return
}
func (m *Moka) createCheckKey() (str string) {
var buffer bytes.Buffer
buffer.WriteString(m.Dealer.Code)
buffer.WriteString("MK")
buffer.WriteString(m.Dealer.Username)
buffer.WriteString("PD")
buffer.WriteString(m.Dealer.Password)
b := buffer.Bytes()
hash := sha256.Sum256(b)
str = hex.EncodeToString(hash[:])
return
}