private void ProcessCancellation(
            Cart cart,
            Store store,
            WorldPayPaymentResponse wpResponse,
            PayPalLog worldPayLog,
            Page page)
        {
            //string serializedResponse = SerializationHelper.SerializeToString(wpResponse);
            //log.Info("received cancellation worldpay postback, xml to follow");
            //log.Info(serializedResponse);

            // return an html order cancelled template for use at world pay
            if (config.WorldPayProduceShopperCancellationResponse)
            {
                string htmlTemplate = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, config.WorldPayShopperCancellationResponseTemplate);
                StringBuilder finalOutput = new StringBuilder();
                finalOutput.Append(htmlTemplate);
                finalOutput.Replace("#WorldPayBannerToken", "<WPDISPLAY ITEM=banner>"); //required by worldpay
                finalOutput.Replace("#CustomerName", wpResponse.Name);
                finalOutput.Replace("#StoreName", store.Name);

                string storePageUrl = worldPayLog.RawResponse;

                finalOutput.Replace("#StorePageLink", "<a href='" + storePageUrl + "'>" + storePageUrl + "</a>");

                page.Response.Write(finalOutput.ToString());
                page.Response.Flush();

            }
        }
Esempio n. 2
0
        public static bool ApplyDiscount(Store store, Cart cart, string discountCode, out string errorMessage)
        {
            if (cart == null)
            {
                errorMessage = WebStoreResources.DiscountInvalidCartError;
                return false;
            }

            if (store == null)
            {
                errorMessage = WebStoreResources.DiscountInvalidCartError;
                return false;
            }

            if (string.IsNullOrEmpty(discountCode))
            {
                errorMessage = WebStoreResources.DiscountCodeNotProvidedError;
                return false;
            }

            Discount discount = new Discount(store.ModuleGuid, discountCode);
            if (discount.DiscountGuid == Guid.Empty)
            {
                errorMessage = WebStoreResources.DiscountCodeNotFoundError;
                return false;
            }

            if (discount.ValidityEndDate < DateTime.UtcNow)
            {
                errorMessage = WebStoreResources.DiscountCodeExpiredError;
                return false;
            }

            if (discount.ValidityStartDate > DateTime.UtcNow)
            {
                errorMessage = WebStoreResources.DiscountCodeNotActiveError;
                return false;
            }

            if (!discount.AllowOtherDiscounts)
            {
                cart.DiscountCodesCsv = discount.DiscountCode;
            }

            if (cart.DiscountCodesCsv.Length == 0)
            {
                cart.DiscountCodesCsv = discount.DiscountCode;
            }
            else
            {
                if (!cart.DiscountCodesCsv.Contains(discount.DiscountCode))
                {
                    cart.DiscountCodesCsv += "," + discount.DiscountCode;
                }
            }

            return ValidateAndApplyDiscounts(store, cart, out errorMessage);
        }
Esempio n. 3
0
        /// <summary>
        /// we are using the paypal log with a different request type rather than making a new log specifically for WorldPay
        /// 
        /// The goal here is to make sure we always have a PayPalLog with current cart serialized.
        /// We need to do this because we could transfer the user to WorldPay, then they add more items to the cart,
        /// then complete the checkout at WorldPay for the previous version of the cart.
        /// If we were to just use the current cart from the db we might give them more or less than they actually
        /// bought. By keeping a copy of the cart as it was at time of transfer, we can be sure
        /// we only give them the products they had at checkout time.
        /// </summary>
        public static PayPalLog EnsureWorldPayCheckoutLog(
            Cart cart,
            Store store,
            string siteRoot,
            string storePageUrl,
            int pageId,
            int moduleId)
        {
            if (cart == null) return null;
            if (store == null) return null;

            PayPalLog worldPayLog = PayPalLog.GetMostRecent(cart.CartGuid, "WorldPay");
            if ((worldPayLog == null) || (worldPayLog.SerializedObject.Length == 0))
            {
                return CreateWorldPayCheckoutLog(cart, store, siteRoot, storePageUrl, pageId, moduleId);
            }

            Cart worldPayCart = (Cart)SerializationHelper.DeserializeFromString(typeof(Cart), worldPayLog.SerializedObject);

            if (worldPayCart.LastModified < cart.LastModified)
            {
                // cart has been modified since we last serialized it so create a new one
                return CreateWorldPayCheckoutLog(cart, store, siteRoot, storePageUrl, pageId, moduleId);
            }

            return worldPayLog;
        }
Esempio n. 4
0
        public bool CanCheckoutWithoutAuthentication(Cart cart)
        {
            if (cart == null) { return false; }
            if((cart.HasDownloadProducts())&&(this.requireRegistrationForDownloadProducts)) { return false; }
            if((cart.HasDonations())&&(this.requireRegistrationForNoFulfillmentProducts)) { return false; }
            if((cart.HasShippingProducts())&&(this.requireRegistrationForShippedProducts)) { return false; }

            return true;
        }
Esempio n. 5
0
 public static void EnsureValidDiscounts(Store store, Cart cart)
 {
     string errorMessage = string.Empty;
     ValidateAndApplyDiscounts(store, cart, out errorMessage);
 }
Esempio n. 6
0
        private static Cart CreateClerkCartAndSetCookie(Store store, string cartKey)
        {
            if (store == null) return null;
            if (store.Guid == Guid.Empty) return null;

            Cart cart = new Cart();
            cart.StoreGuid = store.Guid;
            cart.CreatedFromIP = SiteUtils.GetIP4Address();

            if (
                (HttpContext.Current != null)
                && (HttpContext.Current.Request.IsAuthenticated)
                )
            {
                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                cart.ClerkGuid = siteUser.UserGuid;

            }
            cart.Save();

            CookieHelper.SetPersistentCookie(cartKey, cart.CartGuid.ToString());

            HttpContext.Current.Items[cartKey] = cart;

            return cart;
        }
Esempio n. 7
0
        private void LoadSettings()
        {
            store = StoreHelper.GetStore();
            if (store == null) { return; }

            commerceConfig = SiteUtils.GetCommerceConfig();
            currencyCulture = ResourceHelper.GetCurrencyCulture(siteSettings.GetCurrency().Code);

            if (Request.IsAuthenticated)
            {
                siteUser = SiteUtils.GetCurrentSiteUser();
            }

            if (StoreHelper.UserHasCartCookie(store.Guid))
            {
                cart = StoreHelper.GetCart();
                if (cart != null)
                {
                    cartOffers = cart.GetOffers();

                    canCheckoutWithoutAuthentication = store.CanCheckoutWithoutAuthentication(cart);

                    if ((cart.LastModified < DateTime.UtcNow.AddDays(-1)) && (cart.DiscountCodesCsv.Length > 0))
                    {
                        StoreHelper.EnsureValidDiscounts(store, cart);
                    }

                    if ((cart.UserGuid == Guid.Empty)&&(siteUser != null))
                    {
                        cart.UserGuid = siteUser.UserGuid;
                        cart.Save();
                    }
                    cart.RefreshTotals();
                }
            }

            ConfigureCheckoutButtons();

            AddClassToBody("webstore webstorecheckout");
        }
Esempio n. 8
0
        public void LoadCustomerInfoFromMostRecentOrder(Cart cart)
        {
            Order lastOrder = Order.GetMostRecentOrder(this.guid, cart.UserGuid);
            if (lastOrder != null)
            {
                cart.OrderInfo.CustomerAddressLine1 = lastOrder.CustomerAddressLine1;
                cart.OrderInfo.CustomerAddressLine2 = lastOrder.CustomerAddressLine2;
                cart.OrderInfo.CustomerCity = lastOrder.CustomerCity;
                cart.OrderInfo.CustomerCompany = lastOrder.CustomerCompany;
                cart.OrderInfo.CustomerCountry = lastOrder.CustomerCountry;
                cart.OrderInfo.CustomerEmail = lastOrder.CustomerEmail;
                cart.OrderInfo.CustomerEmailVerified = lastOrder.CustomerEmailVerified;
                cart.OrderInfo.CustomerFirstName = lastOrder.CustomerFirstName;
                cart.OrderInfo.CustomerLastName = lastOrder.CustomerLastName;
                cart.OrderInfo.CustomerPostalCode = lastOrder.CustomerPostalCode;
                cart.OrderInfo.CustomerState = lastOrder.CustomerState;
                cart.OrderInfo.CustomerSuburb = lastOrder.CustomerSuburb;
                cart.OrderInfo.CustomerTelephoneDay = lastOrder.CustomerTelephoneDay;
                cart.OrderInfo.CustomerTelephoneNight = lastOrder.CustomerTelephoneNight;

                cart.OrderInfo.BillingAddress1 = lastOrder.CustomerAddressLine1;
                cart.OrderInfo.BillingAddress2 = lastOrder.CustomerAddressLine2;
                cart.OrderInfo.BillingCity = lastOrder.CustomerCity;
                cart.OrderInfo.BillingCompany = lastOrder.CustomerCompany;
                cart.OrderInfo.BillingCountry = lastOrder.CustomerCountry;
                cart.OrderInfo.BillingFirstName = lastOrder.CustomerFirstName;
                cart.OrderInfo.BillingLastName = lastOrder.CustomerLastName;
                cart.OrderInfo.BillingPostalCode = lastOrder.CustomerPostalCode;
                cart.OrderInfo.BillingState = lastOrder.CustomerState;
                cart.OrderInfo.BillingSuburb = lastOrder.CustomerSuburb;

                cart.OrderInfo.DeliveryAddress1 = lastOrder.CustomerAddressLine1;
                cart.OrderInfo.DeliveryAddress2 = lastOrder.CustomerAddressLine2;
                cart.OrderInfo.DeliveryCity = lastOrder.CustomerCity;
                cart.OrderInfo.DeliveryCompany = lastOrder.CustomerCompany;
                cart.OrderInfo.DeliveryCountry = lastOrder.CustomerCountry;
                cart.OrderInfo.DeliveryFirstName = lastOrder.CustomerFirstName;
                cart.OrderInfo.DeliveryLastName = lastOrder.CustomerLastName;
                cart.OrderInfo.DeliveryPostalCode = lastOrder.CustomerPostalCode;
                cart.OrderInfo.DeliveryState = lastOrder.CustomerState;
                cart.OrderInfo.DeliverySuburb = lastOrder.CustomerSuburb;
                cart.OrderInfo.TaxZoneGuid = lastOrder.TaxZoneGuid;

                cart.OrderInfo.Save();

            }
        }
Esempio n. 9
0
        public static bool ValidateAndApplyDiscounts(Store store, Cart cart, out string errorMessage)
        {
            if (cart == null)
            {
                errorMessage = WebStoreResources.DiscountInvalidCartError;
                return false;
            }

            if (store == null)
            {
                errorMessage = WebStoreResources.DiscountInvalidCartError;
                return false;
            }

            errorMessage = string.Empty;
            List<Discount> discountList = Discount.GetValidDiscounts(store.ModuleGuid, cart, cart.DiscountCodesCsv);
            cart.Discount = 0;
            cart.RefreshTotals();

            cart.DiscountCodesCsv = string.Empty;
            if (cart.SubTotal <= 0)
            {
                cart.Save();
                return false;
            }

            string comma = string.Empty;
            bool appliedDiscount = false;
            foreach (Discount d in discountList)
            {
                cart.DiscountCodesCsv += comma + d.DiscountCode;
                comma = ",";
                if (d.AbsoluteDiscount > 0)
                {
                    cart.Discount += d.AbsoluteDiscount;
                    appliedDiscount = true;
                }

                if (d.PercentageDiscount > 0)
                {
                    cart.Discount += (cart.SubTotal * d.PercentageDiscount);
                    appliedDiscount = true;
                }

            }

            cart.RefreshTotals();

            if (!appliedDiscount) { errorMessage = WebStoreResources.DiscountInvalidCartError; }

            return appliedDiscount;
        }
Esempio n. 10
0
        public static Order CreateOrder(
            Store store,
            Cart cart, 
            string gatewayRawResponse,
            string gatewayTransactionId,
            string gatewayApprovalCode,
            string currencyCode,
            string paymentMethod,
            Guid orderStatusGuid)
        {
            Order order = new Order(cart.CartGuid);

            order.billingAddress1 = cart.OrderInfo.BillingAddress1;
            order.billingAddress2 = cart.OrderInfo.BillingAddress2;
            order.billingCity = cart.OrderInfo.BillingCity;
            order.billingCompany = cart.OrderInfo.BillingCompany;
            order.billingCountry = cart.OrderInfo.BillingCountry;
            order.billingFirstName = cart.OrderInfo.BillingFirstName;
            order.billingLastName = cart.OrderInfo.BillingLastName;
            order.billingPostalCode = cart.OrderInfo.BillingPostalCode;
            order.billingState = cart.OrderInfo.BillingState;
            order.billingSuburb = cart.OrderInfo.BillingSuburb;

            order.completed = cart.OrderInfo.Completed;
            order.completedFromIP = cart.OrderInfo.CompletedFromIP;
            order.created = DateTime.UtcNow;
            order.createdFromIP = cart.OrderInfo.CompletedFromIP;

            order.customerAddressLine1 = cart.OrderInfo.CustomerAddressLine1;
            order.customerAddressLine2 = cart.OrderInfo.CustomerAddressLine2;
            order.customerCity = cart.OrderInfo.CustomerCity;
            order.customerCompany = cart.OrderInfo.CustomerCompany;
            order.customerCountry = cart.OrderInfo.CustomerCountry;
            order.customerEmail = cart.OrderInfo.CustomerEmail;
            order.customerEmailVerified = cart.OrderInfo.CustomerEmailVerified;
            order.customerFirstName = cart.OrderInfo.CustomerFirstName;
            order.customerLastName = cart.OrderInfo.CustomerLastName;
            order.customerPostalCode = cart.OrderInfo.CustomerPostalCode;
            order.customerState = cart.OrderInfo.CustomerState;
            order.customerSuburb = cart.OrderInfo.CustomerSuburb;
            order.customerTelephoneDay = cart.OrderInfo.CustomerTelephoneDay;
            order.customerTelephoneNight = cart.OrderInfo.CustomerTelephoneNight;

            order.deliveryAddress1 = cart.OrderInfo.DeliveryAddress1;
            order.deliveryAddress2 = cart.OrderInfo.DeliveryAddress2;
            order.deliveryCity = cart.OrderInfo.DeliveryCity;
            order.deliveryCompany = cart.OrderInfo.DeliveryCompany;
            order.deliveryCountry = cart.OrderInfo.DeliveryCountry;
            order.deliveryFirstName = cart.OrderInfo.DeliveryFirstName;
            order.deliveryLastName = cart.OrderInfo.DeliveryLastName;
            order.deliveryPostalCode = cart.OrderInfo.DeliveryPostalCode;
            order.deliveryState = cart.OrderInfo.DeliveryState;
            order.deliverySuburb = cart.OrderInfo.DeliverySuburb;

            order.gatewayAuthCode = gatewayApprovalCode;
            order.gatewayRawResponse = gatewayRawResponse;
            order.gatewayTransID = gatewayTransactionId;

            order.lastModified = DateTime.UtcNow;
            order.lastUserActivity = cart.LastUserActivity;

            order.orderGuid = cart.CartGuid;

            order.OrderTotal = cart.OrderTotal;
            order.statusGuid = orderStatusGuid;

            order.storeGuid = cart.StoreGuid;
            order.clerkGuid = cart.ClerkGuid;
            order.subTotal = cart.SubTotal;
            order.taxTotal = cart.TaxTotal;
            order.discount = cart.Discount;
            order.shippingTotal = cart.ShippingTotal;
            order.taxZoneGuid = cart.OrderInfo.TaxZoneGuid;
            order.userGuid = cart.UserGuid;
            order.discountCodesCsv = cart.DiscountCodesCsv;
            order.customData = cart.CustomData;

            order.Save();

            // TODO: need to add this in insert so we don't have to save 2x
            order.paymentMethod = paymentMethod;
            order.Save();

            foreach (CartOffer cartOffer in cart.CartOffers)
            {
                OrderOffer orderOffer = new OrderOffer();
                orderOffer.AddedToCart = cartOffer.AddedToCart;
                //orderOffer.CurrencyGuid = cartOffer.CurrencyGuid;
                orderOffer.OfferGuid = cartOffer.OfferGuid;
                orderOffer.OfferPrice = cartOffer.OfferPrice;
                orderOffer.OrderGuid = order.OrderGuid;
                //orderOffer.PriceGuid = cartOffer.PriceGuid;
                orderOffer.Quantity = cartOffer.Quantity;
                orderOffer.TaxClassGuid = cartOffer.TaxClassGuid;
                orderOffer.Save();

                Collection<OfferProduct> offerProducts
                    = OfferProduct.GetbyOffer(orderOffer.OfferGuid);

                foreach (OfferProduct offerProduct in offerProducts)
                {
                    OrderOfferProduct orderProduct = new OrderOfferProduct();
                    orderProduct.Created = DateTime.UtcNow;
                    orderProduct.FullfillTermsGuid = offerProduct.FullFillTermsGuid;
                    orderProduct.FullfillType = offerProduct.FullfillType;
                    orderProduct.OfferGuid = offerProduct.OfferGuid;
                    orderProduct.OrderGuid = order.OrderGuid;
                    orderProduct.ProductGuid = offerProduct.ProductGuid;
                    orderProduct.Save();

                    if (
                        (offerProduct.FullfillType
                        == (byte)FulfillmentType.Download)
                        && (offerProduct.FullFillTermsGuid != Guid.Empty)
                        )
                    {
                        // create download fullfillment ticket
                        FullfillDownloadTerms downloadTerms
                            = new FullfillDownloadTerms(offerProduct.FullFillTermsGuid);

                        FullfillDownloadTicket downloadTicket = new FullfillDownloadTicket();
                        downloadTicket.CountAfterDownload = downloadTerms.CountAfterDownload;
                        downloadTicket.DownloadsAllowed = downloadTerms.DownloadsAllowed;
                        downloadTicket.ExpireAfterDays = downloadTerms.ExpireAfterDays;
                        downloadTicket.FullfillTermsGuid = offerProduct.FullFillTermsGuid;
                        downloadTicket.OrderGuid = order.OrderGuid;
                        downloadTicket.ProductGuid = offerProduct.ProductGuid;
                        downloadTicket.PurchaseTime = order.Completed;
                        downloadTicket.StoreGuid = order.StoreGuid;
                        downloadTicket.UserGuid = order.UserGuid;
                        downloadTicket.Save();

                    }
                }

            }

            if (order.DiscountCodesCsv.Length > 0)
            {
                List<WebStore.Business.Discount> discountList = WebStore.Business.Discount.GetValidDiscounts(store.ModuleGuid, cart, cart.DiscountCodesCsv);
                foreach (WebStore.Business.Discount d in discountList)
                {
                    d.UseCount += 1;
                    d.Save();
                    // TODO: Discount log

                }
            }

            Cart.Delete(cart.CartGuid);

            return order;
        }
Esempio n. 11
0
        public static Cart GetCartIfExists(Guid storeGuid, bool isAuthenticated)
        {
            if (HttpContext.Current == null) return null;

            //Store store = GetStore();

            //if (store == null) return null;

            Cart cart = null;

            //string cartKey = "cart" + store.Guid.ToString();
            string cartKey = "cart" + storeGuid.ToString();

            if (HttpContext.Current.Items[cartKey] != null)
            {
                cart = (Cart)HttpContext.Current.Items[cartKey];
                if(isAuthenticated)
                {
                    VerifyCartUser(cart);
                }
                return cart;
            }

            if (UserHasCartCookie(storeGuid))
            {
                string cartCookie = GetCartCookie(storeGuid);
                if (cartCookie.Length == 36)
                {
                    Guid cartGuid = new Guid(cartCookie);
                    cart = new Cart(cartGuid);
                    if ((!cart.Exists) || (cart.StoreGuid != storeGuid))
                    {
                        return null;
                    }

                    if (isAuthenticated)
                    {
                        VerifyCartUser(cart);
                    }
                    HttpContext.Current.Items[cartKey] = cart;
                    return cart;

                }
                else
                {
                    // cookie is invalid
                    return null;
                }
            }
            else
            {
                // TODO: handle use case where user adds to cart on 1 machine
                // then comes back to site on another machine and has no cart cookie
                // look for a cart that has the userguid,
                // if found set cookie for that cart

                // doesn't exist
                return null;

            }

            //return null;
        }
        private void LoadSettings()
        {
            store = StoreHelper.GetStore();
            if (store == null) { return; }
            currencyCulture = ResourceHelper.GetCurrencyCulture(siteSettings.GetCurrency().Code);

            cart = StoreHelper.GetClerkCart(store);

            lnkCheckout.NavigateUrl = SiteRoot + "/WebStore/AdminOrderCheckout.aspx?pageid=" + pageId.ToInvariantString()
                + "&mid=" + moduleId.ToInvariantString();

            divCheckoutLink.Visible = (cart.SubTotal > 0);

            int countOfDiscountCodes = Discount.GetCountOfActiveDiscountCodes(store.ModuleGuid);
            pnlDiscountCode.Visible = ((countOfDiscountCodes > 0)&&(cart.SubTotal > 0));

            pnlManualDiscount.Visible = ((WebUser.IsAdmin) && (cart.SubTotal > 0));

            AddClassToBody("webstore orderentry");
        }
Esempio n. 13
0
 public static Order CreateOrder(
     Store store,
     Cart cart, 
     IPaymentGateway gateway, 
     string currencyCode, 
     string paymentMethod)
 {
     return CreateOrder(
         store,
         cart,
         gateway.RawResponse,
         gateway.TransactionId,
         gateway.ApprovalCode,
         currencyCode,
         paymentMethod,
         OrderStatus.OrderStatusFulfillableGuid);
 }
        private void LoadSettings()
        {
            ScriptConfig.IncludeColorBox = true;
            storeCountry = new GeoCountry(siteSettings.DefaultCountryGuid);
            currencyCulture = ResourceHelper.GetCurrencyCulture(siteSettings.GetCurrency().Code);
            commerceConfig = SiteUtils.GetCommerceConfig();

            store = StoreHelper.GetStore();
            if (store == null) { return; }

            cart = StoreHelper.GetClerkCart(store);
            tblCountryList = GeoCountry.GetList();

            if (WebUser.IsInRoles(siteSettings.RolesThatCanLookupUsers))
            {
                SetupSelectUserScript();
                //lnkUserLookup.Visible = true;
                lnkUserSearch.Visible = true;
            }

            AddClassToBody("webstore admincheckout");
        }
Esempio n. 15
0
        private void GetCartInfo()
        {
            if ((!includeItemCount) && (!includeCartTotal)) { return; }

            siteSettings = CacheHelper.GetCurrentSiteSettings();

            currencyCulture = ResourceHelper.GetCurrencyCulture(siteSettings.GetCurrency().Code);

            cart = StoreHelper.GetCartIfExists(moduleGuid, Page.Request.IsAuthenticated);
            if (cart == null) { return; }

            itemCount = cart.CartOffers.Count();
            cartTotal = cart.SubTotal;
        }
Esempio n. 16
0
        private void LoadSettings()
        {
            store = StoreHelper.GetStore();
            if (store == null) { return; }

            commerceConfig = SiteUtils.GetCommerceConfig();
            currencyCulture = ResourceHelper.GetCurrencyCulture(siteSettings.GetCurrency().Code);
            storeCountry = new GeoCountry(siteSettings.DefaultCountryGuid);

            if (Request.IsAuthenticated)
            {
                siteUser = SiteUtils.GetCurrentSiteUser();
            }

            if (StoreHelper.UserHasCartCookie(store.Guid))
            {
                cart = StoreHelper.GetCart();

                if (cart != null)
                {
                    if ((cart.LastModified < DateTime.UtcNow.AddDays(-1)) && (cart.DiscountCodesCsv.Length > 0))
                    {
                        StoreHelper.EnsureValidDiscounts(store, cart);
                    }

                    if (siteUser != null)
                    {
                        if (cart.UserGuid == Guid.Empty)
                        {
                            // take ownership of anonymous cart
                            cart.UserGuid = siteUser.UserGuid;
                            cart.Save();
                            StoreHelper.InitializeOrderInfo(cart, siteUser);
                        }
                        else
                        {
                            // cart already has a user guid but
                            // check if it matches the current user
                            // cart cookie could have been left behind by a previous user
                            // on shared computers
                            // if cart user guid doesn't match reset billing shipping info
                            // and any other identifiers
                            // but leave items in cart
                            if (cart.UserGuid != siteUser.UserGuid)
                            {
                                cart.ResetUserInfo();
                                cart.UserGuid = siteUser.UserGuid;
                                cart.Save();
                                StoreHelper.InitializeOrderInfo(cart, siteUser);
                            }
                        }
                    }

                    if (WebStoreConfiguration.IsDemo)
                    {
                        LoadDemoCustomer();
                    }

                    canCheckoutWithoutAuthentication = store.CanCheckoutWithoutAuthentication(cart);

                    // disable till I finish
                    //canCheckoutWithoutAuthentication = false;

                }

                AddClassToBody("webstore webstoreconfirmorder");
            }

            pnlRequireLogin.Visible = !Request.IsAuthenticated;

            if ((canCheckoutWithoutAuthentication)||(Request.IsAuthenticated))
            {

                pnlOrderDetail.Visible = commerceConfig.CanProcessStandardCards || (commerceConfig.WorldPayInstallationId.Length > 0);
                pnlRequireLogin.Visible = true;
                pnlShippingTotal.Visible = false;
                pnlTaxTotal.Visible = false;
                pnlOrderTotal.Visible = false;

            }

            if ((cart != null) && (cart.SubTotal == 0) && (cart.CartOffers.Count > 0))
            {
                // free checkout
                pnlOrderDetail.Visible = true;
            }

            if (pnlOrderDetail.Visible) { tblCountryList = GeoCountry.GetList(); }

            ConfigureCheckoutButtons();

            //if (!Page.IsPostBack)
            //{
            //    if ((commerceConfig.PayPalIsEnabled) && (commerceConfig.PayPalUsePayPalStandard))
            //    {
            //        if (Request.IsAuthenticated)
            //        {
            //            SetupPayPalStandardForm();
            //        }
            //        else
            //        {
            //            // we need the user to be signed in before we send them to paypal if using PayPal Standard
            //            // because we want to return them to their order summary and that requires login
            //            // so we need to know who the user is before sending them to PayPal
            //            litOr.Visible = false;
            //            btnPayPal.Visible = false;
            //            btnGoogleCheckout.Visible = false;
            //        }
            //    }
            //}

            //if (!Request.IsAuthenticated)
            //{

            //    pnlOrderDetail.Visible = false;
            //    pnlRequireLogin.Visible = true;
            //    pnlShippingTotal.Visible = false;
            //    pnlTaxTotal.Visible = false;
            //    pnlOrderTotal.Visible = false;

            //    if (commerceConfig.GoogleCheckoutIsEnabled)
            //    {
            //        if (
            //        (!commerceConfig.Is503TaxExempt)
            //        && ((cart != null) && (cart.HasDonations()))
            //        )
            //        {
            //            //btnGoogleCheckout.Visible = false;
            //            lblGoogleMessage.Text = WebStoreResources.GoogleCheckoutDisabledForDonationsMessage;
            //            lblGoogleMessage.Visible = true;
            //            PaymentAcceptanceMark mark = (PaymentAcceptanceMark)pam1;
            //            mark.SuppressGoogleCheckout = true;

            //            mark = (PaymentAcceptanceMark)PaymentAcceptanceMark1;
            //            mark.SuppressGoogleCheckout = true;

            //            btnGoogleCheckout.Visible = true;
            //            btnGoogleCheckout.Enabled = false;
            //        }
            //    }

            //}
            //else
            //{
            //    if (
            //        (!commerceConfig.Is503TaxExempt)
            //         && ((cart != null)&& (cart.HasDonations()))
            //        && (commerceConfig.GoogleCheckoutIsEnabled)
            //        )
            //    {
            //        btnGoogleCheckout.Visible = true;
            //        btnGoogleCheckout.Enabled = false;
            //        lblGoogleMessage.Text = WebStoreResources.GoogleCheckoutDisabledForDonationsMessage;
            //        lblGoogleMessage.Visible = true;
            //    }

            //}
        }
Esempio n. 17
0
        /// <summary>
        /// Creates the URL for PayPal Standard BuyNow button
        /// </summary>
        /// <returns></returns>
        public static string GetBuyNowUrl(
            Guid payPalLogGuid,
            Cart cart, 
            Store store,
            CommerceConfiguration commerceConfig)
        {
            //PayPalStandardPaymentGateway gateway = new PayPalStandardPaymentGateway();
            //gateway.PayPalStandardUrl = commerceConfig.PayPalStandardUrl;
            //gateway.BusinessEmail = commerceConfig.PayPalStandardEmailAddress;
            //gateway.PDTId = commerceConfig.PayPalStandardPDTId;

            PayPalStandardPaymentGateway gateway
                = new PayPalStandardPaymentGateway(
                    commerceConfig.PayPalStandardUrl,
                    commerceConfig.PayPalStandardEmailAddress,
                    commerceConfig.PayPalStandardPDTId);

            gateway.Amount = cart.OrderTotal;
            gateway.Tax = cart.TaxTotal;
            gateway.Shipping = cart.ShippingTotal;

            //Currency currency = new Currency(cart.CurrencyGuid);
            //gateway.CurrencyCode = store.DefaultCurrency;

            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
            gateway.CurrencyCode = siteSettings.GetCurrency().Code;

            gateway.OrderHasShippableProducts = cart.HasShippingProducts();

            // TODO: guess we need to split this into first and last
            gateway.ShippingFirstName =  cart.OrderInfo.DeliveryFirstName;
            gateway.ShippingLastName = cart.OrderInfo.DeliveryLastName;

            gateway.ShippingAddress1 = cart.OrderInfo.DeliveryAddress1;
            gateway.ShippingAddress2 = cart.OrderInfo.DeliveryAddress2;
            gateway.ShippingCity = cart.OrderInfo.DeliveryCity;
            gateway.ShippingState = cart.OrderInfo.DeliveryState;
            gateway.ShippingPostalCode = cart.OrderInfo.DeliveryPostalCode;

            //add the items
            //foreach (CartOffer offer in cart.CartOffers)
            //{
            //    PayPalOrderItem item = new PayPalOrderItem();
            //    item.Amount = offer.OfferPrice;
            //    item.ItemName = offer.Name;
            //    item.ItemNumber = offer.OfferGuid.ToString();
            //    item.Quantity = offer.Quantity;

            //    gateway.Items.Add(item);

            //}

            gateway.OrderDescription = store.Name + " " + WebStoreResources.OrderHeading;

            gateway.Custom = payPalLogGuid.ToString();

            string siteRoot = SiteUtils.GetNavigationSiteRoot();
            string storePageUrl = SiteUtils.GetCurrentPageUrl();

            gateway.ReturnUrl = siteRoot + "/Services/PayPalPDTHandler.aspx";
            gateway.NotificationUrl = siteRoot + "/Services/PayPalIPNHandler.aspx";
            gateway.CancelUrl = storePageUrl;

            return gateway.GetBuyNowButtonUrl();
        }
Esempio n. 18
0
        public static Cart GetClerkCart(Store store)
        {
            if (HttpContext.Current == null) return null;
            if (store == null) return null;

            string cartKey = "clerkcart" + store.Guid.ToString();
            if (HttpContext.Current.Items[cartKey] != null)
            {
                return (Cart)HttpContext.Current.Items[cartKey];
            }

            if (CookieHelper.CookieExists(cartKey))
            {
                string cartCookie = CookieHelper.GetCookieValue(cartKey);
                if (cartCookie.Length == 36)
                {
                    Guid cartGuid = new Guid(cartCookie);
                    Cart cart = new Cart(cartGuid);
                    if (!cart.Exists)
                    {
                        return CreateClerkCartAndSetCookie(store, cartKey);
                    }

                    HttpContext.Current.Items[cartKey] = cart;
                    return cart;

                }
                else
                {
                    // cookie is invalid
                    return CreateClerkCartAndSetCookie(store, cartKey);
                }
            }
            else
            {

                return CreateClerkCartAndSetCookie(store, cartKey);

            }
        }
        private void ProcessOrder(
            Cart cart,
            Store store,
            WorldPayPaymentResponse wpResponse,
            PayPalLog worldPayLog,
            Page page)
        {
            // process the cart into an order then
            // return an html order result template for use at world pay

            cart.DeSerializeCartOffers();

            if (wpResponse.CompName.Length > 0)
            {
                cart.OrderInfo.CustomerCompany = wpResponse.CompName;
            }
            if (wpResponse.Address1.Length > 0)
            {
                cart.OrderInfo.CustomerAddressLine1 = wpResponse.Address1;
            }

            if (wpResponse.Address2.Length > 0)
            {
                cart.OrderInfo.CustomerAddressLine2 = wpResponse.Address2;
            }

            if (wpResponse.Address3.Length > 0)
            {
                cart.OrderInfo.CustomerAddressLine2 += " " + wpResponse.Address3;
            }

            if (wpResponse.Town.Length > 0)
            {
                cart.OrderInfo.CustomerCity = wpResponse.Town;
            }
            //cart.OrderInfo.DeliveryFirstName = wpResponse.Name;
            if(
                (wpResponse.Name.Length > 0)
                && ((cart.OrderInfo.CustomerLastName.Length == 0) || (!wpResponse.Name.Contains((cart.OrderInfo.CustomerLastName))))
                )
            {
                cart.OrderInfo.CustomerLastName = wpResponse.Name; // this is full name
            }
            if (wpResponse.Postcode.Length > 0)
            {
                cart.OrderInfo.CustomerPostalCode = wpResponse.Postcode;
            }
            if (wpResponse.Region.Length > 0)
            {
                cart.OrderInfo.CustomerState = wpResponse.Region;
            }
            if (wpResponse.Country.Length > 0)
            {
                cart.OrderInfo.CustomerCountry = wpResponse.Country;
            }

            if (wpResponse.Tel.Length > 0)
            {
                cart.OrderInfo.CustomerTelephoneDay = wpResponse.Tel;
            }

            if (wpResponse.Email.Length > 0)
            {
                cart.OrderInfo.CustomerEmail = wpResponse.Email;
            }

            cart.CopyCustomerToBilling();
            cart.CopyCustomerToShipping();
            //cart.TaxTotal = taxAmount;
            //cart.OrderTotal = grossAmount;
            //if (shippingAmount > 0)
            //{
            //    cart.ShippingTotal = shippingAmount;
            //}

            StoreHelper.EnsureUserForOrder(cart);

            cart.Save();

            Order order = Order.CreateOrder(
                store,
                cart,
                wpResponse.TransId,
                wpResponse.TransId,
                string.Empty,
                wpResponse.Currency,
                "WorldPay",
                OrderStatus.OrderStatusFulfillableGuid);

            // grab the return url before we delete the un-needed logs
            string orderDetailUrl = worldPayLog.ReturnUrl;
            string storePageUrl = worldPayLog.RawResponse;

            // remove any previous logs
            GoogleCheckoutLog.DeleteByCart(order.OrderGuid);
            PayPalLog.DeleteByCart(order.OrderGuid);

            // create a final log that has the serialized reposnse from worldpay rather than the serialized cart
            worldPayLog = new PayPalLog();
            worldPayLog.SiteGuid = store.SiteGuid;
            worldPayLog.StoreGuid = store.Guid;
            worldPayLog.CartGuid = order.OrderGuid;
            worldPayLog.UserGuid = order.UserGuid;
            worldPayLog.ProviderName = "WebStoreWorldPayResponseHandler";
            worldPayLog.RequestType = "WorldPay";
            worldPayLog.PaymentStatus = "Paid";
            worldPayLog.PaymentType = "WorldPay";
            worldPayLog.CartTotal = order.OrderTotal;
            worldPayLog.PayPalAmt = wpResponse.AuthAmount;
            worldPayLog.TransactionId = wpResponse.TransId;
            worldPayLog.CurrencyCode = wpResponse.Currency;
            worldPayLog.ReasonCode = wpResponse.AVS;
            worldPayLog.RawResponse = SerializationHelper.SerializeToString(wpResponse);
            worldPayLog.CreatedUtc = DateTime.UtcNow;
            worldPayLog.ReturnUrl = orderDetailUrl;
            worldPayLog.Save();

            try
            {
                StoreHelper.ConfirmOrder(store, order);

            }
            catch (Exception ex)
            {
                log.Error("error sending confirmation email", ex);
            }

            // retrun the html

            if (config.WorldPayProduceShopperResponse)
            {
                CultureInfo currencyCulture = ResourceHelper.GetCurrencyCulture(wpResponse.Currency);

                string htmlTemplate = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, config.WorldPayShopperResponseTemplate);
                StringBuilder finalOutput = new StringBuilder();
                finalOutput.Append(htmlTemplate);
                finalOutput.Replace("#WorldPayBannerToken", "<WPDISPLAY ITEM=banner>"); //required by worldpay
                finalOutput.Replace("#CustomerName", wpResponse.Name);
                finalOutput.Replace("#StoreName", store.Name);
                finalOutput.Replace("#OrderId", order.OrderGuid.ToString());
                finalOutput.Replace("#StorePageLink", "<a href='" + storePageUrl + "'>" + storePageUrl + "</a>");
                finalOutput.Replace("#OrderDetailLink", "<a href='" + orderDetailUrl + "'>" + orderDetailUrl + "</a>");

                StringBuilder orderDetails = new StringBuilder();
                DataSet dsOffers = Order.GetOrderOffersAndProducts(store.Guid, order.OrderGuid);

                foreach (DataRow row in dsOffers.Tables["Offers"].Rows)
                {
                    string og = row["OfferGuid"].ToString();
                    orderDetails.Append(row["Name"].ToString() + " ");
                    orderDetails.Append(row["Quantity"].ToString() + " @ ");
                    orderDetails.Append(string.Format(currencyCulture, "{0:c}", Convert.ToDecimal(row["OfferPrice"])));
                    orderDetails.Append("<br />");

                    string whereClause = string.Format("OfferGuid = '{0}'", og);
                    DataView dv = new DataView(dsOffers.Tables["Products"], whereClause, "", DataViewRowState.CurrentRows);

                    if (dv.Count > 1)
                    {
                        foreach (DataRow r in dsOffers.Tables["Products"].Rows)
                        {
                            string pog = r["OfferGuid"].ToString();
                            if (og == pog)
                            {
                                orderDetails.Append(r["Name"].ToString() + " ");
                                orderDetails.Append(r["Quantity"].ToString() + "  <br />");

                            }

                        }
                    }

                }

                finalOutput.Replace("#OrderDetails", orderDetails.ToString());
                page.Response.Write(finalOutput.ToString());
                page.Response.Flush();

            }
        }
Esempio n. 20
0
        public bool IsValidForCheckout(Cart cart, out ArrayList errorList)
        {
            bool result = true;
            // TODO: implement rule enforcement
            errorList = new ArrayList();

            return result;
        }
Esempio n. 21
0
        /// <summary>
        /// Creates hidden form fields for PayPal Standard Cart upload
        /// </summary>
        /// <returns></returns>
        public static string GetCartUploadFormFields(
            Guid payPalLogGuid,
            Cart cart,
            Store store,
            CommerceConfiguration commerceConfig)
        {
            //TODO: PayPal is not seeing discounts?

            PayPalStandardPaymentGateway gateway
                = new PayPalStandardPaymentGateway(
                    commerceConfig.PayPalStandardUrl,
                    commerceConfig.PayPalStandardEmailAddress,
                    commerceConfig.PayPalStandardPDTId);

            gateway.Amount = cart.OrderTotal;
            gateway.Tax = cart.TaxTotal;
            gateway.Shipping = cart.ShippingTotal;
            gateway.CartDiscount = cart.Discount;

            //Currency currency = new Currency(cart.CurrencyGuid);
            //if (currency.Guid != Guid.Empty)
            //{
            //    gateway.CurrencyCode = currency.Code;
            //}
            //gateway.CurrencyCode = store.DefaultCurrency;
            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
            gateway.CurrencyCode = siteSettings.GetCurrency().Code;

            gateway.OrderHasShippableProducts = cart.HasShippingProducts();
            gateway.ShippingFirstName = cart.OrderInfo.DeliveryFirstName;
            gateway.ShippingLastName = cart.OrderInfo.DeliveryLastName;

            gateway.ShippingAddress1 = cart.OrderInfo.DeliveryAddress1;
            gateway.ShippingAddress2 = cart.OrderInfo.DeliveryAddress2;
            gateway.ShippingCity = cart.OrderInfo.DeliveryCity;
            gateway.ShippingState = cart.OrderInfo.DeliveryState;
            gateway.ShippingPostalCode = cart.OrderInfo.DeliveryPostalCode;

            //add the items
            foreach (CartOffer offer in cart.CartOffers)
            {
                PayPalOrderItem item = new PayPalOrderItem();
                item.Amount = offer.OfferPrice;
                item.ItemName = offer.Name;
                item.ItemNumber = offer.OfferGuid.ToString();
                item.Quantity = offer.Quantity;
                item.Tax = offer.Tax;

                gateway.Items.Add(item);

            }

            gateway.OrderDescription = store.Name + " " + WebStoreResources.OrderHeading;

            gateway.Custom = payPalLogGuid.ToString();

            string siteRoot = SiteUtils.GetNavigationSiteRoot();
            string storePageUrl = SiteUtils.GetCurrentPageUrl();

            gateway.ReturnUrl = siteRoot + "/Services/PayPalPDTHandler.aspx";
            gateway.NotificationUrl = siteRoot + "/Services/PayPalIPNHandler.aspx";
            gateway.CancelUrl = storePageUrl;

            return gateway.GetCartUploadFormFields();
        }
Esempio n. 22
0
        private static PayPalLog CreatePayPalStandardCheckoutLog(
            Cart cart,
            Store store,
            string siteRoot,
            int pageId,
            int moduleId)
        {
            PayPalLog payPalLog = new PayPalLog();

            payPalLog.ProviderName = "WebStorePayPalHandler";
            payPalLog.PDTProviderName = "WebStorePayPalPDTHandlerProvider";
            payPalLog.IPNProviderName = "WebStorePayPalIPNHandlerProvider";
            payPalLog.ReturnUrl = siteRoot +
                                "/WebStore/OrderDetail.aspx?pageid="
                                + pageId.ToInvariantString()
                                + "&mid=" + moduleId.ToInvariantString()
                                + "&orderid=" + cart.CartGuid.ToString();

            payPalLog.RequestType = "StandardCheckout";

            cart.SerializeCartOffers();
            payPalLog.SerializedObject = SerializationHelper.SerializeToString(cart);

            //Currency currency = new Currency(store.DefaultCurrencyId);

            payPalLog.CartGuid = cart.CartGuid;
            //Store store = new Store(cart.StoreGuid);
            payPalLog.SiteGuid = store.SiteGuid;
            payPalLog.StoreGuid = store.Guid;
            payPalLog.UserGuid = cart.UserGuid;
            payPalLog.CartTotal = cart.OrderTotal;
            //payPalLog.CurrencyCode = currency.Code;
            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
            payPalLog.CurrencyCode = siteSettings.GetCurrency().Code;

            payPalLog.Save();

            return payPalLog;
        }
Esempio n. 23
0
        //public static Cart GetCart(Guid storeGuid)
        //{
        //    if (HttpContext.Current != null)
        //    {
        //        string cartKey = "cart" + storeGuid.ToString();
        //        if (HttpContext.Current.Items[cartKey] != null)
        //        {
        //            return (Cart)HttpContext.Current.Items[cartKey];
        //        }
        //        else
        //        {
        //            if (UserHasCartCookie(storeGuid))
        //            {
        //                string cartCookie = GetCartCookie(storeGuid);
        //                if (cartCookie.Length == 36)
        //                {
        //                    Guid cartGuid = new Guid(cartCookie);
        //                    Cart cart = new Cart(cartGuid);
        //                    if (!cart.Exists)
        //                    {
        //                        return CreateCartAndSetCookie(storeGuid);
        //                    }
        //                    HttpContext.Current.Items[cartKey] = cart;
        //                    return cart;
        //                }
        //                else
        //                {
        //                    // cookie is invalid
        //                    return CreateCartAndSetCookie(storeGuid);
        //                }
        //            }
        //            else
        //            {
        //                // TODO: handle use case where user adds to cart on 1 machine
        //                // then comes back to site on another machine and has no cart cookie
        //                // look for a cart that has the userguid,
        //                // if found set cookie for that cart
        //                // new cart
        //                return CreateCartAndSetCookie(storeGuid);
        //            }
        //        }
        //    }
        //    return null;
        //}
        public static void InitializeOrderInfo(Cart cart, SiteUser siteUser)
        {
            if (cart.OrderInfo.CustomerLastName.Length == 0)
            {
                if(siteUser.LastName.Length > 0)
                {
                    cart.OrderInfo.CustomerLastName = siteUser.LastName;
                }
                else
                {
                    cart.OrderInfo.CustomerLastName = siteUser.Name;
                }
                cart.OrderInfo.CustomerFirstName = siteUser.FirstName;

            }
            cart.OrderInfo.CustomerTelephoneDay = siteUser.PhoneNumber;
            cart.OrderInfo.CustomerEmail = siteUser.Email;
            cart.OrderInfo.Save();
            cart.UserGuid = siteUser.UserGuid;
            cart.Save();
        }
Esempio n. 24
0
        // we are using the paypal log with a different request type rather than making a new log specifically for WorldPay
        private static PayPalLog CreateWorldPayCheckoutLog(
            Cart cart,
            Store store,
            string siteRoot,
            string storePageUrl,
            int pageId,
            int moduleId)
        {
            PayPalLog worldPayLog = new PayPalLog();

            worldPayLog.ProviderName = "WebStoreWorldPayResponseHandler";
            worldPayLog.RequestType = "WorldPay";
            worldPayLog.RawResponse = storePageUrl;

            worldPayLog.ReturnUrl = siteRoot +
                                "/WebStore/OrderDetail.aspx?pageid="
                                + pageId.ToInvariantString()
                                + "&mid=" + moduleId.ToInvariantString()
                                + "&orderid=" + cart.CartGuid.ToString();

            cart.SerializeCartOffers();
            worldPayLog.SerializedObject = SerializationHelper.SerializeToString(cart);

            worldPayLog.CartGuid = cart.CartGuid;

            worldPayLog.SiteGuid = store.SiteGuid;
            worldPayLog.StoreGuid = store.Guid;
            worldPayLog.UserGuid = cart.UserGuid;
            worldPayLog.CartTotal = cart.OrderTotal;

            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
            worldPayLog.CurrencyCode = siteSettings.GetCurrency().Code;

            worldPayLog.Save();

            return worldPayLog;
        }
Esempio n. 25
0
        private static Cart CreateCartAndSetCookie(Store store)
        {
            if (store == null) return null;
            if (store.Guid == Guid.Empty) return null;

            string cartKey = "cart" + store.Guid.ToString();
            Cart cart = new Cart();
            cart.StoreGuid = store.Guid;
            cart.CreatedFromIP = SiteUtils.GetIP4Address();

            if (
                (HttpContext.Current != null)
                && (HttpContext.Current.Request.IsAuthenticated)
                )
            {
                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                cart.UserGuid = siteUser.UserGuid;
                cart.LoadExistingUserCartIfExists();

            }
            cart.Save();

            SetCartCookie(store.Guid, cart.CartGuid);
            HttpContext.Current.Items[cartKey] = cart;

            return cart;
        }
Esempio n. 26
0
        private static void VerifyCartUser(Cart cart)
        {
            if (HttpContext.Current == null) { return; }
            if (HttpContext.Current.Request == null) { return; }
            if (cart == null) { return; }
            if (cart.UserGuid == Guid.Empty) { return; }

            if (HttpContext.Current.Request.IsAuthenticated)
            {
                SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                if (currentUser == null)
                {
                    cart.ClearCustomerData();
                    cart.UserGuid = Guid.Empty;
                    cart.OrderInfo.Save();
                    cart.Save();
                }
                else
                {
                    if (currentUser.UserGuid != cart.UserGuid)
                    {
                        cart.ClearCustomerData();
                        cart.OrderInfo.CustomerEmail = currentUser.Email;
                        cart.OrderInfo.CustomerFirstName = currentUser.FirstName;
                        cart.OrderInfo.CustomerLastName = currentUser.LastName;
                        cart.OrderInfo.CustomerTelephoneDay = currentUser.PhoneNumber;
                        cart.UserGuid = currentUser.UserGuid;
                        cart.OrderInfo.Save();
                        cart.Save();

                    }
                }

            }
            else
            {
                cart.UserGuid = Guid.Empty;
                cart.Save();
            }
        }
        private void LoadSettings()
        {
            PageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
            ModuleId = WebUtils.ParseInt32FromQueryString("mid", -1);
            payPalGetExpressCheckoutLogGuid = WebUtils.ParseGuidFromQueryString("plog", payPalGetExpressCheckoutLogGuid);

            if (payPalGetExpressCheckoutLogGuid == Guid.Empty)
            {
                Response.Redirect(SiteUtils.GetCurrentPageUrl());
            }

            checkoutDetailsLog = new PayPalLog(payPalGetExpressCheckoutLogGuid);

            if (checkoutDetailsLog.RowGuid == Guid.Empty)
            {
                Response.Redirect(SiteUtils.GetCurrentPageUrl());
            }

            cart = (Cart)SerializationHelper.DeserializeFromString(typeof(Cart), checkoutDetailsLog.SerializedObject);

            if (cart == null)
            {
                Response.Redirect(SiteUtils.GetCurrentPageUrl());
            }
            cart.DeSerializeCartOffers();

            cart.RefreshTotals();

            if ((cart.LastModified < DateTime.UtcNow.AddDays(-1)) && (cart.DiscountCodesCsv.Length > 0))
            {
                StoreHelper.EnsureValidDiscounts(store, cart);
            }

            siteUser = SiteUtils.GetCurrentSiteUser();
            //if (siteUser == null)
            //{
            //    Response.Redirect(SiteUtils.GetCurrentPageUrl());
            //}

            if ((siteUser != null)&&(cart.UserGuid == Guid.Empty))
            {
                // user wasn't logged in when express checkout was called
                cart.UserGuid = siteUser.UserGuid;
                cart.Save();
                //if (checkoutDetailsLog.UserGuid == Guid.Empty)
                //{
                //    // we need to make sure we have the user in the log and serialized cart
                //    checkoutDetailsLog.UserGuid = siteUser.UserGuid;
                //    cart.SerializeCartOffers();
                //    checkoutDetailsLog.SerializedObject = SerializationHelper.SerializeToSoap(cart);
                //    checkoutDetailsLog.Save();

                //}
            }

            if ((siteUser != null)&&(cart.UserGuid != siteUser.UserGuid))
            {
                Response.Redirect(SiteUtils.GetCurrentPageUrl());
            }

            if (ModuleId == -1)
            {
                ModuleId = StoreHelper.FindStoreModuleId(CurrentPage);
            }

            store = StoreHelper.GetStore();

            commerceConfig = SiteUtils.GetCommerceConfig();
            currencyCulture = ResourceHelper.GetCurrencyCulture(siteSettings.GetCurrency().Code);

            if (siteUser != null)
            {
                pnlRequireLogin.Visible = false;
            }
            else
            {
                btnMakePayment.Visible = false;
            }

            AddClassToBody("webstore webstoreexpresscheckout");
        }
Esempio n. 28
0
        public static void EnsureUserForOrder(Cart cart)
        {
            if (cart == null) { return; }

            //cart already has a valid userGuid
            if (cart.UserGuid != Guid.Empty) { return; }

            if (cart.OrderInfo == null) { return; }
            if (cart.OrderInfo.CustomerEmail.Length == 0) { return; }

            // if cart.UserGuid == Guid.Empty autocreate a user based on the email and customer info
            // this way we can support ordering without register/sign in
            // at least for fulfillmenttypenone and probably for shipped orders
            // for download orders we should make the usersign in first because they will need to login to download

            try
            {
                SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
                if (siteSettings == null) { return; }
                if (siteSettings.SiteGuid == Guid.Empty) { return; }

                bool includeInMemberList = false;

                SiteUser newUser = SiteUtils.CreateMinimalUser(
                    siteSettings,
                    cart.OrderInfo.CustomerEmail,
                    includeInMemberList,
                    WebStoreResources.UserAutoCreatedComment);

                if (newUser != null) { cart.UserGuid = newUser.UserGuid; }
            }
            catch (Exception ex)
            {
                log.Error("Store Helper failed to auto create user for cart/order " + cart.CartGuid.ToString(), ex);
            }
        }
        public override void HandleNewOrderNotificationExtended(
            string requestXml,
            NewOrderNotificationExtended newOrder, 
            MerchantData merchantData)
        {
            //NotificationSerialNumber = newOrder.serialnumber;

            GoogleCheckoutLog gLog = new GoogleCheckoutLog();
            gLog.ProviderName = "WebStoreGCheckoutNotificationHandlerProvider";
            gLog.RawResponse = requestXml;
            gLog.NotificationType = "NewOrderNotification";
            gLog.SerialNumber = newOrder.serialnumber;
            gLog.OrderNumber = newOrder.googleordernumber;
            gLog.OrderTotal = newOrder.ordertotal.Value;
            gLog.BuyerId = newOrder.buyerid.ToString(CultureInfo.InvariantCulture);
            gLog.FullfillState = newOrder.fulfillmentorderstate.ToString();
            gLog.FinanceState = newOrder.financialorderstate.ToString();
            gLog.ShippingTotal = newOrder.ShippingCost;
            gLog.TaxTotal = newOrder.orderadjustment.totaltax.Value;
            //gLog.DiscountTotal = ext.orderadjustment.adjustmenttotal.Value;
            gLog.EmailListOptIn = newOrder.buyermarketingpreferences.emailallowed;
            gLog.GTimestamp = newOrder.timestamp;
            gLog.CartXml = SerializationHelper.RestoreXmlDeclaration(merchantData.SerializedObject);
            gLog.Save();

            Cart gCart = DeserializeCart(merchantData);

            Guid cartGuid = Guid.Empty;
            if (gCart != null)
                cartGuid = gCart.CartGuid;

            if (cartGuid == Guid.Empty) return;

            Cart cart = new Cart(cartGuid);
            if (cart.CartGuid != cartGuid) return;

            Store store = new Store(gCart.StoreGuid);
            if (store.Guid != cart.StoreGuid) return;

            gCart.DeSerializeCartOffers();

            gLog.SiteGuid = store.SiteGuid;
            gLog.UserGuid = gCart.UserGuid;
            gLog.CartGuid = gCart.CartGuid;
            gLog.StoreGuid = gCart.StoreGuid;
            gLog.Save();

            gCart.OrderInfo.CompletedFromIP = SiteUtils.GetIP4Address();

            gCart.OrderInfo.Completed = DateTime.UtcNow;
            if (newOrder.buyerbillingaddress.structuredname != null)
            {
                gCart.OrderInfo.CustomerFirstName = newOrder.buyerbillingaddress.structuredname.firstname;
                gCart.OrderInfo.CustomerLastName = newOrder.buyerbillingaddress.structuredname.lastname;
            }
            else
            {
                gCart.OrderInfo.CustomerFirstName = newOrder.buyerbillingaddress.contactname;
                gCart.OrderInfo.CustomerLastName = newOrder.buyerbillingaddress.contactname;
            }
            gCart.OrderInfo.CustomerEmail = newOrder.buyerbillingaddress.email;
            gCart.OrderInfo.CustomerCompany = newOrder.buyerbillingaddress.companyname;
            gCart.OrderInfo.CustomerAddressLine1 = newOrder.buyerbillingaddress.address1;
            gCart.OrderInfo.CustomerAddressLine2 = newOrder.buyerbillingaddress.address2;
            gCart.OrderInfo.CustomerCity = newOrder.buyerbillingaddress.city;
            gCart.OrderInfo.CustomerState = newOrder.buyerbillingaddress.region;
            gCart.OrderInfo.CustomerCountry = newOrder.buyerbillingaddress.countrycode;
            gCart.OrderInfo.CustomerPostalCode = newOrder.buyerbillingaddress.postalcode;
            gCart.OrderInfo.CustomerTelephoneDay = newOrder.buyerbillingaddress.phone;

            gCart.CopyCustomerToBilling();

            if (newOrder.buyershippingaddress.structuredname != null)
            {
                gCart.OrderInfo.DeliveryFirstName = newOrder.buyershippingaddress.structuredname.firstname;
                gCart.OrderInfo.DeliveryLastName = newOrder.buyershippingaddress.structuredname.lastname;
            }
            else
            {
                gCart.OrderInfo.DeliveryFirstName = newOrder.buyershippingaddress.contactname;
                gCart.OrderInfo.DeliveryLastName = newOrder.buyershippingaddress.contactname;
            }
            gCart.OrderInfo.DeliveryCompany = newOrder.buyershippingaddress.companyname;
            gCart.OrderInfo.DeliveryAddress1 = newOrder.buyershippingaddress.address1;
            gCart.OrderInfo.DeliveryAddress2 = newOrder.buyershippingaddress.address2;
            gCart.OrderInfo.DeliveryCity = newOrder.buyershippingaddress.city;
            gCart.OrderInfo.DeliveryState = newOrder.buyershippingaddress.region;
            gCart.OrderInfo.DeliveryCountry = newOrder.buyershippingaddress.countrycode;
            gCart.OrderInfo.DeliveryPostalCode = newOrder.buyershippingaddress.postalcode;

            gCart.TaxTotal = newOrder.orderadjustment.totaltax.Value;
            if (newOrder.ShippingCost > 0)
            {
                gCart.ShippingTotal = newOrder.ShippingCost;
            }
            gCart.OrderTotal = newOrder.ordertotal.Value;

            Guid orderStatusGuid = OrderStatus.OrderStatusReceivedGuid;

            if (
                (newOrder.financialorderstate == FinancialOrderState.CHARGEABLE)
                || (newOrder.financialorderstate == FinancialOrderState.CHARGED)
                || (newOrder.financialorderstate == FinancialOrderState.CHARGING)
                )
            {
                orderStatusGuid = OrderStatus.OrderStatusFulfillableGuid;

            }

            StoreHelper.EnsureUserForOrder(gCart);

            gCart.Save();

            //Currency currency = new Currency(store.DefaultCurrencyId);
            SiteSettings siteSettings = new SiteSettings(store.SiteGuid);

            Order order = Order.CreateOrder(
                store,
                gCart,
                gLog.RawResponse,
                gLog.OrderNumber,
                string.Empty,
                siteSettings.GetCurrency().Code,
                "GoogleCheckout",
                orderStatusGuid);

            //StoreHelper.ClearCartCookie(cart.StoreGuid);
            if (orderStatusGuid == OrderStatus.OrderStatusFulfillableGuid)
            {
                StoreHelper.ConfirmOrder(store, order);
                PayPalLog.DeleteByCart(order.OrderGuid);

            }

            if (orderStatusGuid == OrderStatus.OrderStatusReceivedGuid)
            {
                StoreHelper.ConfirmOrderReceived(store, order);
            }
        }
Esempio n. 30
0
        public void CalculateTax(Cart cart)
        {
            // TODO: this doesn't take into account discounts

            decimal taxAmount = 0;

            if(cart.OrderInfo.TaxZoneGuid == Guid.Empty)
            {
                GeoCountry country = new GeoCountry(cart.OrderInfo.BillingCountry);
                GeoZone taxZone = GeoZone.GetByCode(country.Guid, cart.OrderInfo.BillingState);
                if (taxZone != null)
                {
                    cart.OrderInfo.TaxZoneGuid = taxZone.Guid;
                }
            }

            if (cart.OrderInfo.TaxZoneGuid != Guid.Empty)
            {
                Collection<TaxRate> taxRates = TaxRate.GetTaxRates(this.SiteGuid, cart.OrderInfo.TaxZoneGuid);
                if (taxRates.Count > 0)
                {
                    foreach (CartOffer offer in cart.CartOffers)
                    {
                        offer.Tax = 0;

                        foreach (TaxRate taxRate in taxRates)
                        {
                            if (offer.TaxClassGuid == taxRate.TaxClassGuid)
                            {
                                offer.Tax += (taxRate.Rate * (offer.OfferPrice * offer.Quantity));
                                offer.Save();
                                taxAmount += offer.Tax;
                                //break;
                            }
                        }
                    }
                }
            }

            cart.TaxTotal = Math.Round(taxAmount, this.RoundingDecimalPlaces, this.RoundingMode);
            if (cart.TaxTotal < 0) { cart.TaxTotal = 0; }
            cart.Save();
        }