-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.outlet.go
69 lines (63 loc) · 1.87 KB
/
core.outlet.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
package xenditfasthttp
import (
"bytes"
"encoding/json"
"fmt"
"github.com/valyala/fasthttp"
)
const (
pathFixedPaymentCode = "/fixed_payment_code"
pathSimulateFixedPaymentCode = "/fixed_payment_code/simulate_payment"
pathUpdateFixedPaymentCode = "/fixed_payment_code/%s"
)
// UpdateFixedPaymentCode i sused to update payment
func (gw *CoreXendit) UpdateFixedPaymentCode(paymentCode string, req UpdateFixedPaymentCodeRequest) (res FixedPaymentCodeResponse, 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(pathUpdateFixedPaymentCode, paymentCode), headers, buf, &res)
if err != nil {
return
}
return
}
// CreateFixedPaymentCode is used to create payment to outlet e.g: Alfamart, Indomaret ...
func (gw *CoreXendit) CreateFixedPaymentCode(req CreateFixedPaymentCodeRequest) (res FixedPaymentCodeResponse, 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, pathFixedPaymentCode, headers, buf, &res)
if err != nil {
return
}
return
}
// SimulateFixedPayment is used to simulate payment to outlet.
func (gw *CoreXendit) SimulateFixedPayment(req SimulateRequest) (res SimulateResponse, 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, pathSimulateFixedPaymentCode, headers, buf, &res)
if err != nil {
return
}
return
}