public async Task <bool> ConfirmPay(PostPaymentViewModel payInfo) { //TODO need to use using try { var order = await _orderRepository.FindByIdAsync(Guid.Parse(payInfo.OrderId)); order.Status = Status.Paid; _orderRepository.Update(order); var product = await _productRepository.FindByIdAsync(order.ProductId); product.Quantity -= order.Quantity; _productRepository.Update(product); var options = new ChargeCreateOptions { Amount = (long)payInfo.OrderTotalCost * 100, Currency = "usd", Description = payInfo.Description, Source = payInfo.StripeToken }; var service = new ChargeService(); Charge charge = service.Create(options); await _orderRepository.SaveAsync(); await _productRepository.SaveAsync(); } catch { return(false); } return(true); }
public async Task <ActionResult> Create(PostPaymentViewModel paymentModel) { var wasSuccess = await _paymentService.ConfirmPay(paymentModel); if (wasSuccess) { return(View("ThankYou")); } return(View("Error")); }
public ActionResult SavePayment() { var patientFound = Session[Values.SearchedPatientKey]; PostPaymentViewModel viewModel = new PostPaymentViewModel(); if (patientFound != null) { var patient = (PatientFoundDetails)patientFound; viewModel.PatientGivenId = patient.PatientGivenId; viewModel.Username = patient.Username; viewModel.FirstName = patient.FirstName; viewModel.LastName = patient.LastName; viewModel.SubmitDisabled = false; } return(View(viewModel)); }
public ActionResult SavePayment(PostPaymentViewModel viewModel) { viewModel.CreatedBy = Admin.Id; var info = postPaymentService.SavePayment(viewModel); if (info.HasError()) { SetErrorMessages(info.ErrorMessages); viewModel.SubmitDisabled = false; } else { SetSuccessMessage(info.SuccessMessage); ClearFields(viewModel); viewModel.SubmitDisabled = true; } return(View(viewModel)); }