public async Task <IResult <FeeInfo> > GetFeeInfo(FeeRequestObject feeObject) { try { var feeInfoUri = UriHelper.GetFeeInfoUri(feeObject); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, feeInfoUri); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); var messageResponse = JsonConvert.DeserializeObject <dynamic>(json); if (messageResponse["success"] == false) { return(Result.Fail <FeeInfo>(messageResponse["message"].ToString())); } var feeInfo = JsonConvert.DeserializeObject <FeeInfo>(json, new FeeInfoDataConverter()); return(Result.Success(feeInfo)); } catch (Exception e) { return(Result.Fail <FeeInfo>(e.Message)); } }
public async Task <IResult <string> > GetFeeOfOrder(FeeRequestObject feeObject) { try { var feeObjectResult = await GetFeeInfo(feeObject); if (!feeObjectResult.Succeeded) { return(Result.Fail <string>("Error")); } return(Result.Success(feeObjectResult.Value.Fee.ToString())); } catch (Exception e) { return(Result.Fail <string>(e.Message)); } }
public static Uri GetFeeInfoUri(FeeRequestObject feeObject) { string[] payload = new string[7]; payload[0] = "address=" + feeObject.Address; payload[1] = "district=" + feeObject.District; payload[2] = "pick_district=" + feeObject.PickDistrict; payload[3] = "pick_province=" + feeObject.PickProvince; payload[4] = "province=" + feeObject.Province; payload[5] = "value=" + feeObject.Value; payload[6] = "weight=" + feeObject.Weight; if (!Uri.TryCreate(BaseGhtkUri, "shipment/fee?" + string.Join("&", payload), out var feeInfoUri)) { throw new Exception("Cant create Uri to get fee of order"); } return(feeInfoUri); }