Esempio n. 1
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 updatedPersistedCheckoutContext = new PersistedCheckoutContextBuilder()
                                                  .From(PersistedCheckoutContextProvider.LoadCheckoutContext(customer))
                                                  .WithCreditCard(context.CreditCard)
                                                  .WithPayPalExpress(context.PayPalExpress)
                                                  .WithPurchaseOrder(context.PurchaseOrder)
                                                  .WithAcceptJsCreditCard(context.AcceptJsDetailsCreditCard)
                                                  .WithBraintree(context.Braintree)
                                                  .WithSagePayPi(context.SagePayPi)
                                                  .WithAmazonPayments(context.AmazonPayments)
                                                  .WithTermsAndConditionsAccepted(context.TermsAndConditionsAccepted)
                                                  .WithOver13Checked(context.Over13Checked)
                                                  .WithEmail(context.Email)
                                                  .WithSelectedShippingMethodId(context.SelectedShippingMethodId)
                                                  .Build();

            PersistedCheckoutContextProvider.SaveCheckoutContext(customer, updatedPersistedCheckoutContext);

            return(new CheckoutSelectionApplicationResult(
                       customer: customer,
                       selectedPaymentMethod: context.SelectedPaymentMethod,
                       persistedCheckoutContext: updatedPersistedCheckoutContext));
        }
Esempio n. 2
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));
        }