Return order data with orderCreate

This commit is contained in:
Alex Lushpai 2020-07-14 12:29:16 +03:00 committed by GitHub
commit a975815296
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 3 deletions

View File

@ -2248,8 +2248,8 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper
// if data.Success == true { // if data.Success == true {
// fmt.Printf("%v\n", data.ID) // fmt.Printf("%v\n", data.ID)
// } // }
func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, *errs.Failure) { func (c *Client) OrderCreate(order Order, site ...string) (OrderCreateResponse, int, *errs.Failure) {
var resp CreateResponse var resp OrderCreateResponse
orderJSON, _ := json.Marshal(&order) orderJSON, _ := json.Marshal(&order)
p := url.Values{ p := url.Values{

View File

@ -1956,7 +1956,83 @@ func TestClient_OrderChange(t *testing.T) {
MatchType("url"). MatchType("url").
BodyString(p.Encode()). BodyString(p.Encode()).
Reply(201). 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) cr, sc, err := c.OrderCreate(f)
if err.Error() != "" { if err.Error() != "" {
@ -1971,6 +2047,10 @@ func TestClient_OrderChange(t *testing.T) {
t.Errorf("%v", err.ApiError()) 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.ID = cr.ID
f.CustomerComment = "test comment" f.CustomerComment = "test comment"

View File

@ -11,6 +11,12 @@ type CreateResponse struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
} }
// OrderCreateResponse type
type OrderCreateResponse struct {
CreateResponse
Order Order `json:"order,omitempty"`
}
// OperationResponse type // OperationResponse type
type OperationResponse struct { type OperationResponse struct {
Success bool `json:"success"` Success bool `json:"success"`