fixes #30, orders statuses method

This commit is contained in:
Akolzin Dmitry 2020-06-29 16:26:10 +03:00
parent 03084ba3b8
commit 1ede044644
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 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 // OrdersUpload batch orders uploading
// //
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-upload // 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) { func TestClient_OrdersHistory(t *testing.T) {
c := client() c := client()

View File

@ -78,6 +78,12 @@ type OrdersRequest struct {
Page int `url:"page,omitempty"` Page int `url:"page,omitempty"`
} }
// OrdersStatusesRequest type
type OrdersStatusesRequest struct {
IDs []int `url:"ids,omitempty,brackets"`
ExternalIDs []string `url:"externalIds,omitempty,brackets"`
}
// OrdersUploadRequest type // OrdersUploadRequest type
type OrdersUploadRequest struct { type OrdersUploadRequest struct {
Orders []Order `url:"orders,omitempty,brackets"` Orders []Order `url:"orders,omitempty,brackets"`

View File

@ -130,6 +130,12 @@ type OrdersResponse struct {
Orders []Order `json:"orders,omitempty,brackets"` Orders []Order `json:"orders,omitempty,brackets"`
} }
// OrdersStatusesResponse type
type OrdersStatusesResponse struct {
Success bool `json:"success"`
Orders []OrdersStatus `json:"orders"`
}
// OrdersUploadResponse type // OrdersUploadResponse type
type OrdersUploadResponse struct { type OrdersUploadResponse struct {
Success bool `json:"success"` Success bool `json:"success"`

View File

@ -318,6 +318,14 @@ type Order struct {
Payments map[string]OrderPayment `json:"payments,omitempty,brackets"` 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 // OrderDelivery type
type OrderDelivery struct { type OrderDelivery struct {
Code string `json:"code,omitempty"` Code string `json:"code,omitempty"`