Example #1
0
        public ActionResult OrderCapturePayment(Int32 orderID)
        {
            var order = _orderService.GetWithTransactions(orderID);

            var authorizations = order.Transactions.Where(t => t.TransactionType == Entity.Models.TransactionType.Authorization);

            List <String> orderUpdates = new List <String>();

            if (authorizations.Any())
            {
                if (authorizations.Count() == 1)
                {
                    var transToCapture = authorizations.First() as CreditCardTransaction;

                    var result = _creditCardService.Capture(transToCapture);

                    if (result.Success)
                    {
                        transToCapture.TransactionType = TransactionType.Payment;

                        _orderService.Update(order);

                        _uow.Save();

                        orderUpdates.Add("Payment has been successfully captured.");
                    }
                    else
                    {
                        orderUpdates.AddRange(result.Errors);
                    }
                }
                else
                {
                    orderUpdates.Add("More than one authorized transaction was found, please visit advanced options.");
                }
            }
            else
            {
                orderUpdates.Add("No transactions found to capture.");
            }

            TempData.Add("OrderUpdates", orderUpdates);

            return(RedirectToAction("Orders"));
        }