Exemplo n.º 1
0
        private void GetUserInfo(CheckoutApiModel result)
        {
            if (CommerceUserContext.Current == null)
            {
                return;
            }

            result.IsUserAuthenticated = Context.User.IsAuthenticated;
            result.UserEmail           = string.Empty;
            if (!Context.User.IsAuthenticated)
            {
                return;
            }

            result.UserEmail = CommerceUserContext.Current.Email;
            var addresses = new List <IParty>();
            var response  = AccountManager.GetCustomerParties(CommerceUserContext.Current.UserName);

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                addresses = response.Result.ToList();
            }

            var addressesResult = new AddressListApiModel();

            addressesResult.Initialize(addresses);
            result.UserAddresses = addressesResult;
            result.SetErrors(response.ServiceProviderResult);
        }
 private void InitShippingOptions(CheckoutViewModel model, CheckoutApiModel result)
 {
     model.ShippingOptions       = new Dictionary <string, string>();
     model.ShippingOptions["99"] = "Standard";
     model.ShippingOptions["26"] = "Standard overnight";
     model.ShippingOptions["21"] = "Next day air";
 }
        private void GetPaymentClientToken(CheckoutApiModel result)
        {
            //var response = PaymentManager.GetPaymentClientToken();
            //if (response.ServiceProviderResult.Success)
            //{
            //    result.PaymentClientToken = response.ServiceProviderResult.ClientToken;
            //}

            //result.SetErrors(response.ServiceProviderResult);
        }
Exemplo n.º 4
0
        public JsonResult GetCheckoutData()
        {
            try
            {
                var result   = new CheckoutApiModel();
                var response = CartManager.GetCart(CommerceUserContext.Current.UserId, true);
                if (response.ServiceProviderResult.Success && response.Result != null)
                {
                    var cart = (CommerceCart)response.ServiceProviderResult.Cart;
                    if (cart.Lines != null && cart.Lines.Any())
                    {
                        result.Cart = new CartApiModel(response.ServiceProviderResult);
                        result.Cart.Initialize(response.ServiceProviderResult.Cart);

                        result.ShippingMethods = new List <ShippingMethod>();

                        result.CurrencyCode = CurrencyManager.CurrencyContext.CurrencyCode;

                        AddShippingOptionsToResult(result, cart);
                        if (result.Success)
                        {
                            AddShippingMethodsToResult(result);
                            if (result.Success)
                            {
                                GetAvailableCountries(result);
                                if (result.Success)
                                {
                                    GetPaymentOptions(result);
                                    if (result.Success)
                                    {
                                        GetPaymentMethods(result);
                                        if (result.Success)
                                        {
                                            GetPaymentClientToken(result);
                                            if (result.Success)
                                            {
                                                GetUserInfo(result);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                result.SetErrors(response.ServiceProviderResult);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new ErrorApiModel("GetCheckoutData", e), JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 5
0
        private void GetAvailableCountries(CheckoutApiModel result)
        {
            var response  = CountryManager.GetAvailableCountries();
            var countries = new Dictionary <string, string>();

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                countries = response.Result;
            }

            result.Countries = countries;
            result.SetErrors(response.ServiceProviderResult);
        }
Exemplo n.º 6
0
        private void GetPaymentOptions(CheckoutApiModel result)
        {
            var response       = PaymentManager.GetPaymentOptions(CommerceUserContext.Current.UserId);
            var paymentOptions = new List <PaymentOption>();

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                paymentOptions = response.Result.ToList();
                paymentOptions.ForEach(x => x.Name = PaymentManager.GetPaymentName(x.Name));
            }

            result.PaymentOptions = paymentOptions;
            result.SetErrors(response.ServiceProviderResult);
        }
Exemplo n.º 7
0
        private void AddShippingOptionsToResult(CheckoutApiModel result, CommerceCart cart)
        {
            var response             = ShippingManager.GetShippingPreferences(cart);
            var orderShippingOptions = new List <ShippingOption>();
            var lineShippingOptions  = new List <LineShippingOption>();

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                orderShippingOptions = response.ServiceProviderResult.ShippingOptions.ToList();
                lineShippingOptions  = response.ServiceProviderResult.LineShippingPreferences.ToList();
            }

            result.InitializeShippingOptions(orderShippingOptions);
            result.InitializeLineItemShippingOptions(lineShippingOptions);

            result.SetErrors(response.ServiceProviderResult);
        }
Exemplo n.º 8
0
        private void GetPaymentMethods(CheckoutApiModel result)
        {
            var paymentMethodList = new List <PaymentMethod>();

            var response = PaymentManager.GetPaymentMethods(CommerceUserContext.Current.UserId, new PaymentOption {
                PaymentOptionType = PaymentOptionType.PayCard
            });

            if (response.ServiceProviderResult.Success)
            {
                paymentMethodList.AddRange(response.Result);
                paymentMethodList.ForEach(x => x.Description = PaymentManager.GetPaymentName(x.Description));
            }

            result.SetErrors(response.ServiceProviderResult);

            result.PaymentMethods = paymentMethodList;
        }
Exemplo n.º 9
0
        private void AddShippingMethodsToResult(CheckoutApiModel result)
        {
            var shippingMethodJsonResult = new ShippingMethodApiModel();

            var response = ShippingManager.GetShippingMethods(CommerceUserContext.Current.UserId, new GetShippingMethodsInputModel {
                ShippingPreferenceType = ShippingOptionType.None.Name
            });

            if (response.ServiceProviderResult.Success && response.Result.Count > 0)
            {
                shippingMethodJsonResult.Initialize(response.Result.ElementAt(0));
                result.EmailDeliveryMethod = shippingMethodJsonResult;
                return;
            }

            var shippingToStoreJsonResult = new ShippingMethodApiModel();

            //   result.EmailDeliveryMethod = shippingMethodJsonResult;
            //  result.ShipToStoreDeliveryMethod = shippingToStoreJsonResult;
            result.SetErrors(response.ServiceProviderResult);
        }
        private CheckoutViewModel CreateViewModel()
        {
            var model = new CheckoutViewModel();

            var cartResponse = CartManager.GetCart(CommerceUserContext.Current.UserId, true);

            model.Cart = cartResponse.ServiceProviderResult.Cart as CommerceCart;

            var checkoutApiModel = new CheckoutApiModel(cartResponse.ServiceProviderResult);

            checkoutApiModel.Cart = new CartApiModel();
            checkoutApiModel.Cart.Initialize(cartResponse.ServiceProviderResult.Cart);

            InitPaymentUrl(model);
            InitCountriesRegions(model);
            InitShippingOptions(model, checkoutApiModel);

            InitLineShippingOptions(model);
            //InitLineHrefs(model);
            InitLineImgSrcs(model);
            InitPaymentClientToken(model);

            return(model);
        }