-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathiyzipay.go
52 lines (45 loc) · 1.29 KB
/
iyzipay.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
package Iyzipay
import (
"github.com/go-resty/resty/v2"
"github.com/icobani/iyzipay-go/Utils"
"strings"
)
type Iyzipay struct {
APIKey string
APISecret string
URI string
Client *resty.Client
}
type ErrorStruct struct {
Error string
}
func (i Iyzipay) New(APIKey, APISecret string) (*Iyzipay, *ErrorStruct) {
if APIKey == "" {
return nil, &ErrorStruct{"APIKey not found."}
}
if APISecret == "" {
return nil, &ErrorStruct{"APISecret not found."}
}
URI := "https://api.iyzipay.com"
if strings.Contains(APIKey, "sandbox-") {
URI = "https://sandbox-api.iyzipay.com"
}
return &Iyzipay{APIKey, APISecret, URI, resty.New()}, nil
}
func (i Iyzipay) GetURI(uri string) string {
return i.URI + uri
}
func (i Iyzipay) GetHeaders(obj interface{}) map[string]string {
header := map[string]string{}
header["accept"] = "application/json"
header["content-type"] = "application/json"
RandomString := Utils.RandomString(8)
requestString := Utils.RequestString(obj)
pki := Utils.PKIString(i.APIKey, RandomString, i.APISecret, requestString)
hashedPki := Utils.HashedPKIString(pki)
authorization := Utils.GenerateAuthorizationHeader(i.APIKey, hashedPki)
header["authorization"] = authorization
header["x-iyzi-rnd"] = RandomString
header["cache-control"] = "no-cache"
return header
}