-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.va.go
78 lines (71 loc) · 2.22 KB
/
core.va.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
package xenditfasthttp
import (
"bytes"
"encoding/json"
"fmt"
"github.com/valyala/fasthttp"
)
const (
pathCreateVA = "/callback_virtual_accounts"
pathGetVirtualAccountAvailableBanks = "/available_virtual_account_banks"
pathGetVirtualAccountRequest = "/callback_virtual_accounts/%s"
pathUpdateVirtualAccount = "/callback_virtual_accounts/%s"
)
// UpdateVirtualAccount is used to update virtual account
func (gw *CoreXendit) UpdateVirtualAccount(req UpdateVirtualAccountsRequest, id string) (res CreateVAResponse, err error) {
data, err := json.Marshal(req)
if err != nil {
return
}
buf := bytes.NewBuffer(data)
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodPatch, fmt.Sprintf(pathUpdateVirtualAccount, id), headers, buf, &res)
if err != nil {
return
}
return
}
// GetVirtualAccountRequest is used to get virtual account request.
func (gw *CoreXendit) GetVirtualAccountRequest(id string) (res CreateVAResponse, err error) {
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodGet, fmt.Sprintf(pathGetVirtualAccountRequest, id), headers, nil, &res)
if err != nil {
return
}
return
}
// GetVirtualAccountAvailableBanks is used to get virtual account available banks
func (gw *CoreXendit) GetVirtualAccountAvailableBanks() (res VirtualAccountBanksResponse, err error) {
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodGet, pathGetVirtualAccountAvailableBanks, headers, nil, &res)
if err != nil {
return
}
return
}
// CreataVA is used to create virtual account
func (gw *CoreXendit) CreataVA(req CreateVARequest) (res CreateVAResponse, err error) {
data, err := json.Marshal(req)
if err != nil {
return
}
buf := bytes.NewBuffer(data)
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodPost, pathCreateVA, headers, buf, &res)
if err != nil {
return
}
return
}