public async Task <Order> PaymentNotified(PaymentNotice payment) { Order order = GetOrderByBookingId(payment.BookingId); var orderStatusBefore = order?.Status; if (order == null) { if (payment.Status == "approved" || payment.Status == "in_process") { order = _mapper.Map <PaymentNotice, Order>(payment); order.Registration = await _userManager.FindByIdAsync(payment.User_Id ?? string.Empty); order = CreateOrder(order); } } if (order != null && orderStatusBefore != "approved" && (order.Status == "approved" || payment.Status == "approved")) { order.PickUpTime = _calendarRepository.GetPickupEstimate(order.PreparationTime); order.Status = "approved"; order.Payout = _calendarRepository.LocalTime(); _appDbContext.Orders.Update(order); _appDbContext.SaveChanges(); await _emailRepository.SendOrderConfirmationAsync(order, () => _smsRepository.NotifyAdmins($"¡Pedido nuevo! Código {order.FriendlyBookingId}")); } return(order); }
public async Task <IActionResult> Checkout(Order order) { if (_cartRepository.GetTotal(null) <= 0) { ModelState.AddModelError("EmptyTrolley", "Tu carrito no puede estar vacío, agrega algunos productos."); } if (_cartRepository.GetTotal(null) > _maxArsForReservation) { ModelState.AddModelError("MaxValueReached", "El monto de la reserva supera el límite admitido. Deberás usar Mercado Pago."); } var _currentUser = await _userManager.GetUser(_signInManager); if (!_currentUser.PhoneNumberConfirmed) { ModelState.AddModelError("InvalidPhone", "El número de teléfono no esta verificado."); Redirect($"/Account/VerifyNumber/Order/Checkout/"); } Order anotherReservationInProgress = _orderRepository.LatestReservationInProgress(_currentUser); if (anotherReservationInProgress != null) { var link = $"<a target='_blank' href='{Request.HostUrl()}/Order/Status/{anotherReservationInProgress.FriendlyBookingId}'>{anotherReservationInProgress.FriendlyBookingId}</a>"; ModelState.AddModelError("ReservationInProgress", $"Deberás retirar el pedido {link} para poder reservar otra vez. Alternativamente, podés comprar con Mercado Pago."); } if (ModelState.IsValid) { order.Status = "reservation"; order.Registration = _currentUser; order = _orderRepository.CreateOrder(order); await _emailRespository.SendOrderConfirmationAsync(order, () => _smsRepository.NotifyAdmins($"¡Nueva reserva! Código {order.FriendlyBookingId}") ); return(Redirect($"/Order/Status/{order.FriendlyBookingId}")); } return(View(_currentUser)); }