-
Notifications
You must be signed in to change notification settings - Fork 6
/
charge.go
76 lines (67 loc) · 2.09 KB
/
charge.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
package culqi
import (
"encoding/json"
"net/url"
utils "github.com/culqi/culqi-go/utils/validation"
)
const (
chargesURL = baseURL + "/charges"
)
// Create método para crear un cargo
func CreateCharge(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.NewChargeValidation()
err = validator.Create(data)
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Create(chargesURL, body, encryptionData...)
return statusCode, res, err
}
// Capturar un cargo
func ChargeCapture(id string, body []byte, encryptionData ...byte) (int, string, error) {
err := utils.ValidateStringStart(id, "chr")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Create(chargesURL+"/"+id+"/capture", body, encryptionData...)
return statusCode, res, err
}
// GetByID método para obtener un cargo por id
func GetByIdCharge(id string, body []byte) (int, string, error) {
err := utils.ValidateStringStart(id, "chr")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := GetById(chargesURL, id, body)
return statusCode, res, err
}
// GetAll método para obtener la lista de Cargos
func GetAllCharge(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.ChargeListValidation(data)
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := GetAll(chargesURL, queryParams, body)
return statusCode, res, err
}
// Update método para agregar o remplazar información a los valores de la metadata de un cargo
func UpdateCharge(id string, body []byte, encryptionData ...byte) (int, string, error) {
err := utils.ValidateStringStart(id, "chr")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Update(chargesURL, id, body, encryptionData...)
return statusCode, res, err
}