Ejemplo n.º 1
0
        public ActionResult PaymentResponse()
        {
            var args = new PaymentResponse(HttpContext);

            foreach (var handler in _paymentServiceProviders)
            {
                handler.ProcessResponse(args);

                if (args.WillHandleResponse)
                {
                    break;
                }
            }

            if (!args.WillHandleResponse)
            {
                throw new OrchardException(_t("Such things mean trouble"));
            }

            var order = _orderService.GetOrderByNumber(args.OrderReference);

            _orderService.UpdateOrderStatus(order, args);

            var user = _authenticationService.GetAuthenticatedUser();

            if (user == null)
            {
                throw new OrchardSecurityException(_t("Login required"));
            }

            var customer = user.ContentItem.As <CustomerPart>();

            if (customer == null)
            {
                throw new InvalidOperationException("The current user is not a customer");
            }

            if (order.Status == OrderStatus.Paid)
            {
                // send an email confirmation to the customer
                string subject = string.Format("Your Order Number {0} has been received", order.Id);
                string body    = string.Format("Dear {0}<br/><br/>Thank you for your order.<br/><br/>You will receive a Tax Invoice when your order is shipped.", customer.FirstName);
                _messageManager.Process(new Dictionary <string, object>
                {
                    { "Recipients", user.Email },
                    { "Subject", subject },
                    { "Body", body }
                });

                //_messageManager.Send(user.ContentItem.Record, "ORDER_RECEIVED", "email", new Dictionary<string, string>
                //{
                //    { "Subject", subject },
                //    { "Body", body}
                //});

                // send a copy of the order to the administator
                _messageManager.Process(new Dictionary <string, object>
                {
                    { "Recipients", _webshopSettings.GetAdministratorEmail() },
                    { "Subject", string.Format("Order Number {0} received from {1} {2}", order.Id, customer.FirstName, customer.LastName) },
                    { "Body", body }
                });


                //string adminEmail = _webshopSettings.GetAdministratorEmail();
                //if (!string.IsNullOrWhiteSpace(adminEmail))
                //    _messageManager.Send(new List<string> { adminEmail}, "ORDER_RECEIVED", "email", new Dictionary<string, string>
                //    {
                //        { "Subject", string.Format("Order Number {0} received from {1} {2}", order.Id, customer.FirstName, customer.LastName) },
                //        { "Body", body}
                //    });

                // decrement stock levels
                _shoppingCart.RemoveFromStock();

                // finally, clear the order
                _shoppingCart.Clear();
            }

            return(new ShapeResult(this, _shapeFactory.Order_PaymentResponse(Order: order, PaymentResponse: args, ContinueShoppingUrl: _webshopSettings.GetContinueShoppingUrl())));
        }