From aa1745c13a7fa2e7538c2ee63aac2ed75ec0cccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB?= Date: Tue, 14 Jul 2020 11:51:35 +0300 Subject: [PATCH] Closes #34 return order data with orderCreate --- v5/client.go | 4 +-- v5/client_test.go | 82 ++++++++++++++++++++++++++++++++++++++++++++++- v5/response.go | 6 ++++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/v5/client.go b/v5/client.go index d358468..e7afc63 100644 --- a/v5/client.go +++ b/v5/client.go @@ -2248,8 +2248,8 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, *errs.Failure) { - var resp CreateResponse +func (c *Client) OrderCreate(order Order, site ...string) (OrderCreateResponse, int, *errs.Failure) { + var resp OrderCreateResponse orderJSON, _ := json.Marshal(&order) p := url.Values{ diff --git a/v5/client_test.go b/v5/client_test.go index 912d090..73282fd 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -1956,7 +1956,83 @@ func TestClient_OrderChange(t *testing.T) { MatchType("url"). BodyString(p.Encode()). Reply(201). - BodyString(`{"success": true, "id": 1}`) + BodyString(`{ + "success": true, + "id": 1, + "order": { + "slug": 1, + "id": 1, + "number": "1A", + "orderMethod": "shopping-cart", + "countryIso": "RU", + "createdAt": "2020-07-14 11:44:43", + "statusUpdatedAt": "2020-07-14 11:44:43", + "summ": 0, + "totalSumm": 0, + "prepaySum": 0, + "purchaseSumm": 0, + "markDatetime": "2020-07-14 11:44:43", + "call": false, + "expired": false, + "customer": { + "type": "customer", + "id": 1, + "isContact": false, + "createdAt": "2020-07-14 11:44:43", + "vip": false, + "bad": false, + "site": "site", + "contragent": { + "contragentType": "individual" + }, + "tags": [], + "marginSumm": 0, + "totalSumm": 0, + "averageSumm": 0, + "ordersCount": 0, + "personalDiscount": 0, + "segments": [], + "email": "", + "phones": [] + }, + "contact": { + "type": "customer", + "id": 4512, + "isContact": false, + "createdAt": "2020-07-14 11:44:43", + "vip": false, + "bad": false, + "site": "site", + "contragent": { + "contragentType": "individual" + }, + "tags": [], + "marginSumm": 0, + "totalSumm": 0, + "averageSumm": 0, + "ordersCount": 0, + "personalDiscount": 0, + "segments": [], + "email": "", + "phones": [] + }, + "contragent": { + "contragentType": "individual" + }, + "delivery": { + "cost": 0, + "netCost": 0, + "address": {} + }, + "site": "site", + "status": "new", + "items": [], + "payments": [], + "fromApi": true, + "shipmentStore": "main", + "shipped": false + } +}`) cr, sc, err := c.OrderCreate(f) if err.Error() != "" { @@ -1971,6 +2047,10 @@ func TestClient_OrderChange(t *testing.T) { t.Errorf("%v", err.ApiError()) } + if cr.Order.Number != "1A" { + t.Errorf("invalid order number: got %s want %s", cr.Order.Number, "1A") + } + f.ID = cr.ID f.CustomerComment = "test comment" diff --git a/v5/response.go b/v5/response.go index 641bee3..227fb35 100644 --- a/v5/response.go +++ b/v5/response.go @@ -11,6 +11,12 @@ type CreateResponse struct { ID int `json:"id,omitempty"` } +// OrderCreateResponse type +type OrderCreateResponse struct { + CreateResponse + Order Order `json:"order,omitempty"` +} + // OperationResponse type type OperationResponse struct { Success bool `json:"success"`