public DirectionInfo Get(IbsFareRequest request) { var tripDurationInMinutes = (request.TripDurationInSeconds.HasValue ? (int?)TimeSpan.FromSeconds(request.TripDurationInSeconds.Value).TotalMinutes : null); var defaultVehiculeType = _vehicleTypeDao.GetAll().FirstOrDefault(); var fare = _ibsServiceProvider.Booking().GetFareEstimate( request.PickupLatitude, request.PickupLongitude, request.DropoffLatitude, request.DropoffLongitude, request.PickupZipCode, request.DropoffZipCode, request.AccountNumber, request.CustomerNumber, tripDurationInMinutes, _serverSettings.ServerData.DefaultBookingSettings.ProviderId, request.VehicleType, defaultVehiculeType != null ? defaultVehiculeType.ReferenceDataVehicleId : -1); if (fare.FareEstimate != null) { double distance = fare.Distance ?? 0; return(new DirectionInfo { Distance = distance, Price = fare.FareEstimate, FormattedDistance = _resources.FormatDistance(distance), FormattedPrice = _resources.FormatPrice(fare.FareEstimate) }); } return(new DirectionInfo()); }
public AvailableVehiclesResponse Post(AvailableVehicles request) { var vehicleType = _dao.GetAll().FirstOrDefault(v => v.ReferenceDataVehicleId == request.VehicleTypeId); var logoName = vehicleType != null ? vehicleType.LogoName : null; IbsVehiclePosition[] ibsVehicles; string market = null; try { market = _taxiHailNetworkServiceClient.GetCompanyMarket(request.Latitude, request.Longitude); } catch { // Do nothing. If we fail to contact Customer Portal, we continue as if we are in a local market. _logger.LogMessage("VehicleService: Error while trying to get company Market to find available vehicles."); } if (!market.HasValue() && _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.IBS) { // LOCAL market IBS ibsVehicles = _ibsServiceProvider.Booking().GetAvailableVehicles(request.Latitude, request.Longitude, request.VehicleTypeId); } else { string availableVehiclesMarket; IList <int> availableVehiclesFleetIds = null; if (!market.HasValue() && _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.HoneyBadger) { // LOCAL market Honey Badger availableVehiclesMarket = _serverSettings.ServerData.HoneyBadger.AvailableVehiclesMarket; if (request.FleetIds != null) { // Use fleet ids specified in the request first availableVehiclesFleetIds = request.FleetIds; } else if (_serverSettings.ServerData.HoneyBadger.AvailableVehiclesFleetId.HasValue) { // Or fleet id specified in the settings availableVehiclesFleetIds = new[] { _serverSettings.ServerData.HoneyBadger.AvailableVehiclesFleetId.Value }; } } else if (!market.HasValue() && _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.Geo) { // LOCAL market Geo availableVehiclesMarket = _serverSettings.ServerData.CmtGeo.AvailableVehiclesMarket; if (_serverSettings.ServerData.CmtGeo.AvailableVehiclesFleetId.HasValue) { availableVehiclesFleetIds = new[] { _serverSettings.ServerData.CmtGeo.AvailableVehiclesFleetId.Value }; } } else { // EXTERNAL market Honey Badger or Geo availableVehiclesMarket = market; try { // Only get available vehicles for dispatchable companies in market var roamingCompanies = _taxiHailNetworkServiceClient.GetMarketFleets(_serverSettings.ServerData.TaxiHail.ApplicationKey, market); if (roamingCompanies != null) { var roamingFleetIds = roamingCompanies.Select(r => r.FleetId); if (request.FleetIds != null) { // From the fleets accessible by that company, only return vehicles from the fleets specified in the request availableVehiclesFleetIds = roamingFleetIds .Where(fleetId => request.FleetIds.Contains(fleetId)) .ToArray(); } else { // Return vehicles from all fleets accessible by that company availableVehiclesFleetIds = roamingFleetIds.ToArray(); } } else { availableVehiclesFleetIds = request.FleetIds; } } catch { // Do nothing. If we fail to contact Customer Portal, we return an unfiltered list of available vehicles. _logger.LogMessage("VehicleService: Error while trying to get Market fleets."); } } var vehicleResponse = GetAvailableVehiclesServiceClient(market).GetAvailableVehicles( market: availableVehiclesMarket, latitude: request.Latitude, longitude: request.Longitude, searchRadius: request.SearchRadius, fleetIds: availableVehiclesFleetIds, wheelchairAccessibleOnly: (vehicleType != null && vehicleType.IsWheelchairAccessible)); ibsVehicles = vehicleResponse.Select(v => new IbsVehiclePosition { Latitude = v.Latitude, Longitude = v.Longitude, PositionDate = v.Timestamp, VehicleNumber = v.Medallion, FleetId = v.FleetId, Eta = (int?)v.Eta, VehicleType = v.VehicleType, CompassCourse = v.CompassCourse, }).ToArray(); } var isAuthenticated = this.GetSession().IsAuthenticated; var availableVehicles = new List <AvailableVehicle>(); foreach (var ibsVehicle in ibsVehicles) { var vehicle = new AvailableVehicle { Latitude = ibsVehicle.Latitude, Longitude = ibsVehicle.Longitude, LogoName = logoName, Eta = ibsVehicle.Eta, VehicleType = ibsVehicle.VehicleType }; if (isAuthenticated) { vehicle.CompassCourse = ibsVehicle.CompassCourse ?? 0; vehicle.VehicleName = ibsVehicle.VehicleNumber; vehicle.FleetId = ibsVehicle.FleetId; } availableVehicles.Add(vehicle); } return(new AvailableVehiclesResponse(availableVehicles)); }
public IBSOrderResult CreateIbsOrder(Guid orderId, Address pickupAddress, Address dropOffAddress, string accountNumberString, string customerNumberString, string companyKey, int ibsAccountId, string name, string phone, string email, int passengers, int?vehicleTypeId, string ibsInformationNote, bool isFutureBooking, DateTime pickupDate, string[] prompts, int?[] promptsLength, IList <ListItem> referenceDataCompanyList, string market, int?chargeTypeId, int?requestProviderId, Fare fare, double?tipIncentive, int?tipPercent, string assignVehicleId, bool isHailRequest = false, int?companyFleetId = null) { _logger.LogMessage(string.Format("IbsCreateOrderService::CreateIbsOrder - assignVehicleId: {0}", assignVehicleId)); if (_serverSettings.ServerData.IBS.FakeOrderStatusUpdate) { // Wait 15 seconds to reproduce what happens in real life with the "Finding you a taxi" Thread.Sleep(TimeSpan.FromSeconds(15)); // Fake IBS order id return(new IBSOrderResult { CreateOrderResult = new Random(Guid.NewGuid().GetHashCode()).Next(90000, 90000000), IsHailRequest = isHailRequest }); } int?ibsChargeTypeId; if (chargeTypeId == ChargeTypes.CardOnFile.Id || chargeTypeId == ChargeTypes.PayPal.Id) { ibsChargeTypeId = _serverSettings.ServerData.IBS.PaymentTypeCardOnFileId; } else if (chargeTypeId == ChargeTypes.Account.Id) { ibsChargeTypeId = _serverSettings.ServerData.IBS.PaymentTypeChargeAccountId; } else { ibsChargeTypeId = _serverSettings.ServerData.IBS.PaymentTypePaymentInCarId; } var defaultCompany = referenceDataCompanyList.FirstOrDefault(x => x.IsDefault.HasValue && x.IsDefault.Value) ?? referenceDataCompanyList.FirstOrDefault(); //if we are in external market or local market but in a different company var providerId = (market.HasValue() || companyKey.HasValue()) && referenceDataCompanyList.Any() && defaultCompany != null ? defaultCompany.Id : requestProviderId; var ibsPickupAddress = Mapper.Map <IbsAddress>(pickupAddress); var ibsDropOffAddress = dropOffAddress != null && dropOffAddress.IsValid() ? Mapper.Map <IbsAddress>(dropOffAddress) : null; var customerNumber = GetCustomerNumber(accountNumberString, customerNumberString); int?createOrderResult = null; var defaultVehicleType = _vehicleTypeDao.GetAll().FirstOrDefault(); var defaultVehicleTypeId = defaultVehicleType != null ? defaultVehicleType.ReferenceDataVehicleId : -1; IbsHailResponse ibsHailResult = null; if (isHailRequest) { ibsHailResult = Hail(orderId, providerId, market, companyKey, companyFleetId, pickupAddress, ibsAccountId, name, phone, email, passengers, vehicleTypeId, ibsChargeTypeId, ibsInformationNote, pickupDate, ibsPickupAddress, ibsDropOffAddress, accountNumberString, customerNumber, prompts, promptsLength, defaultVehicleTypeId, tipIncentive, tipPercent, fare); } else { createOrderResult = _ibsServiceProvider.Booking(companyKey).CreateOrder( orderId, providerId, ibsAccountId, name, phone, email, passengers, vehicleTypeId, ibsChargeTypeId, ibsInformationNote, pickupDate, ibsPickupAddress, ibsDropOffAddress, accountNumberString, customerNumber, prompts, promptsLength, defaultVehicleTypeId, tipIncentive, tipPercent, assignVehicleId, fare); } var hailResult = Mapper.Map <OrderHailResult>(ibsHailResult); return(new IBSOrderResult { CreateOrderResult = createOrderResult, HailResult = hailResult, IsHailRequest = isHailRequest }); }