public async Task <IActionResult> ConfirmPayment(Guid id, OtherPaymentInfo otherPaymentInfo) //Put in model { var order = await _context.Orders.Include(i => i.Creator).SingleOrDefaultAsync(o => o.ShareIdentifier == id); if (order == null) { return(NotFound()); } if (order.Paid) { ErrorMessage = "Payment has already been confirmed."; return(RedirectToAction("Link", new { id = id })); } if (order.PaymentType == PaymentTypeCodes.CreditCard) { ErrorMessage = "Order requires Other Payment type or UC Account, not a Credit Card Payment type."; return(RedirectToAction("Link", new { id = id })); } if (order.PaymentType == PaymentTypeCodes.Other && string.IsNullOrWhiteSpace(otherPaymentInfo.PoNum)) { ModelState.AddModelError("OtherPaymentInfo.PoNum", "PO # is required"); } otherPaymentInfo.PaymentType = order.GetOrderDetails().OtherPaymentInfo.PaymentType; if (!ModelState.IsValid) { ErrorMessage = "There were errors trying to save that."; var model = new PaymentConfirmationModel { Order = order, OtherPaymentInfo = otherPaymentInfo }; return(View(model)); } var orderDetails = order.GetOrderDetails(); orderDetails.OtherPaymentInfo = otherPaymentInfo; order.SaveDetails(orderDetails); order.Paid = true; order.Status = OrderStatusCodes.Complete; //mark as paid and completed (yeah, completed) await _orderMessageService.EnqueueBillingMessage(order); //Send email to accountants await _context.SaveChangesAsync(); return(RedirectToAction("Link", new { id = id })); }
public async Task <IActionResult> Confirmation(int id, bool confirm) { var order = await _context.Orders.Include(i => i.Creator).SingleOrDefaultAsync(o => o.Id == id); if (order == null) { return(NotFound()); } if (order.CreatorId != CurrentUserId) { ErrorMessage = "You don't have access to this order."; return(NotFound()); } if (order.Status != OrderStatusCodes.Created) { ErrorMessage = "Already confirmed"; return(RedirectToAction("Index")); } if (order.PaymentType == PaymentTypeCodes.UcDavisAccount) { var orderDetails = order.GetOrderDetails(); try { orderDetails.Payment.AccountName = await _financialService.GetAccountName(orderDetails.Payment.Account); } catch { orderDetails.Payment.AccountName = string.Empty; } order.SaveDetails(orderDetails); if (string.IsNullOrWhiteSpace(orderDetails.Payment.AccountName)) { await _context.SaveChangesAsync(); ErrorMessage = "Unable to verify UC Account number. Please edit your order and re-enter the UC account number. Then try again."; return(RedirectToAction("Confirmation", new { id = order.Id })); } } if (order.PaymentType == PaymentTypeCodes.Other) { var orderDetails = order.GetOrderDetails(); if (orderDetails.OtherPaymentInfo.PaymentType.Equals("Agreement", StringComparison.OrdinalIgnoreCase)) { await _orderMessageService.EnqueueBillingMessage(order, "Anlab Work Order Billing Info -- Agreement"); //TODO: Maybe a different one for an Agreement? } } await _orderService.UpdateTestsAndPrices(order); var orderDetailsForClient = order.GetOrderDetails(); if (!string.IsNullOrWhiteSpace(orderDetailsForClient.ClientInfo.ClientId)) { var result = await LookupClientId(orderDetailsForClient.ClientInfo.ClientId); if (result == null) { Log.Error($"Error looking up clientId {orderDetailsForClient.ClientInfo.ClientId}"); } else { orderDetailsForClient.ClientInfo.Email = result.SubEmail; orderDetailsForClient.ClientInfo.PhoneNumber = result.SubPhone; orderDetailsForClient.ClientInfo.CopyPhone = result.CopyPhone; orderDetailsForClient.ClientInfo.Department = result.Department; order.SaveDetails(orderDetailsForClient); } } _orderService.UpdateAdditionalInfo(order); order.Status = OrderStatusCodes.Confirmed; await _orderMessageService.EnqueueCreatedMessage(order); await _context.SaveChangesAsync(); return(RedirectToAction("Confirmed", new { id = id })); }