Ejemplo n.º 1
0
        public void CheckStatus(Guid orderId)
        {
            Func <OrderDetail> getOrderDetails = () =>
            {
                var o = _orderDao.FindById(orderId);
                if (o == null)
                {
                    throw new Exception();
                }
                return(o);
            };

            try
            {
                var order = getOrderDetails.Retry(TimeSpan.FromMilliseconds(300), 7);
                if (order != null && order.IBSOrderId.HasValue)
                {
                    var orderStatus = _orderDao.FindOrderStatusById(orderId);
                    var status      = _ibsServiceProvider.Booking(orderStatus.CompanyKey).GetOrdersStatus(new[] { order.IBSOrderId.Value });

                    _orderStatusUpdater.Update(status.ElementAt(0), orderStatus);
                }
            }
            catch
            { }
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        public void ConfirmExternalPayment(Guid orderId, int ibsOrderId, decimal totalAmount, decimal tipAmount, decimal meterAmount, string type, string provider, string transactionId,
                                           string authorizationCode, string cardToken, int accountId, string name, string phone, string email, string os, string userAgent, string companyKey,
                                           decimal fareAmount = 0, decimal extrasAmount = 0, decimal vatAmount = 0, decimal discountAmount = 0, decimal tollAmount = 0, decimal surchargeAmount = 0)
        {
            if (companyKey.HasValue())
            {
                _logger.LogMessage(string.Format("Confirming external payment on external company '{0}'", companyKey));
            }

            if (!_ibsServiceProvider.Booking(companyKey).ConfirmExternalPayment(orderId, ibsOrderId, totalAmount, tipAmount, meterAmount, type, provider, transactionId,
                            authorizationCode, cardToken, accountId, name, phone, email, os, userAgent, fareAmount, extrasAmount, vatAmount, discountAmount, tollAmount, surchargeAmount))
            {
                throw new Exception("Cannot send payment information to dispatch.");
            }
        }
Ejemplo n.º 4
0
        public object Get(InitiateCallToDriverRequest request)
        {
            var order = Dao.FindById(request.OrderId);

            if (order == null)
            {
                return(new HttpResult(HttpStatusCode.NotFound));
            }

            var status = Dao.FindOrderStatusById(request.OrderId);

            if (status == null)
            {
                return(new HttpResult(HttpStatusCode.NotFound));
            }

            var account = _accountDao.FindById(new Guid(this.GetSession().UserAuthId));

            if (account.Id != order.AccountId)
            {
                throw new HttpError(HttpStatusCode.Unauthorized, "Can't initiate a call with driver of another account's order");
            }

            if (order.IBSOrderId.HasValue &&
                status.VehicleNumber.HasValue())
            {
                return(_ibsServiceProvider.Booking(order.CompanyKey).InitiateCallToDriver(order.IBSOrderId.Value, status.VehicleNumber));
            }

            return(false);
        }
Ejemplo n.º 5
0
        public object Post(ConfirmHailRequest request)
        {
            if (request.OrderKey.IbsOrderId < 0)
            {
                throw new HttpError(string.Format("Cannot confirm hail because IBS returned error code {0}", request.OrderKey.IbsOrderId));
            }

            if (request.VehicleCandidate == null)
            {
                throw new HttpError("You need to specify a vehicle in order to confirm the hail.");
            }

            var orderDetail = _orderDao.FindById(request.OrderKey.TaxiHailOrderId);

            if (orderDetail == null)
            {
                throw new HttpError(string.Format("Order {0} doesn't exist", request.OrderKey.TaxiHailOrderId));
            }

            _logger.LogMessage(string.Format("Trying to confirm Hail. Request : {0}", request.ToJson()));

            var ibsOrderKey         = Mapper.Map <IbsOrderKey>(request.OrderKey);
            var ibsVehicleCandidate = Mapper.Map <IbsVehicleCandidate>(request.VehicleCandidate);

            var confirmHailResult = _ibsServiceProvider.Booking(orderDetail.CompanyKey).ConfirmHail(ibsOrderKey, ibsVehicleCandidate);

            if (confirmHailResult == null || confirmHailResult < 0)
            {
                var errorMessage = string.Format("Error while trying to confirm the hail. IBS response code : {0}", confirmHailResult);
                _logger.LogMessage(errorMessage);

                return(new HttpResult(HttpStatusCode.InternalServerError, errorMessage));
            }

            _logger.LogMessage("Hail request confirmed");

            return(new OrderStatusDetail
            {
                OrderId = request.OrderKey.TaxiHailOrderId,
                Status = OrderStatus.Created,
                IBSStatusId = VehicleStatuses.Common.Assigned,
                IBSStatusDescription = string.Format(
                    _resources.Get("OrderStatus_CabDriverNumberAssigned", orderDetail.ClientLanguageCode),
                    request.VehicleCandidate.VehicleId)
            });
        }
Ejemplo n.º 6
0
        public object Post(OrderUpdateRequest request)
        {
            var order = _orderDao.FindById(request.OrderId);

            if (order == null || !order.IBSOrderId.HasValue)
            {
                throw new HttpError(HttpStatusCode.BadRequest, ErrorCode.OrderNotInIbs.ToString());
            }

            var success = _ibsServiceProvider.Booking(order.CompanyKey).UpdateDropOffInTrip(order.IBSOrderId.Value, order.Id, request.DropOffAddress);

            if (success)
            {
                _commandBus.Send(new UpdateOrderInTrip {
                    OrderId = request.OrderId, DropOffAddress = request.DropOffAddress
                });
            }

            return(success);
        }
Ejemplo n.º 7
0
        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 object Post(SendReceiptAdmin request)
        {
            var order = _orderDao.FindById(request.OrderId);

            if (order == null || !(order.IsManualRideLinq || order.IBSOrderId.HasValue))
            {
                throw new HttpError(HttpStatusCode.BadRequest, ErrorCode.OrderNotInIbs.ToString());
            }

            AccountDetail account;

            // if the admin is requesting the receipt then it won't be for the logged in user
            if (!request.RecipientEmail.IsNullOrEmpty())
            {
                account = _accountDao.FindById(order.AccountId);
            }
            else
            {
                account = _accountDao.FindById(new Guid(this.GetSession().UserAuthId));
                if (account.Id != order.AccountId)
                {
                    throw new HttpError(HttpStatusCode.Unauthorized, "Not your order");
                }
            }

            // If the order was created in another company, need to fetch the correct IBS account
            var ibsAccountId = _accountDao.GetIbsAccountId(account.Id, order.CompanyKey);

            if (!(ibsAccountId.HasValue || order.IsManualRideLinq))
            {
                throw new HttpError(HttpStatusCode.BadRequest, ErrorCode.IBSAccountNotFound.ToString());
            }

            var ibsOrder = !order.IsManualRideLinq
                ? _ibsServiceProvider.Booking(order.CompanyKey).GetOrderDetails(order.IBSOrderId.Value, ibsAccountId.Value, order.Settings.Phone)
                : null;

            var orderPayment = _orderPaymentDao.FindByOrderId(order.Id, order.CompanyKey);
            var pairingInfo  = _orderDao.FindOrderPairingById(order.Id);
            var orderStatus  = _orderDao.FindOrderStatusById(request.OrderId);

            double?fareAmount;
            double?tollAmount = null;
            double?tipAmount;
            double?taxAmount;
            double?surcharge;
            double?bookingFees = null;
            double?extraAmount = null;
            PromotionUsageDetail promotionUsed = null;

            ReadModel.CreditCardDetails creditCard = null;

            var ibsOrderId = orderStatus.IBSOrderId;

            Commands.SendReceipt.CmtRideLinqReceiptFields cmtRideLinqFields = null;

            if (orderPayment != null && orderPayment.IsCompleted)
            {
                fareAmount  = Convert.ToDouble(orderPayment.Meter);
                tipAmount   = Convert.ToDouble(orderPayment.Tip);
                taxAmount   = Convert.ToDouble(orderPayment.Tax);
                surcharge   = Convert.ToDouble(orderPayment.Surcharge);
                bookingFees = Convert.ToDouble(orderPayment.BookingFees);

                // promotion can only be used with in app payment
                promotionUsed = _promotionDao.FindByOrderId(request.OrderId);

                creditCard = orderPayment.CardToken.HasValue()
                    ? _creditCardDao.FindByToken(orderPayment.CardToken)
                    : null;
            }
            else if (order.IsManualRideLinq)
            {
                var manualRideLinqDetail = _orderDao.GetManualRideLinqById(order.Id);
                fareAmount  = manualRideLinqDetail.Fare;
                ibsOrderId  = manualRideLinqDetail.TripId;
                tollAmount  = manualRideLinqDetail.Toll;
                extraAmount = manualRideLinqDetail.Extra;
                tipAmount   = manualRideLinqDetail.Tip;
                taxAmount   = manualRideLinqDetail.Tax;
                surcharge   = manualRideLinqDetail.Surcharge;
                orderStatus.DriverInfos.DriverId = manualRideLinqDetail.DriverId.ToString();
                order.DropOffAddress             = _geocoding.TryToGetExactDropOffAddress(orderStatus, manualRideLinqDetail.LastLatitudeOfVehicle, manualRideLinqDetail.LastLongitudeOfVehicle, order.DropOffAddress, order.ClientLanguageCode);

                cmtRideLinqFields = new Commands.SendReceipt.CmtRideLinqReceiptFields
                {
                    TripId                 = manualRideLinqDetail.TripId,
                    DriverId               = manualRideLinqDetail.DriverId.ToString(),
                    Distance               = manualRideLinqDetail.Distance,
                    AccessFee              = manualRideLinqDetail.AccessFee,
                    PickUpDateTime         = manualRideLinqDetail.StartTime,
                    DropOffDateTime        = manualRideLinqDetail.EndTime,
                    LastFour               = manualRideLinqDetail.LastFour,
                    FareAtAlternateRate    = manualRideLinqDetail.FareAtAlternateRate,
                    RateAtTripEnd          = (int)(manualRideLinqDetail.RateAtTripEnd.GetValueOrDefault()),
                    RateAtTripStart        = (int)(manualRideLinqDetail.RateAtTripStart.GetValueOrDefault()),
                    LastLatitudeOfVehicle  = order.DropOffAddress.Latitude,
                    LastLongitudeOfVehicle = order.DropOffAddress.Longitude,
                    TipIncentive           = order.TipIncentive ?? 0
                };
            }
            else if (pairingInfo != null && pairingInfo.AutoTipPercentage.HasValue)
            {
                var tripInfo = GetTripInfo(pairingInfo.PairingToken);
                if (tripInfo != null && !tripInfo.ErrorCode.HasValue && tripInfo.EndTime.HasValue)
                {
                    // this is for CMT RideLinq only, no VAT

                    fareAmount = Math.Round(((double)tripInfo.Fare / 100), 2);
                    var tollHistory = tripInfo.TollHistory != null
                        ? tripInfo.TollHistory.Sum(p => p.TollAmount)
                        : 0;

                    tollAmount  = Math.Round(((double)tollHistory / 100), 2);
                    extraAmount = Math.Round(((double)tripInfo.Extra / 100), 2);
                    tipAmount   = Math.Round(((double)tripInfo.Tip / 100), 2);
                    taxAmount   = Math.Round(((double)tripInfo.Tax / 100), 2);
                    surcharge   = Math.Round(((double)tripInfo.Surcharge / 100), 2);
                    orderStatus.DriverInfos.DriverId = tripInfo.DriverId.ToString();

                    cmtRideLinqFields = new Commands.SendReceipt.CmtRideLinqReceiptFields
                    {
                        TripId              = tripInfo.TripId,
                        DriverId            = tripInfo.DriverId.ToString(),
                        Distance            = tripInfo.Distance,
                        AccessFee           = Math.Round(((double)tripInfo.AccessFee / 100), 2),
                        PickUpDateTime      = tripInfo.StartTime,
                        DropOffDateTime     = tripInfo.EndTime,
                        LastFour            = tripInfo.LastFour,
                        FareAtAlternateRate = Math.Round(((double)tripInfo.FareAtAlternateRate / 100), 2),
                        RateAtTripEnd       = tripInfo.RateAtTripEnd,
                        RateAtTripStart     = tripInfo.RateAtTripStart,
                        Tolls        = tripInfo.TollHistory,
                        TipIncentive = (order.TipIncentive.HasValue) ? order.TipIncentive.Value : 0
                    };
                }
                else
                {
                    fareAmount = ibsOrder.Fare;
                    tollAmount = ibsOrder.Toll;
                    tipAmount  = FareHelper.CalculateTipAmount(ibsOrder.Fare.GetValueOrDefault(0),
                                                               pairingInfo.AutoTipPercentage.Value);
                    taxAmount = ibsOrder.VAT;
                    surcharge = order.Surcharge;
                }

                orderPayment = null;
                creditCard   = pairingInfo.TokenOfCardToBeUsedForPayment.HasValue()
                    ? _creditCardDao.FindByToken(pairingInfo.TokenOfCardToBeUsedForPayment)
                    : null;
            }
            else
            {
                fareAmount = ibsOrder.Fare;
                tollAmount = ibsOrder.Toll;
                tipAmount  = ibsOrder.Tip;
                taxAmount  = ibsOrder.VAT;
                surcharge  = order.Surcharge;

                orderPayment = null;
            }

            var orderReport = _reportDao.GetOrderReportWithOrderId(order.Id);

            var sendReceiptCommand = SendReceiptCommandBuilder.GetSendReceiptCommand(
                order,
                account,
                ibsOrderId,
                (orderReport != null ? orderReport.VehicleInfos.Number : ibsOrder.VehicleNumber),
                orderStatus.DriverInfos,
                fareAmount,
                tollAmount,
                extraAmount,
                surcharge,
                bookingFees,
                tipAmount,
                taxAmount,
                orderPayment,
                promotionUsed != null
                        ? Convert.ToDouble(promotionUsed.AmountSaved)
                        : (double?)null,
                promotionUsed,
                creditCard,
                cmtRideLinqFields);

            // Since the user or an admin requested the receipt, we should bypass the normal notification settings.
            sendReceiptCommand.BypassNotificationSettings = true;

            if (!request.RecipientEmail.IsNullOrEmpty())
            {
                sendReceiptCommand.EmailAddress = request.RecipientEmail;
            }
            _commandBus.Send(sendReceiptCommand);

            return(new HttpResult(HttpStatusCode.OK, "OK"));
        }
Ejemplo n.º 9
0
 private bool UpdateIBSOrderPaymentType(int ibsAccountId, int ibsOrderId, string companyKey = null)
 {
     // Change payment type to Pay in Car
     return(_ibsServiceProvider.Booking(companyKey).UpdateOrderPaymentType(ibsAccountId, ibsOrderId, _serverSettings.ServerData.IBS.PaymentTypePaymentInCarId));
 }
Ejemplo n.º 10
0
        private async Task <ServiceStatus> GetServiceStatus()
        {
            // Setup tests variable
            var useGeo = _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.Geo ||
                         _serverSettings.ServerData.ExternalAvailableVehiclesMode == ExternalAvailableVehiclesModes.Geo;

            var useHoneyBadger = _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.HoneyBadger ||
                                 _serverSettings.ServerData.ExternalAvailableVehiclesMode == ExternalAvailableVehiclesModes.HoneyBadger;

            var paymentSettings = _serverSettings.GetPaymentSettings();

            var useCmtPapi = paymentSettings.PaymentMode == PaymentMethod.Cmt ||
                             paymentSettings.PaymentMode == PaymentMethod.RideLinqCmt;

            // Setup tests
            var ibsTest = RunTest(() => Task.Run(() => _ibsProvider.Booking().GetOrdersStatus(new[] { 0 })), "IBS");

            var geoTest = useGeo
                ? RunTest(() => Task.Run(() => RunGeoTest()), "GEO")
                : Task.FromResult(false); // We do nothing here.

            var honeyBadger = useHoneyBadger
                ? RunTest(() => Task.Run(() => RunHoneyBadgerTest()), "HoneyBadger")
                : Task.FromResult(false); // We do nothing here.

            var orderStatusUpdateDetailTest = Task.Run(() => _statusUpdaterDao.GetLastUpdate());

            var sqlTest = RunTest(async() => await orderStatusUpdateDetailTest, "SQL");

            var mapiTest = paymentSettings.PaymentMode == PaymentMethod.RideLinqCmt
                ? RunTest(async() => await RunMapiTest(), "CMT MAPI")
                : Task.FromResult(false);

            var papiTest = useCmtPapi
                ? RunTest(() => Task.Run(() => RunPapiTest(paymentSettings.CmtPaymentSettings)), "CMT PAPI")
                : Task.FromResult(false);

            var customerPortalTest = RunTest(() => Task.Run(() => _networkService.GetCompanyMarketSettings(_serverSettings.ServerData.GeoLoc.DefaultLatitude, _serverSettings.ServerData.GeoLoc.DefaultLongitude)), "Customer Portal");

            // We use ConfigureAwait false here to ensure we are not deadlocking ourselves.
            await Task.WhenAll(ibsTest, geoTest, honeyBadger, sqlTest, mapiTest, papiTest, customerPortalTest).ConfigureAwait(false);

            var orderStatusUpdateDetails = orderStatusUpdateDetailTest.Result;

            var now = DateTime.UtcNow;

            var isUpdaterDeadlocked = orderStatusUpdateDetails.CycleStartDate.HasValue &&
                                      orderStatusUpdateDetails.CycleStartDate + TimeSpan.FromMinutes(10) < now;

            return(new ServiceStatus
            {
                IsIbsAvailable = ibsTest.Result,
                IbsUrl = _serverSettings.ServerData.IBS.WebServicesUrl,
                IsGeoAvailable = useGeo ? geoTest.Result : (bool?)null,
                GeoUrl = useGeo ? _serverSettings.ServerData.CmtGeo.ServiceUrl : null,
                IsHoneyBadgerAvailable = useHoneyBadger ? honeyBadger.Result : (bool?)null,
                HoneyBadgerUrl = _serverSettings.ServerData.HoneyBadger.ServiceUrl,
                IsSqlAvailable = sqlTest.Result,
                IsMapiAvailable = paymentSettings.PaymentMode == PaymentMethod.RideLinqCmt ? mapiTest.Result : (bool?)null,
                MapiUrl = paymentSettings.PaymentMode == PaymentMethod.RideLinqCmt ? GetMapiUrl() : null,
                IsPapiAvailable = useCmtPapi ? papiTest.Result : (bool?)null,
                PapiUrl = useCmtPapi ? GetPapiUrl() :null,
                IsCustomerPortalAvailable = customerPortalTest.Result,
                LastOrderUpdateDate = orderStatusUpdateDetails.LastUpdateDate,
                CycleStartDate = orderStatusUpdateDetails.CycleStartDate,
                LastOrderUpdateId = orderStatusUpdateDetails.Id.ToString(),
                LastOrderUpdateServer = orderStatusUpdateDetails.UpdaterUniqueId,
                IsUpdaterDeadlocked = isUpdaterDeadlocked
            });
        }
Ejemplo n.º 11
0
        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
            });
        }