-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.go
80 lines (66 loc) · 1.99 KB
/
wallet.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package kotani
import (
"bytes"
"context"
"encoding/json"
"net/http"
)
type (
WalletBody struct {
Name string `json:"name"`
Currency Currency `json:"currency"`
}
CreateWalletResponse struct {
CommonResponseFields
Data struct {
Name string `json:"name"`
Type string `json:"type"`
Currency string `json:"currency"`
Integrator string `json:"integrator"`
Status string `json:"status"`
ID string `json:"id"`
Balance int `json:"balance"`
DepositBalance int `json:"deposit_balance"`
} `json:"data"`
}
FiatWalletsResponse struct {
CommonResponseFields
Data []struct {
Name string `json:"name"`
Type string `json:"type"`
Currency string `json:"currency"`
Integrator string `json:"integrator"`
Status string `json:"status"`
ID string `json:"id"`
Balance int `json:"balance"`
DepositBalance int `json:"deposit_balance"`
} `json:"data"`
}
)
const walletPath = "/wallet/"
func (kc *KotaniClient) CreateFiatWallet(ctx context.Context, input WalletBody) (CreateWalletResponse, error) {
createWalletResp := CreateWalletResponse{}
jsonRequestBody, err := json.Marshal(&input)
if err != nil {
return createWalletResp, err
}
resp, err := kc.requestWithCtx(ctx, http.MethodPost, kc.endpoint+walletPath+"fiat", bytes.NewBuffer(jsonRequestBody))
if err != nil {
return createWalletResp, err
}
if err := parseResponse(resp, &createWalletResp); err != nil {
return createWalletResp, err
}
return createWalletResp, nil
}
func (kc *KotaniClient) GetIntegratorFiatWallets(ctx context.Context) (FiatWalletsResponse, error) {
fiatWalletsResp := FiatWalletsResponse{}
resp, err := kc.requestWithCtx(ctx, http.MethodGet, kc.endpoint+walletPath+"fiat", nil)
if err != nil {
return fiatWalletsResp, err
}
if err := parseResponse(resp, &fiatWalletsResp); err != nil {
return fiatWalletsResp, err
}
return fiatWalletsResp, nil
}