Ejemplo n.º 1
0
        public async Task <OrderConfirmationViewModel> ConfirmOrder(string token)
        {
            var options = paypalOptions.CurrentValue;
            PayPalEnvironment environment = CreateEnvironment();
            var client = new PayPalHttpClient(environment);

            var request = new OrdersCaptureRequest(token);

            request.Prefer("return=representation");
            request.RequestBody(new OrderActionRequest());
            try
            {
                var response = await client.Execute(request);

                Order order = response.Result <Order>();
                return(OrderConfirmationViewModel.FromOrder(order));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                logger.LogError($"Il tentativo di catturare il pagamento è fallito con status code {statusCode} e debugId {debugId}");
                throw new PaymentException();
            }
        }
Ejemplo n.º 2
0
        public OrderConfirmationViewModel Build()
        {
            var viewModel = new OrderConfirmationViewModel();

            viewModel.OrderNumber = orderID.ToString();
            viewModel.Email       = checkoutDetails.Email;

            return(viewModel);
        }
        public ActionResult OrderConfirmation([Bind(Prefix = StorefrontConstants.QueryStrings.ConfirmationId)] string confirmationId)
        {
            var viewModel = new OrderConfirmationViewModel();
            var order     = _checkoutRepository.GetCommerceOrder(confirmationId);

            viewModel.Initialize(this.CurrentRendering, confirmationId, order);

            return(View("OrderConfirmation", viewModel));
        }
Ejemplo n.º 4
0
        public ActionResult Index(OrderConfirmationMailPage currentPage, Guid?contactId = null, int orderNumber = 0)
        {
            PurchaseOrder order = _confirmationService.GetOrder(orderNumber, PageEditing.PageIsInEditMode);

            if (order == null && !PageEditing.PageIsInEditMode)
            {
                return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
            }

            OrderConfirmationViewModel <OrderConfirmationMailPage> model = CreateViewModel(currentPage, order);

            return(View(model));
        }
        protected OrderConfirmationViewModel <T> CreateViewModel(T currentPage, IPurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <T> {
                    CurrentPage = currentPage
                });
            }

            var lineItems = order.GetFirstForm().Shipments.SelectMany(x => x.LineItems);
            var totals    = _orderGroupTotalsCalculator.GetOrderGroupTotals(order);

            var viewModel = new OrderConfirmationViewModel <T>
            {
                Currency                = order.Currency,
                CurrentPage             = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.OrderNumber,
                Created                 = order.Created,
                Items                   = lineItems,
                BillingAddress          = new AddressModel(),
                ShippingAddresses       = new List <AddressModel>(),
                ContactId               = _customerContext.CurrentContactId,
                Payments                = order.GetFirstForm().Payments,
                OrderGroupId            = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(),
                ShippingSubTotal        = order.GetShippingSubTotal(),
                ShippingDiscountTotal   = order.GetShippingDiscountTotal(),
                ShippingTotal           = totals.ShippingTotal,
                HandlingTotal           = totals.HandlingTotal,
                TaxTotal                = totals.TaxTotal,
                CartTotal               = totals.Total
            };

            var billingAddress = order.GetFirstForm().Payments.First().BillingAddress;

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapToModel(billingAddress, viewModel.BillingAddress);

            // Map the remaining addresses as shipping addresses.
            foreach (var orderAddress in order.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
            {
                var shippingAddress = new AddressModel();
                _addressBookService.MapToModel(orderAddress, shippingAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }
Ejemplo n.º 6
0
        private OrderConfirmationViewModel <OrderConfirmationMailPage> CreateViewModel(OrderConfirmationMailPage currentPage, IPurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <OrderConfirmationMailPage>(currentPage));
            }

            var lineItems = order.GetFirstForm().Shipments.SelectMany(x => x.LineItems);
            var totals    = _orderGroupCalculator.GetOrderGroupTotals(order);

            var viewModel = new OrderConfirmationViewModel <OrderConfirmationMailPage>(currentPage)
            {
                Currency                = order.Currency,
                CurrentContent          = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.OrderNumber,
                Created                 = order.Created,
                Items                   = lineItems,
                BillingAddress          = new AddressModel(),
                ShippingAddresses       = new List <AddressModel>(),
                ContactId               = _customerService.CurrentContactId,
                Payments                = order.GetFirstForm().Payments.Where(c => c.TransactionType == TransactionType.Authorization.ToString() || c.TransactionType == TransactionType.Sale.ToString()),
                OrderGroupId            = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(),
                ShippingSubTotal        = order.GetShippingSubTotal(),
                ShippingDiscountTotal   = order.GetShippingDiscountTotal(),
                ShippingTotal           = totals.ShippingTotal,
                HandlingTotal           = totals.HandlingTotal,
                TaxTotal                = totals.TaxTotal,
                CartTotal               = totals.Total,
                SubTotal                = order.GetSubTotal()
            };

            var billingAddress = order.GetFirstForm().Payments.First().BillingAddress;

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapToModel(billingAddress, viewModel.BillingAddress);

            // Map the remaining addresses as shipping addresses.
            foreach (var orderAddress in order.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
            {
                var shippingAddress = new AddressModel();
                _addressBookService.MapToModel(orderAddress, shippingAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }
        protected OrderConfirmationViewModel <T> CreateViewModel(T currentPage, PurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <T> {
                    CurrentPage = currentPage
                });
            }

            var form = order.OrderForms.First();

            OrderConfirmationViewModel <T> viewModel = new OrderConfirmationViewModel <T>
            {
                CurrentPage             = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.TrackingNumber,
                Created                 = order.Created,
                Items                   = form.LineItems,
                BillingAddress          = new Address(),
                ShippingAddresses       = new List <Address>(),
                ContactId               = _customerContext.CurrentContactId,
                Payments                = form.Payments,
                GroupId                 = order.OrderGroupId,
                OrderLevelDiscountTotal = order.ToMoney(form.LineItems.Sum(x => x.OrderLevelDiscountAmount)),
                ShippingSubTotal        = order.ToMoney(form.Shipments.Sum(s => s.ShippingSubTotal)),
                ShippingDiscountTotal   = order.ToMoney(form.Shipments.Sum(s => s.ShippingDiscountAmount)),
                ShippingTotal           = order.ToMoney(form.ShippingTotal),
                HandlingTotal           = order.ToMoney(form.HandlingTotal),
                TaxTotal                = order.ToMoney(form.TaxTotal),
                CartTotal               = order.ToMoney(form.Total)
            };

            // Identify the id for all shipping addresses.
            IEnumerable <string> shippingAddressIdCollection = order.OrderForms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddressId);

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapOrderAddressToModel(viewModel.BillingAddress, order.OrderAddresses.Single(x => x.Name == form.BillingAddressId));

            // Map the remaining addresses as shipping addresses.
            foreach (OrderAddress orderAddress in order.OrderAddresses.Where(x => shippingAddressIdCollection.Contains(x.Name)))
            {
                ShippingAddress shippingAddress = new ShippingAddress();
                _addressBookService.MapOrderAddressToModel(shippingAddress, orderAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }
Ejemplo n.º 8
0
        public ActionResult OrderConfirmation([Bind(Prefix = ConfirmationIdQueryString)] string confirmationId)
        {
            var viewModel = new OrderConfirmationViewModel();

            if (!string.IsNullOrWhiteSpace(confirmationId))
            {
                var response = OrderManager.GetOrderDetails(CommerceUserContext.Current.UserId, confirmationId);
                if (response.ServiceProviderResult.Success)
                {
                    var order = response.Result;
                    viewModel.Initialize(RenderingContext.Current.Rendering, order.TrackingNumber, OrderManager.GetOrderStatusName(order.Status));
                }
            }

            return(View(viewModel));
        }
        public ActionResult OrderConfirmation([Bind(Prefix = StorefrontConstants.QueryStrings.ConfirmationId)] string confirmationId)
        {
            var           viewModel = new OrderConfirmationViewModel();
            CommerceOrder order     = null;

            if (!string.IsNullOrWhiteSpace(confirmationId))
            {
                var response = this.OrderManager.GetOrderDetails(this.CurrentStorefront, this.CurrentVisitorContext, confirmationId);
                if (response.ServiceProviderResult.Success)
                {
                    order = response.Result;
                }
            }

            viewModel.Initialize(this.CurrentRendering, confirmationId, order);

            return(View(this.CurrentRenderingView, viewModel));
        }
        public ActionResult Index(OrderConfirmationPage currentPage, string notificationMessage, Guid?contactId = null, int orderNumber = 0)
        {
            PurchaseOrder order = _confirmationService.GetOrder(orderNumber, PageEditing.PageIsInEditMode);

            if (order == null && !PageEditing.PageIsInEditMode)
            {
                return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
            }
            if (order.CustomerId != _customerContext.CurrentContactId && !PageEditing.PageIsInEditMode)
            {
                return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
            }

            OrderConfirmationViewModel <OrderConfirmationPage> viewModel = CreateViewModel(currentPage, order);

            viewModel.NotificationMessage = notificationMessage;

            return(View(viewModel));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Checkout(CheckoutViewModel model)
        {
            model.User = await _userManager.GetUserAsync(HttpContext.User);

            var vm = new OrderConfirmationViewModel
            {
                Address         = model.Address,
                ApartmentNumber = model.ApartmentNumber,
                Floor           = model.Floor,
                EntryCode       = model.EntryCode,
                DeliveryMethod  = model.DeliveryMethod,
                PaymentMethod   = model.PaymentMethod,
                Cart            = _cartService.GetCart()
            };

            if (ModelState.IsValid)
            {
                return(View("OrderConfirmation", vm));
            }
            return(View(model));
        }
        public ActionResult OrderConfirmation([Bind(Prefix = ConfirmationIdQueryString)] string confirmationId)
        {
            var viewModel = new OrderConfirmationViewModel();

            if (!string.IsNullOrWhiteSpace(confirmationId))
            {
                var order = this.Session["NewOrder"] as CommerceOrder;
                if (order == null)
                {
                    order = new CommerceOrder()
                    {
                        Status = Sitecore.Commerce.Connect.DynamicsRetail.Texts.Pending
                    };
                    viewModel.Initialize(RenderingContext.Current.Rendering, order.TrackingNumber, OrderManager.GetOrderStatusName(order.Status));
                }

                viewModel.Initialize(RenderingContext.Current.Rendering, confirmationId, order.Status);
            }

            return(View(viewModel));
        }
        public ActionResult Confirmation(int orderNumber)
        {
            var customer        = HttpContext.GetCustomer();
            var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer);
            var order           = new Order(orderNumber, customer.LocaleSetting);

            //Missing info
            if (customer.CustomerID == 0 || orderNumber == 0)
            {
                NoticeProvider.PushNotice(AppLogic.GetString("orderconfirmation.Invalid"), NoticeType.Failure);
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            //No such order
            if (order.IsEmpty)
            {
                NoticeProvider.PushNotice(AppLogic.GetString("orderconfirmation.aspx.19"), NoticeType.Failure);
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            //Wrong customer
            if (customer.CustomerID != order.CustomerID)
            {
                return(RedirectToAction(ActionNames.Detail, ControllerNames.Topic, new { @name = "ordernotfound" }));
            }

            if (customer.ThisCustomerSession["3DSecure.LookupResult"].Length > 0)
            {
                var sqlParams = new SqlParameter[]
                {
                    new SqlParameter("@LookupResult", customer.ThisCustomerSession["3DSecure.LookupResult"]),
                    new SqlParameter("@OrderNumber", orderNumber)
                };

                DB.ExecuteSQL("UPDATE Orders SET CardinalLookupResult = @LookupResult WHERE OrderNumber = @OrderNumber", sqlParams);
            }

            //Order cleanup
            if (!order.AlreadyConfirmed)
            {
                ViewBag.OrderAlreadyConfirmed = false;                 // Adding a variable to the viewbag so that xmlpackages can tell the order has not yet been confirmed
                var paymentMethod = AppLogic.CleanPaymentMethod(order.PaymentMethod);

                DB.ExecuteSQL("update Customer set OrderOptions=NULL, OrderNotes=NULL, FinalizationData=NULL where CustomerID=" + customer.CustomerID.ToString());

                //New order notification
                AppLogic.SendOrderEMail(customer, orderNumber, false, paymentMethod, true);

                //Low inventory notification
                if (AppLogic.AppConfigBool("SendLowStockWarnings") && order.TransactionIsCaptured())                //If delayed capture, we'll check this when the order is captured
                {
                    List <int> purchasedVariants = new List <int>();
                    foreach (CartItem ci in order.CartItems)
                    {
                        purchasedVariants.Add(ci.VariantID);
                    }

                    AppLogic.LowInventoryWarning(purchasedVariants);
                }

                //Handle impersonation
                var impersonationValue = customer.ThisCustomerSession[AppLogic.ImpersonationSessionKey];
                if (!string.IsNullOrEmpty(impersonationValue))
                {
                    int impersonatorId = 0;

                    if (int.TryParse(impersonationValue, out impersonatorId))
                    {
                        var impersonator           = new Customer(impersonatorId);
                        var impersonationSql       = "UPDATE Orders SET Notes = Notes + @ImpersonationNote WHERE OrderNumber = @OrderNumber";
                        var impersonationSqlParams = new SqlParameter[]
                        {
                            new SqlParameter("@OrderNumber", orderNumber),
                            new SqlParameter("@ImpersonationNote", string.Format(AppLogic.GetString("admin.order.ImpersonationNote"), impersonator.EMail))
                        };

                        DB.ExecuteSQL(impersonationSql, impersonationSqlParams);
                        customer.ThisCustomerSession.ClearVal(AppLogic.ImpersonationSessionKey);
                    }
                }

                //Braintree cleanup
                if (order.PaymentGateway == Gateway.ro_GWBRAINTREE)
                {
                    //Clear out some session values we don't need anymore
                    customer.ThisCustomerSession.ClearVal(AppLogic.Braintree3dSecureKey);
                    customer.ThisCustomerSession.ClearVal(AppLogic.BraintreeNonceKey);
                    customer.ThisCustomerSession.ClearVal(AppLogic.BraintreePaymentMethod);
                }

                //SagePayPi cleanup
                if (order.PaymentGateway == Gateway.ro_GWSAGEPAYPI)
                {
                    //Clear out some session values we don't need anymore
                    customer.ThisCustomerSession.ClearVal(AppLogic.SagePayPi3dSecureKey);
                    customer.ThisCustomerSession.ClearVal(AppLogic.SagePayPiCardIdentifier);
                    customer.ThisCustomerSession.ClearVal(AppLogic.SagePayPiPaymentMethod);
                }

                //Make sure we don't do this again
                DB.ExecuteSQL("UPDATE Orders SET AlreadyConfirmed = 1 WHERE OrderNumber = @OrderNumber", new SqlParameter[] { new SqlParameter("@OrderNumber", orderNumber) });
            }

            //Build the return model
            string googleTrackingCode = null;

            if (!order.AlreadyConfirmed && AppLogic.AppConfigBool("IncludeGoogleTrackingCode"))
            {
                googleTrackingCode = GetTrackingCodeTopicContents("GoogleTrackingCode", customer, orderNumber, order.Total());
            }

            string generalTrackingCode = null;

            if (!order.AlreadyConfirmed)
            {
                generalTrackingCode = GetTrackingCodeTopicContents("ConfirmationTracking", customer, orderNumber, order.Total());
            }

            var showGoogleCustomerReviews = AppLogic.AppConfigBool("GoogleCustomerReviewsEnabled") &&
                                            !order.AlreadyConfirmed &&
                                            !string.IsNullOrWhiteSpace(AppLogic.AppConfig("GoogleCustomerReviewsMerchantID"));

            var xmlPackage = AppLogic.AppConfig("XmlPackage.OrderConfirmationPage");

            if (string.IsNullOrEmpty(xmlPackage))
            {
                xmlPackage = "page.orderconfirmation.xml.config";
            }

            var body = AppLogic.RunXmlPackage(xmlPackage, new Parser(), customer, customer.SkinID, string.Empty, "OrderNumber=" + orderNumber.ToString(), true, true);

            var model = new OrderConfirmationViewModel(
                orderNumber: orderNumber,
                body: body,
                googleTrackingCode: googleTrackingCode,
                generalTrackingCode: generalTrackingCode,
                showGoogleTrackingCode: !string.IsNullOrWhiteSpace(googleTrackingCode),
                showGeneralTrackingCode: !string.IsNullOrWhiteSpace(generalTrackingCode),
                showGoogleCustomerReviews: showGoogleCustomerReviews,
                addPayPalExpressCheckoutScript: order.PaymentMethod == AppLogic.ro_PMPayPalExpress &&
                !order.AlreadyConfirmed,
                addBuySafeScript: AppLogic.GlobalConfigBool("BuySafe.Enabled") &&
                !string.IsNullOrEmpty(AppLogic.GlobalConfig("BuySafe.Hash")) &&
                !order.AlreadyConfirmed);

            //Get rid of old data - do this at the very end so we have all the info we need for order processing and building the model above
            ClearSensitiveOrderData(customer);

            if (!customer.IsRegistered || AppLogic.AppConfigBool("ForceSignoutOnOrderCompletion"))
            {
                ClearCustomerSession(customer);
            }

            return(View(model));
        }
Ejemplo n.º 14
0
        protected OrderConfirmationViewModel <T> CreateViewModel(T currentPage, IPurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <T>(currentPage));
            }

            var lineItems = order.GetFirstForm().Shipments.SelectMany(x => x.LineItems);
            var totals    = _orderGroupCalculator.GetOrderGroupTotals(order);

            var viewModel = new OrderConfirmationViewModel <T>(currentPage)
            {
                Currency                = order.Currency,
                CurrentContent          = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.OrderNumber,
                Created                 = order.Created,
                Items                   = lineItems,
                BillingAddress          = new AddressModel(),
                ShippingAddresses       = new List <AddressModel>(),
                ContactId               = PrincipalInfo.CurrentPrincipal.GetContactId(),
                Payments                = order.GetFirstForm().Payments.Where(c => c.TransactionType == TransactionType.Authorization.ToString() || c.TransactionType == TransactionType.Sale.ToString()),
                OrderGroupId            = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(),
                ShippingSubTotal        = order.GetShippingSubTotal(),
                ShippingDiscountTotal   = order.GetShippingDiscountTotal(),
                ShippingTotal           = totals.ShippingTotal,
                HandlingTotal           = totals.HandlingTotal,
                TaxTotal                = totals.TaxTotal,
                CartTotal               = totals.Total,
                SubTotal                = order.GetSubTotal(),
                FileUrls                = new List <Dictionary <string, string> >(),
                Keys = new List <Dictionary <string, string> >()
            };

            foreach (var lineItem in lineItems)
            {
                var entry   = lineItem.GetEntryContent <EntryContentBase>();
                var variant = entry as GenericVariant;
                if (entry == null || variant == null || variant.VirtualProductMode == null || variant.VirtualProductMode.Equals("None"))
                {
                    continue;
                }

                if (variant.VirtualProductMode.Equals("File"))
                {
                    var url = "";// _urlResolver.GetUrl(((FileVariant)lineItem.GetEntryContentBase()).File);
                    viewModel.FileUrls.Add(new Dictionary <string, string>()
                    {
                        { lineItem.DisplayName, url }
                    });
                }
                else if (variant.VirtualProductMode.Equals("Key"))
                {
                    var key = Guid.NewGuid().ToString();
                    viewModel.Keys.Add(new Dictionary <string, string>()
                    {
                        { lineItem.DisplayName, key }
                    });
                }
                else if (variant.VirtualProductMode.Equals("ElevatedRole"))
                {
                    viewModel.ElevatedRole = variant.VirtualProductRole;
                    var currentContact = _customerService.GetCurrentContact();
                    if (currentContact != null)
                    {
                        currentContact.ElevatedRole = ElevatedRoles.Reader.ToString();
                        currentContact.SaveChanges();
                    }
                }
            }

            var billingAddress = order.GetFirstForm().Payments.First().BillingAddress;

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapToModel(billingAddress, viewModel.BillingAddress);

            // Map the remaining addresses as shipping addresses.
            foreach (var orderAddress in order.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
            {
                var shippingAddress = new AddressModel();
                _addressBookService.MapToModel(orderAddress, shippingAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }