Beispiel #1
0
        public ApiRajaOngkirTrackingDto Tracking(GetTrackingInputDto inputDto)
        {
            using (var client = new HttpClient())
            {
                var url    = AppSettingConfigurationHelper.GetSection("APIUrlRajaOngkir").Value;
                var apiKey = AppSettingConfigurationHelper.GetSection("APIKeyRajaOngkir").Value;
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("key", apiKey);

                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("waybill", inputDto.AirWayBill),
                    new KeyValuePair <string, string>("courier", inputDto.ExpeditionService.Expedition.RajaOngkirCode.ToLower())
                });

                HttpResponseMessage response = client.PostAsync("waybill", content).Result;

                var    resultString = AsyncHelper.RunSync(() => response.Content.ReadAsStringAsync());
                JToken token        = JObject.Parse(resultString);

                if ((string)token.SelectToken("rajaongkir").SelectToken("status").SelectToken("description") != HttpStatusCode.OK.ToString())
                {
                    throw new HozaruException((string)token.SelectToken("rajaongkir").SelectToken("status").SelectToken("description"));
                }

                var result = token.SelectToken("rajaongkir").SelectToken("result");
                return(result.ToObject <ApiRajaOngkirTrackingDto>());
            }
        }
Beispiel #2
0
        public void UpdateTrackingInfo(Guid orderId)
        {
            var order = _orderRepository.Get(orderId);

            Validate.Found(order, "Orderan");

            var getTrackingInputDto = new GetTrackingInputDto()
            {
                AirWayBill = order.Shipment.AirWaybill, ExpeditionService = order.Shipment.ExpeditionService
            };
            var result = _rajaOngkirService.Tracking(getTrackingInputDto);

            var shipmentDateSplited = result.WayBillDate.Split("-");
            var shipmentTimeSplited = result.WayBillTime.Split(":");
            var shipmentDateTime    = new DateTime(Convert.ToInt32(shipmentDateSplited[0]), Convert.ToInt32(shipmentDateSplited[1]), Convert.ToInt32(shipmentDateSplited[2]), Convert.ToInt32(shipmentTimeSplited[0]), Convert.ToInt32(shipmentTimeSplited[1]), 0);

            if (result.ProofOfDeliveryDate.IsNull())
            {
                order.UpdateTrackingInfo(shipmentDateTime, result.Status, "", null);
            }
            else
            {
                var podDateSplited          = result.ProofOfDeliveryDate.Split("-");
                var podTimeSplited          = result.ProofOfDeliveryTime.Split(":");
                var proofOfDeliveryDateTime = new DateTime(Convert.ToInt32(podDateSplited[0]), Convert.ToInt32(podDateSplited[1]), Convert.ToInt32(podDateSplited[2]), Convert.ToInt32(podTimeSplited[0]), Convert.ToInt32(podTimeSplited[1]), 0);
                order.UpdateTrackingInfo(shipmentDateTime, result.Status, result.ProofOfDeliveryReceiver, proofOfDeliveryDateTime);
            }

            foreach (var trackingDetail in result.Details)
            {
                var trackingDateplited  = trackingDetail.TrackingDate.Split("-");
                var trackingTimeSplited = trackingDetail.TrackingTime.Split(":");
                var trackingDateTime    = new DateTime(Convert.ToInt32(trackingDateplited[0]), Convert.ToInt32(trackingDateplited[1]), Convert.ToInt32(trackingDateplited[2]), Convert.ToInt32(trackingTimeSplited[0]), Convert.ToInt32(trackingTimeSplited[1]), 0);
                order.AddDetailTrackingInfo(trackingDetail.Code, trackingDetail.Description, trackingDateTime, trackingDetail.CityName);
            }

            if (order.Shipment.IsDelivered)
            {
                this.CompleteOrder(order.Id);
            }

            _orderRepository.Update(order);
        }