-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrefund.go
66 lines (58 loc) · 1.79 KB
/
refund.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
package culqi
import (
"encoding/json"
"net/url"
utils "github.com/culqi/culqi-go/utils/validation"
)
const (
refundURL = baseURL + "/refunds"
)
// Create método para crear una devolucion
func CreateRefund(body []byte, encryptionData ...byte) (int, string, error) {
var data map[string]interface{}
err := json.Unmarshal(body, &data)
if err != nil {
return 0, "", err
}
// Perform validation
validator := utils.NewRefundValidation()
err = validator.Create(data)
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Create(refundURL, body, encryptionData...)
return statusCode, res, err
}
// GetByID método para obtener una devolucion por id
func GetByIDRefund(id string, body []byte) (int, string, error) {
err := utils.ValidateStringStart(id, "ref")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := GetById(refundURL, id, body)
return statusCode, res, err
}
// GetAll método para obtener la lista de devoluciones
func GetAllRefund(queryParams url.Values, body []byte) (int, string, error) {
data := make(map[string]interface{})
for key, values := range queryParams {
if len(values) > 0 {
data[key] = values[0] // Taking only the first value for each key.
}
}
err := utils.RefundListValidation(data)
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := GetAll(refundURL, queryParams, body)
return statusCode, res, err
}
// Update método para agregar o remplazar información a los valores de la metadata de una devolucion
func UpdateRefund(id string, body []byte, encryptionData ...byte) (int, string, error) {
err := utils.ValidateStringStart(id, "ref")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Update(refundURL, id, body, encryptionData...)
return statusCode, res, err
}