forked from kenriortega/qvapay-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_payment_app.go
57 lines (52 loc) · 1.13 KB
/
client_payment_app.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
package qvapay
import (
"crypto/tls"
"net/http"
"os"
"time"
)
// PaymentAppClient is an interface that implements https://qvapay.com/api
type PaymentAppClient interface {
IQvaPay
}
func NewPaymentAppClient(
opts Options,
) PaymentAppClient {
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
MaxIdleConns: 256,
MaxIdleConnsPerHost: 256,
IdleConnTimeout: 60 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
DisableCompression: true,
}
c := &client{
appID: opts.AppID,
appSecret: opts.SecretID,
url: opts.BaseURL,
httpClient: opts.HttpClient,
debug: opts.Debug,
}
if opts.AppID == "" {
c.appID = os.Getenv("APP_ID")
}
if opts.SecretID == "" {
c.appSecret = os.Getenv("APP_SECRET")
}
if opts.BaseURL == "" {
c.url = BaseURL
}
if opts.HttpClient != nil {
c.httpClient = opts.HttpClient
} else {
c.httpClient = http.DefaultClient
}
if opts.SkipVerify {
// #nosec
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
c.httpClient.Transport = tr
}
c.httpClient.Transport = tr
return c
}