public async Task <IActionResult> Approve(Guid id) { var user = await _userManager.GetUserAsync(User); var booking = await _unitOfWork.Bookings.GetById(id); if (!booking.IsOwnerOfBooking(user.Id) && !booking.IsNotExpired()) { return(Unauthorized()); } var isAvailable = await _unitOfWork.Bookings.IsAvailable(booking.Id, booking.To, booking.From); if (!isAvailable) { return(NotFound()); } int amountInPennies = (int)(booking.TotalPrice * 100); var success = await _stripe.ProcessPayment(booking.StripeCustomerIdToken, amountInPennies, user.Email, "Tapr Booking"); if (!success) { return(RedirectToAction("Detail", "Booking", new { Id = id, message = "We could not process your card details" })); } booking.Approve(); _unitOfWork.Complete(); return(RedirectToAction("Index", "Host", null)); }
public async Task <IActionResult> AddPayment(PaymentCreateBindingModel data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _stripeService.ProcessPayment(data); if (result.Item1.ServiceStatus == ServiceStatus.Error) { foreach (var error in result.Item1.Errors) { ModelState.AddModelError(error.Item1, error.Item2); } return(BadRequest(ModelState)); } else { return(Ok(result.Item2)); } } catch (Exception ex) { throw ex; } }