-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.go
60 lines (49 loc) · 1.22 KB
/
order.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
package squarego
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
// OrderRequest ...
type OrderRequest struct {
OrderIDs []string `json:"order_ids"`
}
// OrderResponse ...
type OrderResponse struct {
Orders []Order `json:"orders"`
}
// Order ...
type Order struct {
ID *string `json:"id"`
LocationID *string `json:"location_id"`
ReferenceID *string `json:"reference_id"`
CustomerID *string `json:"customer_id"`
Items []Item `json:"line_items"`
TotalMoney PaymentAmount `json:"total_money"`
Tenders []Tender `json:"tenders"`
}
// GetOrderByID ...
func (svc *service) GetOrderByID(locationID, orderID string) (Order, error) {
var orderResp OrderResponse
request := OrderRequest{
OrderIDs: []string{orderID},
}
data, err := json.Marshal(request)
if err != nil {
return Order{}, err
}
resp, err := svc.createRequest(http.MethodPost, fmt.Sprintf("locations/%s/orders/batch-retrieve", locationID), data)
if err != nil {
return Order{}, err
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return Order{}, err
}
err = json.Unmarshal(b, &orderResp)
if len(orderResp.Orders) > 0 {
return orderResp.Orders[0], nil
}
return Order{}, nil
}