private static string ReplaceValuesInTemplate(string template, CheckoutState checkoutSate, CartOrder cartOrder)
 {
     var order = OrdersManager.GetManager().GetOrder(cartOrder.Id);
     if (order != null)
     {
         var orderConfirmationEmailTemplateFormatter = new OrderConfirmationEmailTemplateFormatter();
         return orderConfirmationEmailTemplateFormatter.ReplaceValuesInTemplate(template, checkoutSate, order);
     }
     return string.Empty;
 }
        internal static void SendOrderPlacedEmailToClientAndMerchant(CartOrder cartOrder, CheckoutState checkoutState,int orderNumber)
        {
            var messageBody = GetEmailMessageBody(cartOrder, checkoutState);
            if (string.IsNullOrEmpty(messageBody))
            {
                return;
            }

            string fromAddress = Config.Get<EcommerceConfig>().MerchantEmail;
            string subject = String.Format(Res.Get<OrdersResources>("OrderEmailSubject"), orderNumber);
            SendEmail(fromAddress, checkoutState.BillingEmail, subject, messageBody, true);
        }
        private static string GetEmailMessageBody(CartOrder cartOrder, CheckoutState checkoutSate)
        {
            Guid templateId = new Guid("f949cccb-c337-4d0e-ad1e-f35a466b01e8");
            ControlPresentation emailTemplate;

            using (var pageManager = PageManager.GetManager())
            {
                IQueryable<ControlPresentation> controlPresentations = pageManager.GetPresentationItems<ControlPresentation>();

                emailTemplate = controlPresentations.Where(tmpl => tmpl.Id == templateId).SingleOrDefault();
            }

            return emailTemplate != null ? ReplaceValuesInTemplate(emailTemplate.Data, checkoutSate, cartOrder) : "";
        }
        internal static CartPayment GetCartPaymentFromCheckoutState(OrdersManager ordersManager, CheckoutState checkoutState)
        {
            CartPayment payment = ordersManager.CreateCartPayment();
            payment.CreditCardCustomerName = checkoutState.CreditCardInfo.CreditCardCardholderName;
            payment.CreditCardExpireMonth = Convert.ToInt32(checkoutState.CreditCardInfo.CreditCardExpirationMonth);
            payment.CreditCardExpireYear = Convert.ToInt32(checkoutState.CreditCardInfo.CreditCardExpirationYear);
            payment.CreditCardNumberLastFour = string.Empty;
            payment.CreditCardNumber = string.Empty;
            payment.CreditCardType = checkoutState.CreditCardInfo.CreditCardType;

            payment.PaymentMethodId = checkoutState.PaymentMethodId;
            payment.PaymentMethodType = checkoutState.PaymentMethodType;

            return payment;
        }
        internal static void SendOrderPlacedEmailToClientAndMerchant(CartOrder cartOrder, CheckoutState checkoutState,int orderNumber)
        {
            var messageBody = GetEmailMessageBody(cartOrder, checkoutState);
            if (string.IsNullOrEmpty(messageBody))
            {
                //JMABase.WriteLogFile("Cannot send an email because there is no message body", "/ecommercelog.txt");
                return;
            }

            //JMABase.WriteLogFile("Message Body for email: " + messageBody, "/ecommercelog.txt");

            string fromAddress = Config.Get<EcommerceConfig>().MerchantEmail;
            string subject = String.Format(Res.Get<OrdersResources>("OrderEmailSubject"), orderNumber);
            SendEmail(fromAddress, checkoutState.BillingEmail, subject, messageBody, true);
        }
        public static CheckoutState GetCheckoutState(this HttpContextBase httpContext)
        {
            Guard.ArgumentNotNull(() => httpContext);

            var state = httpContext.Session.SafeGetValue <CheckoutState>(CheckoutState.CheckoutStateSessionKey);

            if (state != null)
            {
                return(state);
            }

            state = new CheckoutState();
            httpContext.Session.SafeSet(CheckoutState.CheckoutStateSessionKey, state);

            return(state);
        }
        internal static CartAddress GetBillingAddressFromCheckoutState(OrdersManager ordersManager, CheckoutState checkoutState)
        {
            CartAddress billingAddress = ordersManager.CreateCartAddress();
            billingAddress.FirstName = checkoutState.BillingFirstName;
            billingAddress.LastName = checkoutState.BillingLastName;
            billingAddress.Email = checkoutState.BillingEmail;
            billingAddress.Address = checkoutState.BillingAddress1;
            billingAddress.Address2 = checkoutState.BillingAddress2;
            billingAddress.AddressType = AddressType.Billing;
            billingAddress.City = checkoutState.BillingCity;
            billingAddress.PostalCode = checkoutState.BillingZip;
            billingAddress.StateRegion = checkoutState.BillingState;
            billingAddress.Country = checkoutState.BillingCountry;
            billingAddress.Phone = checkoutState.BillingPhoneNumber;
            billingAddress.Email = checkoutState.BillingEmail;
            billingAddress.Company = checkoutState.BillingCompany;

            return billingAddress;
        }
 public MyPagesViewModelService(
     SecurityContextService securityContextService,
     PersonService personService,
     AuthenticationService authenticationService,
     UserValidationService userValidationService,
     AddressTypeService addressTypeService,
     CountryService countryService,
     RequestModelAccessor requestModelAccessor,
     CheckoutState checkoutState)
 {
     _securityContextService = securityContextService;
     _personService          = personService;
     _authenticationService  = authenticationService;
     _userValidationService  = userValidationService;
     _addressTypeService     = addressTypeService;
     _checkoutState          = checkoutState;
     _countryService         = countryService;
     _requestModelAccessor   = requestModelAccessor;
 }
        internal static Customer GetCustomerInfoOrCreateOneIfDoesntExsist(UserProfileManager userProfileManager, OrdersManager ordersManager, CheckoutState checkoutState)
        {
            var customerRetriever = new CustomerRetriever(ordersManager, userProfileManager);

            User customerUser = null;
            Customer customer = null;

            Guid userId = SecurityManager.CurrentUserId;
            if (userId != Guid.Empty)
            {
                customerUser = SecurityManager.GetUser(userId);
                if (customerUser != null)
                {

                    customer = customerRetriever.GetCustomer(customerUser, checkoutState);
                }
            }

            return customer;
        }
Beispiel #10
0
 public LoginServiceImpl(
     AuthenticationService authenticationService,
     SecurityContextService securityContextService,
     PersonService personService,
     OrganizationService organizationService,
     RoleService roleService,
     MailService mailService,
     UserValidationService userValidationService,
     PersonStorage personStorage,
     CheckoutState checkoutState)
 {
     _authenticationService  = authenticationService;
     _securityContextService = securityContextService;
     _personService          = personService;
     _organizationService    = organizationService;
     _roleService            = roleService;
     _mailService            = mailService;
     _userValidationService  = userValidationService;
     _personStorage          = personStorage;
     _checkoutState          = checkoutState;
 }
Beispiel #11
0
        public static CheckoutState UpdateCheckoutState(Customer customer, OrdersManager ordersManager, CartOrder cartOrder)
        {
            CheckoutState   state           = new CheckoutState();
            ShippingManager shippingManager = ShippingManager.GetManager();

            var shippingMethod = shippingManager.GetShippingMethods().FirstOrDefault();

            state.ShippingMethodId     = shippingMethod.Id;
            state.ShippingServiceName  = shippingMethod.Name;
            cartOrder.ShippingMethodId = state.ShippingMethodId;

            state.ShippingFirstName   = customer.CustomerFirstName;
            state.ShippingLastName    = customer.CustomerLastName;
            state.ShippingCompany     = MockCompany;
            state.ShippingEmail       = customer.CustomerEmail;
            state.ShippingAddress1    = MockAdressOne;
            state.ShippingAddress2    = MockAdressTwo;
            state.ShippingCity        = MockCity;
            state.ShippingCountry     = MockCountry;
            state.ShippingCountryName = MockCountry;
            state.ShippingZip         = MockZip;
            state.ShippingPhoneNumber = MockPhone;
            state.BillingFirstName    = customer.CustomerFirstName;
            state.BillingLastName     = customer.CustomerLastName;
            state.BillingCompany      = MockCompany;
            state.BillingEmail        = customer.CustomerEmail;
            state.BillingAddress1     = MockAdressOne;
            state.BillingAddress2     = MockAdressTwo;
            state.BillingCity         = MockCity;
            state.BillingCountry      = MockCountry;
            state.BillingCountryName  = MockCountry;
            state.BillingZip          = MockZip;
            state.BillingPhoneNumber  = MockPhone;

            state.OrderRequiresShipping = true;

            UpdateCartDetails(state, ordersManager, customer, cartOrder);

            return(state);
        }
        public CheckoutState Apply(CheckoutState checkoutState)
        {
            var applicableItems = GetApplicableItems(checkoutState).ToArray();

            if (!applicableItems.Any())
            {
                return(ToNotAppliedCheckoutState(checkoutState, GetNoApplicableProductsMessage()));
            }

            var leftToSpend = AmountRequiredToPassThreshold(checkoutState.DiscountableItemsTotal);

            if (leftToSpend > 0)
            {
                return(ToNotAppliedCheckoutState(checkoutState, GetThresholdNotReachedMessage(leftToSpend)));
            }

            var currentSpendOnApplicableItems = CurrentSpendOnApplicableItems(applicableItems);
            var discountToApply = CalculateDiscountToApply(currentSpendOnApplicableItems);
            var newStateTotal   = checkoutState.CurrentTotal - discountToApply;

            return(checkoutState.ToNewState(newStateTotal, DiscountResult.CreateApplied(_id)));
        }
 public CheckoutServiceImpl(
     ModuleECommerce moduleECommerce,
     RequestModelAccessor requestModelAccessor,
     CartService cartService,
     IPaymentInfoFactory paymentInfoFactory,
     LanguageService languageService,
     UserValidationService userValidationService,
     SecurityContextService securityContextService,
     PersonService personService,
     LoginService loginService,
     MailService mailService,
     WelcomeEmailDefinitionResolver welcomeEmailDefinitionResolver,
     FieldTemplateService templateService,
     WebsiteService websiteService,
     AddressTypeService addressTypeService,
     UrlService urlService,
     PageService pageService,
     PersonStorage personStorage,
     CheckoutState checkoutState)
 {
     _moduleECommerce                = moduleECommerce;
     _requestModelAccessor           = requestModelAccessor;
     _cartService                    = cartService;
     _paymentInfoFactory             = paymentInfoFactory;
     _languageService                = languageService;
     _userValidationService          = userValidationService;
     _securityContextService         = securityContextService;
     _personService                  = personService;
     _loginService                   = loginService;
     _mailService                    = mailService;
     _welcomeEmailDefinitionResolver = welcomeEmailDefinitionResolver;
     _templateService                = templateService;
     _addressTypeService             = addressTypeService;
     _websiteService                 = websiteService;
     _pageService                    = pageService;
     _personStorage                  = personStorage;
     _checkoutState                  = checkoutState;
     _urlService = urlService;
 }
Beispiel #14
0
        CheckoutAction GetActionForState(CheckoutState state)
        {
            switch (state)
            {
            case CheckoutState.SubtotalDoesNotMeetMinimumAmount:
            case CheckoutState.CartItemsLessThanMinimumItemCount:
            case CheckoutState.CartItemsGreaterThanMaximumItemCount:
            case CheckoutState.RecurringScheduleMismatchOnItems:
            case CheckoutState.ShippingAddressDoesNotMatchBillingAddress:
            case CheckoutState.MicroPayBalanceIsInsufficient:
            case CheckoutState.CustomerIsNotOver13:
            case CheckoutState.TermsAndConditionsRequired:
                return(CheckoutAction.Error);

            case CheckoutState.ShoppingCartIsEmpty:
                return(CheckoutAction.Empty);

            case CheckoutState.Valid:
                return(CheckoutAction.Complete);

            default:
                return(CheckoutAction.None);
            }
        }
Beispiel #15
0
 public static TransitionBuilder <CheckoutState> TransitionTo(this TransitionBuilder <Guard> builder, CheckoutState target)
 {
     return(new TransitionBuilder <CheckoutState>(
                target: target,
                guards: builder.Guards));
 }
        internal static void SendOrderPlacedEmailToClientAndMerchant(CartOrder cartOrder, CheckoutState checkoutState, int orderNumber)
        {
            var messageBody = GetEmailMessageBody(cartOrder, checkoutState);

            if (string.IsNullOrEmpty(messageBody))
            {
                return;
            }

            string fromAddress = Config.Get <EcommerceConfig>().MerchantEmail;
            string subject     = String.Format(Res.Get <OrdersResources>("OrderEmailSubject"), orderNumber);

            SendEmail(fromAddress, checkoutState.BillingEmail, subject, messageBody, true);
        }
Beispiel #17
0
        private CheckoutState GetCheckoutState()
        {
            CheckoutState checkoutState = new CheckoutState();

            checkoutState.BillingFirstName   = FirstNameBilling.Value.ToString();
            checkoutState.BillingLastName    = LastNameBilling.Value.ToString();
            checkoutState.BillingAddress1    = Address1Billing.Value.ToString();
            checkoutState.BillingAddress2    = Address2Billing.Value.ToString();
            checkoutState.BillingCity        = CityBilling.Value.ToString();
            checkoutState.BillingCountry     = CountryBilling.SelectedValue.ToString();
            checkoutState.BillingState       = StateBilling.SelectedValue.ToString();
            checkoutState.BillingZip         = ZipBilling.Value.ToString();
            checkoutState.BillingPhoneNumber = PhoneNumberBilling.Value.ToString();
            checkoutState.BillingCompany     = CompanyBilling.Value.ToString();
            checkoutState.BillingEmail       = EmailBilling.Value.ToString();



            if (UseBillingAddressAsShippingAddress != null && !UseBillingAddressAsShippingAddress.Checked)
            {
                checkoutState.ShippingFirstName   = FirstNameShipping.Value.ToString();
                checkoutState.ShippingLastName    = LastNameShipping.Value.ToString();
                checkoutState.ShippingAddress1    = Address1Shipping.Value.ToString();
                checkoutState.ShippingAddress2    = Util.GetSafeString(Address2Shipping.Value);
                checkoutState.ShippingCity        = CityShipping.Value.ToString();
                checkoutState.ShippingCountry     = CountryShipping.SelectedValue.ToString();
                checkoutState.ShippingState       = StateShipping.SelectedValue.ToString();
                checkoutState.ShippingZip         = ZipShipping.Value.ToString();
                checkoutState.ShippingPhoneNumber = Util.GetSafeString(PhoneNumberShipping.Value);
                checkoutState.ShippingCompany     = Util.GetSafeString(CompanyShipping.Value);
                checkoutState.ShippingEmail       = EmailShipping.Value.ToString();
            }
            else
            {
                checkoutState.ShippingFirstName   = FirstNameBilling.Value.ToString();
                checkoutState.ShippingLastName    = LastNameBilling.Value.ToString();
                checkoutState.ShippingAddress1    = Address1Billing.Value.ToString();
                checkoutState.ShippingAddress2    = Util.GetSafeString(Address2Billing.Value);
                checkoutState.ShippingCity        = CityBilling.Value.ToString();
                checkoutState.ShippingCountry     = CountryBilling.SelectedValue.ToString();
                checkoutState.ShippingState       = StateBilling.SelectedValue.ToString();
                checkoutState.ShippingZip         = ZipBilling.Value.ToString();
                checkoutState.ShippingPhoneNumber = Util.GetSafeString(PhoneNumberBilling.Value);
                checkoutState.ShippingCompany     = Util.GetSafeString(CompanyBilling.Value);
                checkoutState.ShippingEmail       = EmailBilling.Value.ToString();
            }


            checkoutState.CreditCardInfo = new CreditCardInfo();
            checkoutState.CreditCardInfo.CreditCardNumber          = CreditCardNumber.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardCardholderName  = CardHolderName.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardExpirationMonth = Convert.ToInt32(CardExpirationMonth.Value.ToString());
            checkoutState.CreditCardInfo.CreditCardExpirationYear  = Convert.ToInt32(CardExpirationYear.Value.ToString());
            checkoutState.CreditCardInfo.CreditCardSecurityCode    = SecurityCode.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardType            = CreditCardType.Visa; //for now

            //get the first payment. The example doesn't support the case with multiple payment methods.
            PaymentMethod paymentMethod = this.OrdersManager.GetPaymentMethods().Where(pm => pm.IsActive && pm.PaymentMethodType == PaymentMethodType.PaymentProcessor).First();

            if (paymentMethod == null)
            {
                throw new ArgumentException("Please configure a payment method");
            }

            checkoutState.PaymentMethodId = paymentMethod.Id;
            //since Sitefinity 6.2 you need to populate also this properties :
            checkoutState.GatewayNotificationUrl   = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/Ecommerce/offsite-payment-notification/";
            checkoutState.GatewayRedirectCancelUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/PathToYourCheckoutWidgetPageOrOtherPageWhenCancel";
            string landingUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/PathToConfirmationPageSayingSuccessful e.g. the same page you redirecting to in case of direct payment in place clicked handler";

            checkoutState.GatewayRedirectSuccessUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/Ecommerce/offsite-payment-return/?landingUrl=" + HttpContext.Current.Server.UrlEncode(Compress(landingUrl));

            return(checkoutState);
        }
        internal static Tuple<bool, IPaymentResponse> PlaceOrder(OrdersManager ordersManager, CatalogManager catalogManager, UserManager userManager, RoleManager roleManager, UserProfileManager userProfileManager, CheckoutState checkoutState, Guid cartOrderId)
        {
            CartOrder cartOrder = ordersManager.GetCartOrder(cartOrderId);
            cartOrder.Addresses.Clear();
            cartOrder.Payments.Clear();

            //set the default currency of the order
            string defaultCurrency = Config.Get<EcommerceConfig>().DefaultCurrency;
            cartOrder.Currency = defaultCurrency;

            // set the shipping address
            CartAddress shippingAddress = CartHelper.GetShippingAddressFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Addresses.Add(shippingAddress);

            // set the billing address
            CartAddress billingAddress = CartHelper.GetBillingAddressFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Addresses.Add(billingAddress);

            //Get the first payment method in the shop

            // set the payment
            CartPayment payment = CartHelper.GetCartPaymentFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Payments.Add(payment);

            ordersManager.SaveChanges();

            // Get current customer or create new one

            Customer customer = UserProfileHelper.GetCustomerInfoOrCreateOneIfDoesntExsist(userProfileManager,ordersManager, checkoutState);

            // Save the customer address
            CustomerAddressHelper.SaveCustomerAddressOfCurrentUser(checkoutState, customer);

            //Use the API to checkout
            IPaymentResponse paymentResponse = ordersManager.Checkout(cartOrderId, checkoutState, customer);

            // record the "success" state of the checkout
            checkoutState.IsPaymentSuccessful = paymentResponse.IsSuccess;

            Order order = ordersManager.GetOrder(cartOrderId);

            //Increment the order
            IncrementOrderNumber(ordersManager, order);

            // add the order to customer
            customer.Orders.Add(order);

            // Update the order
            order.Customer = customer;

            ordersManager.SaveChanges();

            if (!paymentResponse.IsSuccess)
            {
                return new Tuple<bool, IPaymentResponse>(false, paymentResponse);
            }

            if (order.OrderStatus == OrderStatus.Paid)
            {
                UserProfileHelper.AssignCustomerToRoles(userManager, roleManager, catalogManager, SecurityManager.GetCurrentUserId(), order);
                EmailHelper.SendOrderPlacedEmailToClientAndMerchant(cartOrder, checkoutState, order.OrderNumber);
            }

            return new Tuple<bool, IPaymentResponse>(true, paymentResponse);
        }
        private CheckoutState GetCheckoutState()
        {
            CheckoutState checkoutState = new CheckoutState();

            checkoutState.BillingFirstName = FirstNameBilling.Value.ToString();
            checkoutState.BillingLastName = LastNameBilling.Value.ToString();
            checkoutState.BillingAddress1 = Address1Billing.Value.ToString();
            checkoutState.BillingAddress2 = Address2Billing.Value.ToString();
            checkoutState.BillingCity = CityBilling.Value.ToString();
            checkoutState.BillingCountry = CountryBilling.SelectedValue.ToString();
            checkoutState.BillingState = StateBilling.SelectedValue.ToString();
            checkoutState.BillingZip = ZipBilling.Value.ToString();
            checkoutState.BillingPhoneNumber = PhoneNumberBilling.Value.ToString();
            checkoutState.BillingCompany = CompanyBilling.Value.ToString();
            checkoutState.BillingEmail = EmailBilling.Value.ToString();

            if (UseBillingAddressAsShippingAddress != null && !UseBillingAddressAsShippingAddress.Checked)
            {
                checkoutState.ShippingFirstName = FirstNameShipping.Value.ToString();
                checkoutState.ShippingLastName = LastNameShipping.Value.ToString();
                checkoutState.ShippingAddress1 = Address1Shipping.Value.ToString();
                checkoutState.ShippingAddress2 = Util.GetSafeString(Address2Shipping.Value);
                checkoutState.ShippingCity = CityShipping.Value.ToString();
                checkoutState.ShippingCountry = CountryShipping.SelectedValue.ToString();
                checkoutState.ShippingState = StateShipping.SelectedValue.ToString();
                checkoutState.ShippingZip = ZipShipping.Value.ToString();
                checkoutState.ShippingPhoneNumber = Util.GetSafeString(PhoneNumberShipping.Value);
                checkoutState.ShippingCompany = Util.GetSafeString(CompanyShipping.Value);
                checkoutState.ShippingEmail = EmailShipping.Value.ToString();
            }
            else
            {
                checkoutState.ShippingFirstName = FirstNameBilling.Value.ToString();
                checkoutState.ShippingLastName = LastNameBilling.Value.ToString();
                checkoutState.ShippingAddress1 = Address1Billing.Value.ToString();
                checkoutState.ShippingAddress2 = Util.GetSafeString(Address2Billing.Value);
                checkoutState.ShippingCity = CityBilling.Value.ToString();
                checkoutState.ShippingCountry = CountryBilling.SelectedValue.ToString();
                checkoutState.ShippingState = StateBilling.SelectedValue.ToString();
                checkoutState.ShippingZip = ZipBilling.Value.ToString();
                checkoutState.ShippingPhoneNumber = Util.GetSafeString(PhoneNumberBilling.Value);
                checkoutState.ShippingCompany = Util.GetSafeString(CompanyBilling.Value);
                checkoutState.ShippingEmail = EmailBilling.Value.ToString();
            }

            checkoutState.CreditCardInfo = new CreditCardInfo();
            checkoutState.CreditCardInfo.CreditCardNumber = CreditCardNumber.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardCardholderName = CardHolderName.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardExpirationMonth = Convert.ToInt32(CardExpirationMonth.Value.ToString());
            checkoutState.CreditCardInfo.CreditCardExpirationYear = Convert.ToInt32(CardExpirationYear.Value.ToString());
            checkoutState.CreditCardInfo.CreditCardSecurityCode = SecurityCode.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardType = CreditCardType.Visa; //for now

            //get the first payment. The example doesn't support the case with multiple payment methods.
            PaymentMethod paymentMethod = this.OrdersManager.GetPaymentMethods().Where(pm => pm.IsActive && pm.PaymentMethodType == PaymentMethodType.PaymentProcessor).First();
            if (paymentMethod == null)
            {
                throw new ArgumentException("Please configure a payment method");
            }

            checkoutState.PaymentMethodId = paymentMethod.Id;
            //since Sitefinity 6.2 you need to populate also this properties :
            checkoutState.GatewayNotificationUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/Ecommerce/offsite-payment-notification/";
            checkoutState.GatewayRedirectCancelUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/PathToYourCheckoutWidgetPageOrOtherPageWhenCancel";
            string landingUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/PathToConfirmationPageSayingSuccessful e.g. the same page you redirecting to in case of direct payment in place clicked handler";
            checkoutState.GatewayRedirectSuccessUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/Ecommerce/offsite-payment-return/?landingUrl=" + HttpContext.Current.Server.UrlEncode(Compress(landingUrl));

            return checkoutState;
        }
 private static CheckoutState CheckoutStateWith(params BasketItem[] basketItems)
 {
     return(CheckoutState.Initialise(basketItems));
 }
Beispiel #21
0
        internal static IPaymentResponse PlaceOrder(OrdersManager ordersManager, CatalogManager catalogManager, UserManager userManager, RoleManager roleManager, UserProfileManager userProfileManager, CheckoutState checkoutState, Guid cartOrderId)
        {
            CartOrder cartOrder = ordersManager.GetCartOrder(cartOrderId);

            cartOrder.Addresses.Clear();
            cartOrder.Payments.Clear();

            //set the default currency of the order
            string defaultCurrency = Config.Get <EcommerceConfig>().DefaultCurrency;

            cartOrder.Currency = defaultCurrency;

            // set the shipping address
            CartAddress shippingAddress = CartHelper.GetShippingAddressFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Addresses.Add(shippingAddress);

            // set the billing address
            CartAddress billingAddress = CartHelper.GetBillingAddressFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Addresses.Add(billingAddress);

            //Get the first payment method in the shop

            // set the payment
            CartPayment payment = CartHelper.GetCartPaymentFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Payments.Add(payment);

            ordersManager.SaveChanges();


            // Get current customer or create new one

            Customer customer = UserProfileHelper.GetCustomerInfoOrCreateOneIfDoesntExsist(userProfileManager, ordersManager, checkoutState);

            // Save the customer address
            CustomerAddressHelper.SaveCustomerAddressOfCurrentUser(checkoutState, customer);

            //Use the API to checkout
            IPaymentResponse paymentResponse = ordersManager.Checkout(cartOrderId, checkoutState, customer);

            // record the "success" state of the checkout
            checkoutState.IsPaymentSuccessful = paymentResponse.IsSuccess;

            Order order = ordersManager.GetOrder(cartOrderId);

            //Increment the order
            IncrementOrderNumber(ordersManager, order);

            // add the order to customer
            customer.Orders.Add(order);

            // Update the order
            order.Customer = customer;

            ordersManager.SaveChanges();

            if (order.OrderStatus == OrderStatus.Paid)
            {
                UserProfileHelper.AssignCustomerToRoles(userManager, roleManager, catalogManager, SecurityManager.GetCurrentUserId(), order);
                EmailHelper.SendOrderPlacedEmailToClientAndMerchant(cartOrder, checkoutState, order.OrderNumber);
            }

            return(paymentResponse);
        }
 internal static void SaveCustomerAddressOfCurrentUser(CheckoutState checkoutState, Customer customer)
 {
     checkoutState.SaveCustomerAddress(UserProfileHelper.GetCurrentlyLoggedInUser(), customer);
 }
        private CheckoutState ToNotAppliedCheckoutState(CheckoutState checkoutState, string message)
        {
            var notAppliedResult = DiscountResult.CreateNotApplied(_id, message);

            return(checkoutState.ToNewState(checkoutState.CurrentTotal, notAppliedResult));
        }
        internal static CartPayment GetCartPaymentFromCheckoutState(OrdersManager ordersManager, CheckoutState checkoutState)
        {
            CartPayment payment = ordersManager.CreateCartPayment();

            payment.CreditCardCustomerName   = checkoutState.CreditCardInfo.CreditCardCardholderName;
            payment.CreditCardExpireMonth    = Convert.ToInt32(checkoutState.CreditCardInfo.CreditCardExpirationMonth);
            payment.CreditCardExpireYear     = Convert.ToInt32(checkoutState.CreditCardInfo.CreditCardExpirationYear);
            payment.CreditCardNumberLastFour = string.Empty;
            payment.CreditCardNumber         = string.Empty;
            payment.CreditCardType           = checkoutState.CreditCardInfo.CreditCardType;

            payment.PaymentMethodId   = checkoutState.PaymentMethodId;
            payment.PaymentMethodType = checkoutState.PaymentMethodType;

            return(payment);
        }
Beispiel #25
0
        private CheckoutState ToNotAppliedState(CheckoutState checkoutState)
        {
            var notAppliedResult = DiscountResult.CreateNotApplied(_id, GetNotAppliedMessage());

            return(checkoutState.ToNewState(checkoutState.CurrentTotal, notAppliedResult));
        }
Beispiel #26
0
        internal static Customer GetCustomerInfoOrCreateOneIfDoesntExsist(UserProfileManager userProfileManager, OrdersManager ordersManager, CheckoutState checkoutState)
        {
            var customerRetriever = new CustomerRetriever(ordersManager, userProfileManager);

            User     customerUser = null;
            Customer customer     = null;

            Guid userId = SecurityManager.CurrentUserId;

            if (userId != Guid.Empty)
            {
                customerUser = SecurityManager.GetUser(userId);
                if (customerUser != null)
                {
                    customer = customerRetriever.GetCustomer(customerUser, checkoutState);
                }
            }

            return(customer);
        }
 internal static void SaveCustomerAddressOfCurrentUser(CheckoutState checkoutState, Customer customer)
 {
     checkoutState.SaveCustomerAddress(UserProfileHelper.GetCurrentlyLoggedInUser(), customer);
 }
        public void StoreCheckout([FromBody] CheckoutState data)
        {
            var res = JsonConvert.SerializeObject(data);

            _session.HttpContext.Items["checkout"] = res;//HttpContext.Session.SetString("checkout", res);
        }
Beispiel #29
0
        public static PayPalSessionData GetPayPalSessionData(this HttpContextBase httpContext, CheckoutState state = null)
        {
            if (state == null)
            {
                state = httpContext.GetCheckoutState();
            }

            if (!state.CustomProperties.ContainsKey(PayPalPlusProvider.SystemName))
            {
                state.CustomProperties.Add(PayPalPlusProvider.SystemName, new PayPalSessionData());
            }

            return(state.CustomProperties.Get(PayPalPlusProvider.SystemName) as PayPalSessionData);
        }
Beispiel #30
0
 public MyStateBase()
 {
     Basket   = new List <BasketItem>();
     Checkout = new CheckoutState();
 }
Beispiel #31
0
    public void NextDialogue()
    {
        switch (currentState)
        {
        case CheckoutState.Greeting:
        {
            message.text = customerInfo.progressMessage;
            int i = 0;         // variable for counting in loops
            foreach (string response in customerInfo.progressResponses)
            {
                responseText[i].text = response;
                i++;
            }
            currentState = CheckoutState.Chat;
            break;
        }

        case CheckoutState.Chat:
        {
            message.text = customerInfo.goodbyeMessage;
            int i = 0;         // variable for counting in loops
            foreach (string response in customerInfo.goodbyeResponses)
            {
                responseText[i].text = response;
                i++;
            }
            currentState = CheckoutState.Goodbye;
            break;
        }

        case CheckoutState.Goodbye:
        {
            dialogueBox.SetActive(false);
            foreach (GameObject button in responseButtons)
            {
                button.SetActive(false);
            }
            currentState     = CheckoutState.Finished;
            dialogueFinished = true;
            FinishCheckout();
            break;
        }

        case CheckoutState.Angry:
        {
            dialogueBox.SetActive(false);
            foreach (GameObject button in responseButtons)
            {
                button.SetActive(false);
            }
            currentState     = CheckoutState.Finished;
            dialogueFinished = true;
            FinishCheckout();
            break;
        }

        default:
        {
            Debug.Log("Uh oh");
            break;
        }
        }

        //clean up later
    }
        private CheckoutState GetCheckoutState()
        {
            CheckoutState checkoutState = new CheckoutState();

            checkoutState.BillingFirstName = FirstNameBilling.Value.ToString();
            checkoutState.BillingLastName = LastNameBilling.Value.ToString();
            checkoutState.BillingAddress1 = Address1Billing.Value.ToString();
            checkoutState.BillingAddress2 = Address2Billing.Value.ToString();
            checkoutState.BillingCity = CityBilling.Value.ToString();
            checkoutState.BillingCountry = CountryBilling.SelectedValue.ToString();
            checkoutState.BillingState = StateBilling.SelectedValue.ToString();
            checkoutState.BillingZip = ZipBilling.Value.ToString();
            checkoutState.BillingPhoneNumber = PhoneNumberBilling.Value.ToString();
            checkoutState.BillingCompany = CompanyBilling.Value.ToString();
            checkoutState.BillingEmail = EmailBilling.Value.ToString();

            if (UseBillingAddressAsShippingAddress != null && !UseBillingAddressAsShippingAddress.Checked)
            {
                checkoutState.ShippingFirstName = FirstNameShipping.Value.ToString();
                checkoutState.ShippingLastName = LastNameShipping.Value.ToString();
                checkoutState.ShippingAddress1 = Address1Shipping.Value.ToString();
                checkoutState.ShippingAddress2 = Util.GetSafeString(Address2Shipping.Value);
                checkoutState.ShippingCity = CityShipping.Value.ToString();
                checkoutState.ShippingCountry = CountryShipping.SelectedValue.ToString();
                checkoutState.ShippingState = StateShipping.SelectedValue.ToString();
                checkoutState.ShippingZip = ZipShipping.Value.ToString();
                checkoutState.ShippingPhoneNumber = Util.GetSafeString(PhoneNumberShipping.Value);
                checkoutState.ShippingCompany = Util.GetSafeString(CompanyShipping.Value);
                checkoutState.ShippingEmail = EmailShipping.Value.ToString();
            }
            else
            {
                checkoutState.ShippingFirstName = FirstNameBilling.Value.ToString();
                checkoutState.ShippingLastName = LastNameBilling.Value.ToString();
                checkoutState.ShippingAddress1 = Address1Billing.Value.ToString();
                checkoutState.ShippingAddress2 = Util.GetSafeString(Address2Billing.Value);
                checkoutState.ShippingCity = CityBilling.Value.ToString();
                checkoutState.ShippingCountry = CountryBilling.SelectedValue.ToString();
                checkoutState.ShippingState = StateBilling.SelectedValue.ToString();
                checkoutState.ShippingZip = ZipBilling.Value.ToString();
                checkoutState.ShippingPhoneNumber = Util.GetSafeString(PhoneNumberBilling.Value);
                checkoutState.ShippingCompany = Util.GetSafeString(CompanyBilling.Value);
                checkoutState.ShippingEmail = EmailBilling.Value.ToString();
            }

            checkoutState.CreditCardInfo = new CreditCardInfo();
            checkoutState.CreditCardInfo.CreditCardNumber = CreditCardNumber.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardCardholderName = CardHolderName.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardExpirationMonth = Convert.ToInt32(CardExpirationMonth.Value.ToString());
            checkoutState.CreditCardInfo.CreditCardExpirationYear = Convert.ToInt32(CardExpirationYear.Value.ToString());
            checkoutState.CreditCardInfo.CreditCardSecurityCode = SecurityCode.Value.ToString();
            checkoutState.CreditCardInfo.CreditCardType = CreditCardType.Visa; //for now

            PaymentMethod paymentMethod = this.OrdersManager.GetPaymentMethods().Where(pm => pm.IsActive && pm.PaymentMethodType == PaymentMethodType.PaymentProcessor).First();
            if (paymentMethod == null)
            {
                throw new ArgumentException("Please configure a payment method");
            }

            checkoutState.PaymentMethodId = paymentMethod.Id;

            return checkoutState;
        }
Beispiel #33
0
 public Transition(CheckoutState target, IEnumerable <Guard> guards = null, IEnumerable <Trigger> triggers = null)
 {
     Target   = target;
     Guards   = guards ?? Enumerable.Empty <Guard>();
     Triggers = triggers ?? Enumerable.Empty <Trigger>();
 }
Beispiel #34
0
 public PlaceOrderAction(CheckoutState value)
 {
     Value = value;
 }
Beispiel #35
0
 public StateEvaluationResult(CheckoutState state, CheckoutStageContext checkoutStageContext, CheckoutSelectionContext selections)
 {
     State = state;
     CheckoutStageContext = checkoutStageContext;
     Selections           = selections;
 }
        internal static CartAddress GetBillingAddressFromCheckoutState(OrdersManager ordersManager, CheckoutState checkoutState)
        {
            CartAddress billingAddress = ordersManager.CreateCartAddress();

            billingAddress.FirstName   = checkoutState.BillingFirstName;
            billingAddress.LastName    = checkoutState.BillingLastName;
            billingAddress.Email       = checkoutState.BillingEmail;
            billingAddress.Address     = checkoutState.BillingAddress1;
            billingAddress.Address2    = checkoutState.BillingAddress2;
            billingAddress.AddressType = AddressType.Billing;
            billingAddress.City        = checkoutState.BillingCity;
            billingAddress.PostalCode  = checkoutState.BillingZip;
            billingAddress.StateRegion = checkoutState.BillingState;
            billingAddress.Country     = checkoutState.BillingCountry;
            billingAddress.Phone       = checkoutState.BillingPhoneNumber;
            billingAddress.Email       = checkoutState.BillingEmail;
            billingAddress.Company     = checkoutState.BillingCompany;

            return(billingAddress);
        }
Beispiel #37
0
        private static void UpdateCartDetails(CheckoutState checkoutState, OrdersManager ordersManager, Customer customer, CartOrder cartOrder)
        {
            CartAddress shippingAddress = null;

            if (checkoutState.OrderRequiresShipping)
            {
                shippingAddress             = ordersManager.CreateCartAddress();
                shippingAddress.FirstName   = checkoutState.ShippingFirstName;
                shippingAddress.LastName    = checkoutState.ShippingLastName;
                shippingAddress.Address     = checkoutState.ShippingAddress1;
                shippingAddress.Address2    = checkoutState.ShippingAddress2;
                shippingAddress.AddressType = AddressType.Shipping;
                shippingAddress.City        = checkoutState.ShippingCity;
                shippingAddress.PostalCode  = checkoutState.ShippingZip;
                shippingAddress.StateRegion = checkoutState.ShippingState;
                shippingAddress.Country     = checkoutState.ShippingCountry;
                shippingAddress.Phone       = checkoutState.ShippingPhoneNumber;
                shippingAddress.Email       = checkoutState.ShippingEmail;
                shippingAddress.Company     = checkoutState.ShippingCompany;
                shippingAddress.County      = checkoutState.ShippingCounty;
                cartOrder.Addresses.Add(shippingAddress);
            }

            var billingAddress = ordersManager.CreateCartAddress();

            billingAddress.FirstName   = checkoutState.BillingFirstName;
            billingAddress.LastName    = checkoutState.BillingLastName;
            billingAddress.Address     = checkoutState.BillingAddress1;
            billingAddress.Address2    = checkoutState.BillingAddress2;
            billingAddress.AddressType = AddressType.Billing;
            billingAddress.City        = checkoutState.BillingCity;
            billingAddress.PostalCode  = checkoutState.BillingZip;
            billingAddress.StateRegion = checkoutState.BillingState;
            billingAddress.Country     = checkoutState.BillingCountry;
            billingAddress.Phone       = checkoutState.BillingPhoneNumber;
            billingAddress.Email       = checkoutState.BillingEmail;
            billingAddress.Company     = checkoutState.BillingCompany;
            billingAddress.County      = checkoutState.BillingCounty;

            cartOrder.Addresses.Add(billingAddress);

            decimal vatTaxAmount = cartOrder.VatTaxAmount.HasValue ? cartOrder.VatTaxAmount.Value : 0;

            checkoutState.SubTotal        = cartOrder.SubTotalDisplay + vatTaxAmount;
            checkoutState.TotalWeight     = cartOrder.Weight;
            checkoutState.Tax             = cartOrder.Tax;
            checkoutState.ShippingAmount  = cartOrder.ShippingTotal;
            checkoutState.ShippingTax     = cartOrder.ShippingTax;
            checkoutState.ShippingTaxRate = cartOrder.ShippingTaxRate;
            checkoutState.DiscountAmount  = cartOrder.DiscountTotal;
            checkoutState.Total           = cartOrder.Total;

            var paymentmethod = ordersManager.GetPaymentMethods().FirstOrDefault();

            checkoutState.PaymentMethodId   = paymentmethod.Id;
            checkoutState.PaymentMethodType = paymentmethod.PaymentMethodType;

            CartPayment cartPayment = ordersManager.CreateCartPayment();

            cartPayment.PaymentMethodId        = paymentmethod.Id;
            cartPayment.PaymentMethodType      = paymentmethod.PaymentMethodType;
            cartPayment.CreditCardCustomerName = customer.CustomerFirstName;
            cartPayment.CreditCardNumber       = MockCreditCardNumber;

            cartOrder.Payments.Add(cartPayment);
        }
Beispiel #38
0
 public void StoreCheckout([FromBody] CheckoutState data)
 {
     HttpContext.Session.SetString("checkout", JsonConvert.SerializeObject(data));
 }
 public void SetCheckout([FromBody] CheckoutState checkout)
 {
     HttpContext.Session.SetString("checkout", JsonConvert.SerializeObject(checkout));
 }