public bool SendOrderCreationCommands(Guid orderId, int?ibsOrderId, bool isPrepaid, string clientLanguageCode, bool switchedCompany = false, string newCompanyKey = null, string newCompanyName = null, string market = null) { if (!ibsOrderId.HasValue || ibsOrderId <= 0) { var code = !ibsOrderId.HasValue || (ibsOrderId.Value >= -1) ? string.Empty : "_" + Math.Abs(ibsOrderId.Value); var errorCode = "CreateOrder_CannotCreateInIbs" + code; var errorCommand = new CancelOrderBecauseOfError { OrderId = orderId, ErrorCode = errorCode, ErrorDescription = _resources.Get(errorCode, clientLanguageCode) }; _commandBus.Send(errorCommand); return(false); } else if (switchedCompany) { var orderDetail = _orderDao.FindById(orderId); // Cancel order on current company IBS _ibsCreateOrderService.CancelIbsOrder(orderDetail.IBSOrderId, orderDetail.CompanyKey, orderDetail.Settings.Phone, orderDetail.AccountId); _commandBus.Send(new SwitchOrderToNextDispatchCompany { OrderId = orderId, IBSOrderId = ibsOrderId.Value, CompanyKey = newCompanyKey, CompanyName = newCompanyName, Market = market }); return(true); } else { _logger.LogMessage(string.Format("Adding IBSOrderId {0} to order {1}", ibsOrderId, orderId)); var ibsCommand = new AddIbsOrderInfoToOrder { OrderId = orderId, IBSOrderId = ibsOrderId.Value }; _commandBus.Send(ibsCommand); return(true); } }
public void Handle(IbsOrderInfoAddedToOrder @event) { if ([email protected]) { return; } // User decided to cancel his order before we got assigned an ibs order id // Since we now have the ibs order id and the order is already flagged as cancelled on our side, we have to cancel it on ibs var orderDetail = _orderDao.FindById(@event.SourceId); _logger.LogMessage( string.Format("User requested a cancellation before IbsOrderId was received, cancel the order on ibs now that we have it (OrderId: {0}, IbsOrderId: {1}, CompanyKey {2})", @event.SourceId, @event.IBSOrderId, orderDetail.CompanyKey )); // Cancel order on current company IBS _ibsCreateOrderService.CancelIbsOrder(@event.IBSOrderId, orderDetail.CompanyKey, orderDetail.Settings.Phone, orderDetail.AccountId); }
public object Post(CancelOrder request) { var order = _orderDao.FindById(request.OrderId); var account = _accountDao.FindById(new Guid(this.GetSession().UserAuthId)); if (order == null) { return(new HttpResult(HttpStatusCode.NotFound)); } if (account.Id != order.AccountId) { throw new HttpError(HttpStatusCode.Unauthorized, "Can't cancel another account's order"); } if (order.IBSOrderId.HasValue) { var currentIbsAccountId = _accountDao.GetIbsAccountId(account.Id, order.CompanyKey); var orderStatus = _orderDao.FindOrderStatusById(order.Id); var marketSettings = _networkServiceClient.GetCompanyMarketSettings(order.PickupAddress.Latitude, order.PickupAddress.Longitude); var canCancelWhenPaired = orderStatus.IBSStatusId.SoftEqual(VehicleStatuses.Common.Loaded) && marketSettings.DisableOutOfAppPayment; if (currentIbsAccountId.HasValue && (!orderStatus.IBSStatusId.HasValue() || orderStatus.IBSStatusId.SoftEqual(VehicleStatuses.Common.Waiting) || orderStatus.IBSStatusId.SoftEqual(VehicleStatuses.Common.Assigned) || orderStatus.IBSStatusId.SoftEqual(VehicleStatuses.Common.Arrived) || orderStatus.IBSStatusId.SoftEqual(VehicleStatuses.Common.Scheduled) || canCancelWhenPaired)) { _ibsCreateOrderService.CancelIbsOrder(order.IBSOrderId.Value, order.CompanyKey, order.Settings.Phone, account.Id); } else { var errorReason = !currentIbsAccountId.HasValue ? string.Format("no IbsAccountId found for accountid {0} and companykey {1}", account.Id, order.CompanyKey) : string.Format("orderDetail.IBSStatusId is not in the correct state: {0}, state: {1}", orderStatus.IBSStatusId, orderStatus.IBSStatusId); var errorMessage = string.Format("Could not cancel order because {0}", errorReason); _logger.LogMessage(errorMessage); throw new HttpError(HttpStatusCode.BadRequest, _resources.Get("CancelOrderError"), errorMessage); } } else { _logger.LogMessage("We don't have an ibs order id yet, send a CancelOrder command so that when we receive the ibs order info, we can cancel it"); } var command = new Commands.CancelOrder { OrderId = request.OrderId }; _commandBus.Send(command); UpdateStatusAsync(command.OrderId); return(new HttpResult(HttpStatusCode.OK)); }
public object Post(SwitchOrderToNextDispatchCompanyRequest request) { _logger.LogMessage("Switching order to another IBS : " + request.ToJson()); var account = _accountDao.FindById(new Guid(this.GetSession().UserAuthId)); var order = _orderDao.FindById(request.OrderId); var orderStatusDetail = _orderDao.FindOrderStatusById(request.OrderId); if (orderStatusDetail.Status != OrderStatus.TimedOut) { // Only switch companies if order is timedout return(orderStatusDetail); } // We are in a network timeout situation. if (orderStatusDetail.CompanyKey == request.NextDispatchCompanyKey) { _ibsCreateOrderService.CancelIbsOrder(order.IBSOrderId, order.CompanyKey, order.Settings.Phone, account.Id); orderStatusDetail.IBSStatusId = VehicleStatuses.Common.Timeout; orderStatusDetail.IBSStatusDescription = _resources.Get("OrderStatus_" + VehicleStatuses.Common.Timeout); return(orderStatusDetail); } var market = _taxiHailNetworkServiceClient.GetCompanyMarket(order.PickupAddress.Latitude, order.PickupAddress.Longitude); var isConfiguredForCmtPayment = _taxiHailNetworkHelper.FetchCompanyPaymentSettings(request.NextDispatchCompanyKey); var chargeTypeId = order.Settings.ChargeTypeId; var chargeTypeDisplay = order.Settings.ChargeType; if (!isConfiguredForCmtPayment) { // Only companies configured for CMT payment can support CoF orders outside of home market chargeTypeId = ChargeTypes.PaymentInCar.Id; chargeTypeDisplay = ChargeTypes.PaymentInCar.Display; } var newOrderRequest = new CreateOrderRequest { PickupDate = GetCurrentOffsetedTime(request.NextDispatchCompanyKey), PickupAddress = order.PickupAddress, DropOffAddress = order.DropOffAddress, Settings = new BookingSettings { LargeBags = order.Settings.LargeBags, Name = order.Settings.Name, NumberOfTaxi = order.Settings.NumberOfTaxi, Passengers = order.Settings.Passengers, Phone = order.Settings.Phone, ProviderId = null, ChargeType = chargeTypeDisplay, ChargeTypeId = chargeTypeId, // Reset vehicle type VehicleType = null, VehicleTypeId = null }, Note = order.UserNote, ClientLanguageCode = account.Language }; var fare = FareHelper.GetFareFromEstimate(new RideEstimate { Price = order.EstimatedFare }); var newReferenceData = (ReferenceData)_referenceDataService.Get(new ReferenceDataRequest { CompanyKey = request.NextDispatchCompanyKey }); // This must be localized with the priceformat to be localized in the language of the company // because it is sent to the driver var chargeTypeIbs = _resources.Get(chargeTypeDisplay, _serverSettings.ServerData.PriceFormat); var ibsInformationNote = IbsHelper.BuildNote( _serverSettings.ServerData.IBS.NoteTemplate, chargeTypeIbs, order.UserNote, order.PickupAddress.BuildingName, newOrderRequest.Settings.LargeBags, _serverSettings.ServerData.IBS.HideChargeTypeInUserNote); var networkErrorMessage = string.Format(_resources.Get("Network_CannotCreateOrder", order.ClientLanguageCode), request.NextDispatchCompanyName); int ibsAccountId; try { // Recreate order on next dispatch company IBS ibsAccountId = CreateIbsAccountIfNeeded(account, request.NextDispatchCompanyKey); } catch (Exception ex) { _logger.LogMessage(networkErrorMessage); _logger.LogError(ex); throw new HttpError(HttpStatusCode.InternalServerError, networkErrorMessage); } ValidateProvider(newOrderRequest, newReferenceData, market.HasValue(), null); var newOrderCommand = Mapper.Map <CreateOrder>(newOrderRequest); newOrderCommand.OrderId = request.OrderId; newOrderCommand.ReferenceDataCompanyList = newReferenceData.CompaniesList.ToArray(); newOrderCommand.Market = market; newOrderCommand.CompanyKey = request.NextDispatchCompanyKey; newOrderCommand.CompanyName = request.NextDispatchCompanyName; newOrderCommand.Fare = fare; newOrderCommand.IbsInformationNote = ibsInformationNote; _commandBus.Send(new InitiateIbsOrderSwitch { NewIbsAccountId = ibsAccountId, NewOrderCommand = newOrderCommand }); return(new OrderStatusDetail { OrderId = request.OrderId, Status = OrderStatus.Created, CompanyKey = request.NextDispatchCompanyKey, CompanyName = request.NextDispatchCompanyName, NextDispatchCompanyKey = null, NextDispatchCompanyName = null, IBSStatusId = string.Empty, IBSStatusDescription = string.Format(_resources.Get("OrderStatus_wosWAITINGRoaming", order.ClientLanguageCode), request.NextDispatchCompanyName), }); }