-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcryptomus.go
44 lines (37 loc) · 972 Bytes
/
cryptomus.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
package cryptomus
import (
"bytes"
"encoding/json"
"net/http"
)
const APIURL = "https://api.cryptomus.com/v1"
type Cryptomus struct {
merchant string
paymentApiKey string
payoutApiKey string
client *http.Client
}
func New(client *http.Client, merchant, paymentApiKey, payoutApiKey string) *Cryptomus {
return &Cryptomus{
client: client,
merchant: merchant,
paymentApiKey: paymentApiKey,
payoutApiKey: payoutApiKey,
}
}
func (c *Cryptomus) fetch(method string, endpoint string, payload any) (*http.Response, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
sign := c.signRequest(c.paymentApiKey, body)
req, err := http.NewRequest(method, APIURL+endpoint, bytes.NewBuffer(body))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("merchant", c.merchant)
req.Header.Set("sign", sign)
res, err := c.client.Do(req)
return res, err
}