Esempio n. 1
0
        public void SaveCheckoutContext(Customer customer, PersistedCheckoutContext checkoutContext)
        {
            var serializedCheckoutContext = JsonConvert.SerializeObject(checkoutContext
                                                                        ?? new PersistedCheckoutContext(
                                                                            creditCard: null,
                                                                            eCheck: null,
                                                                            payPalExpress: null,
                                                                            purchaseOrder: null,
                                                                            acceptJsDetailsCreditCard: null,
                                                                            acceptJsDetailsECheck: null,
                                                                            braintree: null,
                                                                            sagePayPi: null,
                                                                            amazonPayments: null,
                                                                            termsAndConditionsAccepted: false,
                                                                            over13Checked: false,
                                                                            shippingEstimate: null,
                                                                            offsiteRequiredBillingAddressId: null,
                                                                            offsiteRequiredShippingAddressId: null,
                                                                            email: null,
                                                                            selectedShippingMethodId: null));

            var encryptedCheckoutContext = Security.MungeString(serializedCheckoutContext);

            customer.ThisCustomerSession.SetVal(CheckoutContextSessionKey, encryptedCheckoutContext);
        }
Esempio n. 2
0
 public PreCheckoutRuleContext(CheckoutConfiguration checkoutConfiguration, Customer customer, PersistedCheckoutContext persistedCheckoutContext, CartContext cartContext, PaymentMethodInfo paymentMethodInfo)
 {
     CheckoutConfiguration = checkoutConfiguration;
     Customer = customer;
     PersistedCheckoutContext = persistedCheckoutContext;
     CartContext       = cartContext;
     PaymentMethodInfo = paymentMethodInfo;
 }
Esempio n. 3
0
 public CheckoutSelectionApplicationResult(
     Customer customer,
     PaymentMethodInfo selectedPaymentMethod,
     PersistedCheckoutContext persistedCheckoutContext)
 {
     Customer = customer;
     SelectedPaymentMethod    = selectedPaymentMethod;
     PersistedCheckoutContext = persistedCheckoutContext;
 }
Esempio n. 4
0
        public CheckoutSelectionApplicationResult ApplyCheckoutSelections(Customer customer, CheckoutSelectionContext context)
        {
            // Gate customer updates so we don't needlessly invalidate the cache
            if ((context.SelectedPaymentMethod == null && customer.RequestedPaymentMethod != null) ||
                context.SelectedPaymentMethod.Name != customer.RequestedPaymentMethod ||
                (context.SelectedBillingAddress == null && customer.PrimaryBillingAddressID != 0) ||
                (context.SelectedBillingAddress != null && context.SelectedBillingAddress.AddressID != customer.PrimaryBillingAddressID) ||
                (context.SelectedShippingAddress == null && customer.PrimaryShippingAddressID != 0) ||
                (context.SelectedShippingAddress != null && context.SelectedShippingAddress.AddressID != customer.PrimaryShippingAddressID) ||
                context.Email != customer.EMail)
            {
                // While "Over 13" is put into the CheckoutSelectionContext above, it's not persisted back until the order is placed.
                customer.UpdateCustomer(
                    requestedPaymentMethod: context.SelectedPaymentMethod == null
                                                ? string.Empty
                                                : context.SelectedPaymentMethod.Name,
                    billingAddressId: context.SelectedBillingAddress == null
                                                ? 0
                                                : context.SelectedBillingAddress.AddressID,
                    shippingAddressId: context.SelectedShippingAddress == null
                                                ? 0
                                                : context.SelectedShippingAddress.AddressID,
                    email: string.IsNullOrWhiteSpace(context.Email) || customer.IsRegistered
                                                ? customer.EMail
                                                : context.Email);

                customer = new Customer(customer.CustomerID);
            }

            var originalPersistedCheckoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer);

            var updatedPersistedCheckoutContext = new PersistedCheckoutContext(
                creditCard: context.CreditCard,
                payPalExpress: context.PayPalExpress,
                purchaseOrder: context.PurchaseOrder,
                braintree: context.Braintree,
                amazonPayments: context.AmazonPayments,
                termsAndConditionsAccepted: context.TermsAndConditionsAccepted,
                over13Checked: context.Over13Checked,
                shippingEstimateDetails: originalPersistedCheckoutContext.ShippingEstimateDetails,
                offsiteRequiresBillingAddressId: originalPersistedCheckoutContext.OffsiteRequiresBillingAddressId,
                offsiteRequiresShippingAddressId: originalPersistedCheckoutContext.OffsiteRequiresShippingAddressId,
                email: context.Email,
                selectedShippingMethodId: context.SelectedShippingMethodId);

            PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedPersistedCheckoutContext);

            return(new CheckoutSelectionApplicationResult(
                       customer: customer,
                       selectedPaymentMethod: context.SelectedPaymentMethod,
                       persistedCheckoutContext: updatedPersistedCheckoutContext));
        }
Esempio n. 5
0
        public CheckoutSelectionContext GetCheckoutSelection(Customer customer, PaymentMethodInfo selectedPaymentMethod, PersistedCheckoutContext persistedCheckoutContext)
        {
            var validatedBillingAddress  = LoadAddress(customer.PrimaryBillingAddressID);
            var validatedShippingAddress = LoadAddress(customer.PrimaryShippingAddressID);

            // Build up the selections context
            return(new CheckoutSelectionContext(
                       selectedPaymentMethod: selectedPaymentMethod,
                       selectedBillingAddress: validatedBillingAddress,
                       selectedShippingAddress: validatedShippingAddress,
                       selectedShippingMethodId: persistedCheckoutContext.SelectedShippingMethodId,
                       creditCard: persistedCheckoutContext.CreditCard,
                       eCheck: persistedCheckoutContext.ECheck,
                       payPalExpress: persistedCheckoutContext.PayPalExpress,
                       amazonPayments: persistedCheckoutContext.AmazonPayments,
                       purchaseOrder: persistedCheckoutContext.PurchaseOrder,
                       acceptJsDetailsCreditCard: persistedCheckoutContext.AcceptJsDetailsCreditCard,
                       braintree: persistedCheckoutContext.Braintree,
                       sagePayPi: persistedCheckoutContext.SagePayPi,
                       termsAndConditionsAccepted: persistedCheckoutContext.TermsAndConditionsAccepted,
                       over13Checked: persistedCheckoutContext.Over13Checked || customer.IsOver13,
                       email: persistedCheckoutContext.Email ?? customer.EMail));
        }
Esempio n. 6
0
        public CartContext LoadCartContext(CheckoutConfiguration configuration, Customer customer, PersistedCheckoutContext persistedCheckoutContext, PaymentMethodInfo selectedPaymentMethod)
        {
            var cartContext = new CartContext(
                cart: CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID()));

            var preRuleCheckoutContext = new PreCheckoutRuleContext(
                checkoutConfiguration: configuration,
                customer: customer,
                persistedCheckoutContext: persistedCheckoutContext,
                cartContext: cartContext,
                paymentMethodInfo: selectedPaymentMethod);

            foreach (var rule in PreCheckoutRules)
            {
                cartContext = rule.Apply(preRuleCheckoutContext);
            }

            return(cartContext);
        }