-
Notifications
You must be signed in to change notification settings - Fork 6
/
orders.go
101 lines (90 loc) · 2.87 KB
/
orders.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package culqi
import (
"encoding/json"
"net/url"
utils "github.com/culqi/culqi-go/utils/validation"
)
const (
ordersURL = baseURL + "/orders"
)
// Create método para crear una orden
func CreateOrder(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.NewOrderValidation()
err = validator.Create(data)
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Create(ordersURL, body, encryptionData...)
return statusCode, res, err
}
// GetByID método para obtener una orden por id
func GetByIDOrder(id string, body []byte) (int, string, error) {
err := utils.ValidateStringStart(id, "ord")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := GetById(ordersURL, id, body)
return statusCode, res, err
}
// GetAll método para obtener la lista de Ordenes
func GetAllOrder(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.OrderListValidation(data)
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := GetAll(ordersURL, queryParams, body)
return statusCode, res, err
}
// Update método para agregar o remplazar información a los valores de la metadata de una orden
func UpdateOrder(id string, body []byte, encryptionData ...byte) (int, string, error) {
err := utils.ValidateStringStart(id, "ord")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Update(ordersURL, id, body, encryptionData...)
return statusCode, res, err
}
// Delete método para eliminar una orden
func DeleteOrder(id string, body []byte) (int, string, error) {
err := utils.ValidateStringStart(id, "ord")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Delete(ordersURL, id, body)
return statusCode, res, err
}
// Confirm método para confirmar una orden
func ConfirmOrder(id string, body []byte, encryptionData ...byte) (int, string, error) {
err := utils.ValidateStringStart(id, "ord")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Create(ordersURL+"/"+id+"/confirm", body, encryptionData...)
return statusCode, res, err
}
// Confirm método para confirmar una orden por tipo
func ConfirmTipoOrder(body []byte, encryptionData ...byte) (int, string, error) {
var data map[string]interface{}
errassign := json.Unmarshal(body, &data)
if errassign != nil {
return 0, "", errassign
}
err := utils.ValidateStringStart(data["order_id"].(string), "ord")
if err != nil {
return ErrorBadRequest, "", err
}
statusCode, res, err := Create(ordersURL+"/confirm", body, encryptionData...)
return statusCode, res, err
}