Пример #1
0
func (p *InfinityAPI) NewOrder(order t.NewOrderInfo) t.Answer {
	//because sedi use Id address and id from street autocomplete was equal idadress not idstreet
	order.Delivery.IdAddress = ""
	order.Destinations[0].IdAddress = ""

	order.IdService = p.Config.GetIdService()
	param, err := json.Marshal(order)
	if err != nil {
		log.Printf("INF NO error at marshal json to infinity %+v, %v", order, err)
		return t.Answer{IsSuccess: false, Message: fmt.Sprint(err)}
	}
	log.Printf("INF NEW ORDER (jsonified): \n%s\nat%+v", param, p)
	body, err := p._request("RemoteCall", map[string]string{"params": string(param), "method": "Taxi.WebAPI.NewOrder"})
	if err != nil {
		return t.Answer{IsSuccess: false, Message: fmt.Sprint(err)}
	}
	var ans t.Answer
	err = json.Unmarshal(body, &ans)
	log.Printf("INF NEW ORDER ANSER: \n%+v err? %v", ans, err)
	if err != nil {
		log.Printf("INF NO error at unmarshal json from infinity %v", string(body))
		p.Connect()
		return t.Answer{IsSuccess: false, Message: fmt.Sprint(err)}
	}
	return ans
}
Пример #2
0
func (p *InfinityAPI) CalcOrderCost(order t.NewOrderInfo) (int, string) {
	order.IdService = p.Config.GetIdService()
	param, err := json.Marshal(order)
	if err != nil {
		log.Printf("INF COC error at marshal json from infinity %+v %v", order, err)
		return -1, ""
	}
	body, err := p._request("RemoteCall", map[string]string{"params": string(param), "method": "Taxi.WebAPI.CalcOrderCost"})
	if err != nil {
		return 0, fmt.Sprint(err)
	}
	var tmp t.Answer
	err = json.Unmarshal(body, &tmp)
	if err != nil {
		log.Printf("INFO COC error at unmarshal json from infinity %v %v", string(body), err)
		p.Connect()
		return -1, ""
	}
	return tmp.Content.Cost, tmp.Content.Details
}