Closes #34 return order data with orderCreate

This commit is contained in:
Pavel 2020-07-14 11:51:35 +03:00
parent 2245c40212
commit aa1745c13a
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 {
// 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{

View File

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

View File

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