-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.disbursement.go
74 lines (67 loc) · 2.17 KB
/
core.disbursement.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
package xenditfasthttp
import (
"bytes"
"encoding/json"
"fmt"
"github.com/valyala/fasthttp"
)
const (
pathDisbursements = "/disbursements"
pathAvailDisbBanks = "/available_disbursements_banks"
pathGetDisbursementByID = "/disbursements/%s"
pathGetDisbursementsByExternalID = "/disbursements?external_id=%s"
)
// GetDisbursementsByExternalID is used to get Disbursement by external ID
func (gw *CoreXendit) GetDisbursementsByExternalID(exID string) (res []DisbursementResponse, err error) {
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodGet, fmt.Sprintf(pathGetDisbursementsByExternalID, exID), headers, nil, &res)
if err != nil {
return
}
return
}
// GetDisbursementByID is used to get disbusement by ID
func (gw *CoreXendit) GetDisbursementByID(disursementID string) (res DisbursementResponse, err error) {
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodGet, fmt.Sprintf(pathGetDisbursementByID, disursementID), headers, nil, &res)
if err != nil {
return
}
return
}
// GetAvailableDisbursementBanks is used to get available disbusrsement banks
func (gw *CoreXendit) GetAvailableDisbursementBanks() (res []AvailableDisbursementBanksResponse, err error) {
headers := map[string]string{
"Authorization": BasicAuth(gw.Client.SecretKey, ""),
"Content-Type": "application/json",
}
err = gw.Call(fasthttp.MethodGet, pathAvailDisbBanks, headers, nil, &res)
if err != nil {
return
}
return
}
// CreateDisbursement is used to create disbursement
func (gw *CoreXendit) CreateDisbursement(req DisbursementRequest) (res DisbursementResponse, 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",
"X-IDEMPOTENCY-KEY": req.IdempotencyKey,
}
err = gw.Call(fasthttp.MethodPost, pathDisbursements, headers, buf, &res)
if err != nil {
return
}
return
}