public async Task <ActionResult> PayReservation(ReservationPaymentViewModel model) { _logger.Info("Paying Reservation! Params: " + model.ToJson()); if (!ModelState.IsValid) { _logger.Error("Paying Reservation Form Invalid! Errors:" + ModelState.ToJson()); return(Json(ModelState.ToDictionary())); //throw new ArgumentException("Проблем при плащане на резервацията. Опитайте отново, ако не стане свържете се с екипът ни!"); } if (model.PaymentInfo.PaymentMethod.ToUpper() == "EASYPAY" && (string.IsNullOrEmpty(model.PaymentInfo.PayerName) || model.PaymentInfo.PayerName.Length > 26)) { ModelState.AddModelError(nameof(model.PaymentInfo.PayerName), "Името е задължително и не трябва да превишава 26 символа"); _logger.Error("Paying Reservation Form Invalid! Errors:" + ModelState.ToJson()); return(Json(ModelState.ToDictionary())); } try { //Either EasyPayCode or redirect Form which have to be submited var paymentRedirectForm = await ReservationsManager.PayReservation(model.Id, model.IsCaparoPayed, model.PaymentInfo, model.UrlOk, model.UrlCancel); _logger.Info("Paying Reservation - Redirecting to External Payment provider!"); return(Content(paymentRedirectForm)); } catch (Exception ex) { _logger.Error(ex, "Paying Reservation Failed!"); throw; } }
public async Task <IHttpActionResult> CreatePayment(ReservationPaymentBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var reservationPayment = new ReservationPayment { ReservationId = model.ReservationId, Payment = new Payment { PaymentDate = model.Payment.PaymentDate, Amount = model.Payment.Amount, PaymentStatusId = (model.Payment.StatusId == 0) ? 2 : model.Payment.StatusId } }; await ReservationPaymentRepository.Add(reservationPayment); var result = await ReservationPaymentRepository.Get(reservationPayment.Id); var reservationViewModel = new ReservationPaymentViewModel { Id = reservationPayment.Id, Payment = new PaymentViewModel { Id = result.PaymentId, PaymentDate = result.Payment.PaymentDate, Amount = result.Payment.Amount, //Status = result.Payment.Status.Description }, Reservation = new ReservationViewModel { Id = result.ReservationId, ReservationDate = result.Reservation.ReservationDate, NumberInParty = result.Reservation.NumberInParty } }; return(Ok(reservationViewModel)); }