diff --git a/v5/client.go b/v5/client.go index a80a4ad..6a7d590 100644 --- a/v5/client.go +++ b/v5/client.go @@ -2509,6 +2509,46 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S return resp, status, nil } +// OrderPaymentEdit edit payment +// +// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-statuses +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.OrdersStatuses(v5.OrdersStatusesRequest{ +// IDs: []int{1}, +// ExternalIDs: []string{"2"}, +// }) +// +// if err.Error() != "" { +// fmt.Printf("%v", err.RuntimeErr) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ApiErr()) +// } +func (c *Client) OrdersStatuses(request OrdersStatusesRequest) (OrdersStatusesResponse, int, *errs.Failure) { + var resp OrdersStatusesResponse + + params, _ := query.Values(request) + + data, status, err := c.GetRequest(fmt.Sprintf("/orders/statuses?%s", params.Encode())) + if err.Error() != "" { + return resp, status, err + } + + json.Unmarshal(data, &resp) + + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil +} + // OrdersUpload batch orders uploading // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-upload diff --git a/v5/client_test.go b/v5/client_test.go index 9de366b..f00c640 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -2286,6 +2286,55 @@ func TestClient_OrdersFixExternalIds_Fail(t *testing.T) { } } +func TestClient_OrdersStatuses(t *testing.T) { + c := client() + defer gock.Off() + + gock.New(crmURL). + Get("/orders/statuses"). + MatchParam("ids[]", "1"). + MatchParam("externalIds[]", "2"). + Reply(200). + BodyString(` + { + "success": true, + "orders": [ + { + "id": 1, + "externalId": "123", + "status": "New", + "group": "new" + }, + { + "id": 123, + "externalId": "2", + "status": "New", + "group": "new" + } + ] + }`) + + data, status, err := c.OrdersStatuses(OrdersStatusesRequest{ + IDs: []int{1}, + ExternalIDs: []string{"2"}, + }) + if err.Error() != "" { + t.Errorf("%v", err.Error()) + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ApiError()) + } + + if data.Success != true { + t.Errorf("%v", err.ApiError()) + } + + if len(data.Orders) == 0 { + t.Errorf("%v", err.ApiError()) + } +} + func TestClient_OrdersHistory(t *testing.T) { c := client() diff --git a/v5/request.go b/v5/request.go index 2ae19b6..0de069e 100644 --- a/v5/request.go +++ b/v5/request.go @@ -78,6 +78,12 @@ type OrdersRequest struct { Page int `url:"page,omitempty"` } +// OrdersStatusesRequest type +type OrdersStatusesRequest struct { + IDs []int `url:"ids,omitempty,brackets"` + ExternalIDs []string `url:"externalIds,omitempty,brackets"` +} + // OrdersUploadRequest type type OrdersUploadRequest struct { Orders []Order `url:"orders,omitempty,brackets"` diff --git a/v5/response.go b/v5/response.go index 8fb8c72..e97d144 100644 --- a/v5/response.go +++ b/v5/response.go @@ -130,6 +130,12 @@ type OrdersResponse struct { Orders []Order `json:"orders,omitempty,brackets"` } +// OrdersStatusesResponse type +type OrdersStatusesResponse struct { + Success bool `json:"success"` + Orders []OrdersStatus `json:"orders"` +} + // OrdersUploadResponse type type OrdersUploadResponse struct { Success bool `json:"success"` diff --git a/v5/types.go b/v5/types.go index 1d97f2f..c6742b6 100644 --- a/v5/types.go +++ b/v5/types.go @@ -318,6 +318,14 @@ type Order struct { Payments map[string]OrderPayment `json:"payments,omitempty,brackets"` } +// OrdersStatus type +type OrdersStatus struct { + ID int `json:"id"` + ExternalID string `json:"externalId,omitempty"` + Status string `json:"status"` + Group string `json:"group"` +} + // OrderDelivery type type OrderDelivery struct { Code string `json:"code,omitempty"`