-
Notifications
You must be signed in to change notification settings - Fork 0
/
gogojudo.go
54 lines (43 loc) · 1007 Bytes
/
gogojudo.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 gogojudo
import (
"encoding/base64"
"net/http"
"net/url"
"os"
)
type JudoPay struct {
HttpClient *http.Client
APIUrl *url.URL
Authorization string
JudopayID string
}
// funcction New returns an instacce of the Judopay struct
func New() *JudoPay {
api_url, err := url.Parse(getEnv("JUDOPAY_URL", "https://gw1.judopay-sandbox.com/transactions"))
if err != nil {
panic(err)
}
return &JudoPay{
&http.Client{},
api_url,
base64.StdEncoding.EncodeToString(
[]byte(
os.Getenv("JUDOPAY_TOKEN") + ":" + os.Getenv("JUDOPAY_SECRET"),
),
),
os.Getenv("JUDOPAY_ID"),
}
}
func (jp *JudoPay) SetHeaders(req *http.Request) error {
req.Header.Set("Authorization", "Basic "+jp.Authorization)
req.Header.Set("API-Version", getEnv("JUDOPAY_API_VERSION", "5.6"))
req.Header.Set("Content-Type", "application/json")
return nil
}
func getEnv(name string, fallback string) string {
val := os.Getenv(name)
if len(val) == 0 {
return fallback
}
return val
}