Orders statuses method

This commit is contained in:
Alex Lushpai 2020-06-29 16:28:19 +03:00 committed by GitHub
commit a293f7235e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -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"`

View File

@ -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"`

View File

@ -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"`