public ActionResult Finish(CheckoutPage currentPage) { if (!_cartService.GetCartItems().Any()) { return(RedirectToAction("Index")); } var startpage = _contentRepository.Get <StartPage>(ContentReference.StartPage); var confirmationPage = _contentRepository.GetFirstChild <OrderConfirmationPage>(currentPage.ContentLink); PurchaseOrder purchaseOrder = null; string emailAddress = null; OrderForm orderForm = _cartService.GetOrderForms().First(); decimal totalProcessedAmount = orderForm.Payments.Where(x => x.Status.Equals(PaymentStatus.Processed.ToString())).Sum(x => x.Amount); if (totalProcessedAmount != orderForm.Total) { throw new InvalidOperationException("Wrong amount"); } _cartService.RunWorkflow(OrderGroupWorkflowManager.CartCheckOutWorkflowName); purchaseOrder = _checkoutService.SaveCartAsPurchaseOrder(); _checkoutService.DeleteCart(); emailAddress = purchaseOrder.OrderAddresses.First().Email; var queryCollection = new NameValueCollection { { "contactId", _customerContext.CurrentContactId.ToString() }, { "orderNumber", purchaseOrder.OrderGroupId.ToString(CultureInfo.InvariantCulture) } }; try { _mailService.Send(startpage.OrderConfirmationMail, queryCollection, emailAddress, currentPage.Language.Name); } catch (Exception) { // The purchase has been processed and the payment was successfully settled, but for some reason the e-mail // receipt could not be sent to the customer. Rollback is not possible so simple make sure to inform the // customer to print the confirmation page instead. queryCollection.Add("notificationMessage", string.Format(_localizationService.GetString("/OrderConfirmationMail/ErrorMessages/SmtpFailure"), emailAddress)); // Todo: Log the error and raise an alert so that an administrator can look in to it. } _cookieService.Remove(CouponKey); return(Redirect(new UrlBuilder(confirmationPage.LinkURL) { QueryCollection = queryCollection }.ToString())); }