mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-24 22:06:03 +03:00
Closes #34 return order data with orderCreate
This commit is contained in:
parent
2245c40212
commit
aa1745c13a
@ -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{
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
@ -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"`
|
||||||
|
Loading…
Reference in New Issue
Block a user