Exemplo n.º 1
0
        private void RedirectToSucceedingPage()
        {
            if (_checkOutMode)
            {
                string redirectUrl;

                if (isAnonPayPal)
                {
                    _cart.BuildSalesOrderDetails(false, false);
                    Customer.Current.ThisCustomerSession["paypalfrom"] = "shoppingcart";
                    redirectUrl = PayPalExpress.CheckoutURL(_cart);
                }
                else if (isAnonGoogleCheckout)
                {
                    _cart.BuildSalesOrderDetails(false, false);
                    redirectUrl = GoogleCheckout.CreateGoogleCheckout(_cart);
                }
                else if (AppLogic.AppConfigBool("Checkout.UseOnePageCheckout"))
                {
                    redirectUrl = "checkout1.aspx";
                }
                else
                {
                    redirectUrl = "checkoutshipping.aspx";
                }

                Response.Redirect(redirectUrl);
            }
            else
            {
                Response.Redirect("account.aspx");
            }
        }
Exemplo n.º 2
0
        protected void btnPayPalExpressCheckout_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            if (!ThisCustomer.IsRegistered &&
                (AppLogic.AppConfigBool("PasswordIsOptionalDuringCheckout") && AppLogic.AppConfigBool("PayPalCheckout.AllowAnonCheckout")))
            {
                Response.Redirect("checkoutanon.aspx?checkout=true&checkouttype=pp");
            }
            else
            {
                // Get IS Cart ready
                ProcessCart(false);

                if (cart == null)
                {
                    cart = new InterpriseShoppingCart(base.EntityHelpers, SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, String.Empty, false, true);
                }

                cart.BuildSalesOrderDetails(false, false);

                ThisCustomer.ThisCustomerSession["paypalfrom"] = "shoppingcart";
                Response.Redirect(PayPalExpress.CheckoutURL(cart));
            }
        }
Exemplo n.º 3
0
        protected void btnSignInAndCheckout_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                String EMailField    = EMail.Text.ToLower();
                String PasswordField = Password.Text;

                if (AppLogic.AppConfigBool("SecurityCodeRequiredOnStoreLogin"))
                {
                    String sCode = Session["SecurityCode"].ToString();
                    String fCode = SecurityCode.Text;

                    Boolean codeMatch = false;

                    if (AppLogic.AppConfigBool("Captcha.CaseSensitive"))
                    {
                        if (fCode.Equals(sCode))
                        {
                            codeMatch = true;
                        }
                    }
                    else
                    {
                        if (fCode.Equals(sCode, StringComparison.InvariantCultureIgnoreCase))
                        {
                            codeMatch = true;
                        }
                    }

                    if (!codeMatch)
                    {
                        ErrorMsgLabel.Text     = string.Format(AppLogic.GetString("signin.aspx.22", SkinID, ThisCustomer.LocaleSetting, true), string.Empty, string.Empty);
                        ErrorPanel.Visible     = true;
                        SecurityImage.ImageUrl = "Captcha.ashx?id=1";
                        return;
                    }
                }

                Customer customerWithValidLogin = Customer.FindByLogin(EMail.Text, PasswordField);
                if (null == customerWithValidLogin)
                {
                    ErrorMsgLabel.Text = AppLogic.GetString("signin.aspx.20", SkinID, ThisCustomer.LocaleSetting, true);
                    ErrorPanel.Visible = true;
                    return;
                }

                ThisCustomer.ThisCustomerSession["CustomerID"] = customerWithValidLogin.ContactGUID.ToString();

                AppLogic.ExecuteSigninLogic(ThisCustomer.CustomerCode, ThisCustomer.ContactCode, customerWithValidLogin.CustomerCode, customerWithValidLogin.PrimaryShippingAddressID, customerWithValidLogin.ContactCode);

                string cookieUserName = customerWithValidLogin.ContactGUID.ToString();

                Security.SignOutCrossDomainCookie();
                Security.CreateLoginCookie(cookieUserName, true);

                if (_checkoutType == "pp")
                {
                    var customer = Customer.Find(customerWithValidLogin.ContactGUID);
                    Security.OverrideThisCustomer(customer);

                    if (!cart.IsSalesOrderDetailBuilt)
                    {
                        cart.BuildSalesOrderDetails();
                    }
                    Customer.Current.ThisCustomerSession["paypalFrom"] = "checkoutanon";
                    Response.Redirect(PayPalExpress.CheckoutURL(cart));
                }
                else
                {
                    string sReturnURL = "shoppingcart.aspx";

                    FormPanel.Visible       = false;
                    HeaderPanel.Visible     = false;
                    ExecutePanel.Visible    = true;
                    SignInExecuteLabel.Text = AppLogic.GetString("signin.aspx.2", SkinID, ThisCustomer.LocaleSetting, true);

                    Response.AddHeader("REFRESH", "1; URL=" + Server.UrlDecode(sReturnURL));
                }
            }
        }
Exemplo n.º 4
0
        private void ProcessPayment()
        {
            if (!_cart.IsEmpty())
            {
                var isOutOfStockAndPhaseOut = _cart.CartItems.Any(item => item.Status == "P" && item.IsOutOfStock);
                if (isOutOfStockAndPhaseOut)
                {
                    Response.Redirect("shoppingcart.aspx?resetlinkback=1");
                }
            }

            if (!_isRequirePayment)
            {
                Response.Redirect("checkoutreview.aspx");
            }

            bool isCustomerRegistered            = Customer.Current.IsRegistered;
            bool isCreditCardTokenizationEnabled = IsCreditCardTokenizationEnabled;

            string paymentMethodFromInput   = ctrlPaymentTerm.PaymentMethod;
            string paymentTermCodeFromInput = ctrlPaymentTerm.PaymentTerm;

            #region Payments

            string PAYMENT_METHOD_PAYPALX    = DomainConstants.PAYMENT_METHOD_PAYPALX;
            string PAYMENT_METHOD_CREDITCARD = DomainConstants.PAYMENT_METHOD_CREDITCARD;

            if (_cart.GetOrderBalance() == System.Decimal.Zero && AppLogic.AppConfigBool("SkipPaymentEntryOnZeroDollarCheckout"))
            {
                _cart.MakePaymentTermNotRequired();
            }
            if (paymentTermCodeFromInput.ToString().Trim().Equals("PURCHASE ORDER", StringComparison.InvariantCultureIgnoreCase))
            {
                ThisCustomer.ThisCustomerSession.SetVal("PONumber", ctrlPaymentTerm.PONumber);
            }
            else if (paymentTermCodeFromInput.ToString().Trim().Equals("REQUEST QUOTE", StringComparison.InvariantCultureIgnoreCase))
            {
            }
            else if (paymentMethodFromInput == PAYMENT_METHOD_PAYPALX)
            {
                ThisCustomer.ThisCustomerSession["paypalfrom"] = "checkoutpayment";
                Response.Redirect(PayPalExpress.CheckoutURL(_cart));
            }
            else if (paymentMethodFromInput == PAYMENT_METHOD_CREDITCARD)
            {
                //Validate first the inputs (empty and invalid dropdown selection)
                //triggers the input registered validators.

                if (!IsValid)
                {
                    return;
                }

                //Skip credit card valiation when card is tokenized

                if (!_skipCreditCardValidation)
                {
                    //credit card validation

                    if (!IsValidCreditCardInfo())
                    {
                        return;
                    }
                }

                UpdateAnonForAge13();

                #region Posted Data (Credit Card Information)

                string nameOnCard                = ctrlPaymentTerm.NameOnCard;
                string cardNumberFromInput       = ctrlPaymentTerm.CardNumber;
                string cardTypeFromInput         = ctrlPaymentTerm.CardType;
                string cardExpiryYearFromInput   = ctrlPaymentTerm.CardExpiryYear;
                string cardExpiryMonthFromInput  = ctrlPaymentTerm.CardExpiryMonth;
                string cVVFromInput              = ctrlPaymentTerm.CVV;
                string saveCreditCardAsFromInput = ctrlPaymentTerm.CardDescription;

                string cardStartMonth  = string.Empty;
                string cardStartYear   = string.Empty;
                string cardIssueNumber = string.Empty;

                if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                {
                    cardStartMonth  = ctrlPaymentTerm.CardStartMonth;
                    cardStartYear   = ctrlPaymentTerm.CardStartYear;
                    cardIssueNumber = ctrlPaymentTerm.CardIssueNumber;
                }

                #endregion

                #region Save Billing Address

                var aBillingAddress  = Address.New(ThisCustomer, AddressTypes.Billing);
                var ThisAddress      = Address.New(ThisCustomer, AddressTypes.Shipping);
                var aShippingAddress = ThisCustomer.PrimaryShippingAddress;

                string maskedCardNumber = string.Empty;

                //set the default value of creditCardCode to primary billing address

                string creditCardCode = ThisCustomer.PrimaryBillingAddress.AddressID;

                if (isCustomerRegistered)
                {
                    if (!txtCode.Text.IsNullOrEmptyTrimmed())
                    {
                        //txtCode.Text - Customer CreditCard code
                        //Override the credit card code if tokenization
                        //decrypt the credit card code from the rendered hidden text box since it is encrypted.

                        creditCardCode   = AppLogic.DecryptCreditCardCode(ThisCustomer, txtCode.Text);
                        maskedCardNumber = AppLogic.GetCustomerCreditCardMaskedCardNumber(creditCardCode);
                    }

                    if (maskedCardNumber.StartsWith("X"))
                    {
                        CreditCardDTO credit = null;

                        if (!creditCardCode.IsNullOrEmptyTrimmed())
                        {
                            //set the credit card info using the creditcard code

                            credit = CreditCardDTO.Find(creditCardCode);
                        }

                        //test if the credit card info has been tokenized and saved by the client
                        //if refno > 0 means the credit card has been authorized

                        if (credit.RefNo > 0)
                        {
                            cardNumberFromInput      = credit.CardNumber;
                            nameOnCard               = credit.NameOnCard;
                            cardTypeFromInput        = credit.CardType;
                            cardExpiryMonthFromInput = credit.ExpMonth;
                            cardExpiryYearFromInput  = credit.ExpYear;

                            if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                            {
                                cardStartMonth = credit.StartMonth;
                                cardStartYear  = credit.StartYear;
                            }
                        }
                    }

                    aBillingAddress.Address1   = BillingAddressControl.street;
                    aBillingAddress.Country    = BillingAddressControl.country;
                    aBillingAddress.PostalCode = BillingAddressControl.postal;

                    string bCityStates = txtCityStates.Text;
                    string city        = String.Empty;
                    string state       = String.Empty;

                    var cityStateArray = GetCityStateArray();
                    aBillingAddress.State = cityStateArray[0];
                    aBillingAddress.City  = cityStateArray[1];

                    aBillingAddress.ResidenceType = aShippingAddress.ThisCustomer.PrimaryShippingAddress.ResidenceType;
                    aBillingAddress.Name          = txtBillingContactName.Text;
                    aBillingAddress.Phone         = txtBillingContactNumber.Text;

                    if (AppLogic.AppConfigBool("Address.ShowCounty"))
                    {
                        aBillingAddress.County = BillingAddressControl.county;
                    }
                }
                else
                {
                    var primariBillingAddress = ThisCustomer.PrimaryBillingAddress;
                    aBillingAddress.Address1      = primariBillingAddress.Address1;
                    aBillingAddress.Country       = primariBillingAddress.Country;
                    aBillingAddress.PostalCode    = primariBillingAddress.PostalCode;
                    aBillingAddress.City          = primariBillingAddress.City;
                    aBillingAddress.State         = primariBillingAddress.State;
                    aBillingAddress.ResidenceType = primariBillingAddress.ResidenceType;
                    aBillingAddress.Name          = primariBillingAddress.Name;
                    aBillingAddress.Phone         = primariBillingAddress.Phone;
                    aBillingAddress.EMail         = primariBillingAddress.EMail;
                }

                //Credit card code has default value of primary billing addressid
                //This will be overridden when tokenization

                aBillingAddress.AddressID           = creditCardCode;
                aBillingAddress.CardNumber          = cardNumberFromInput;
                aBillingAddress.CardName            = nameOnCard;
                aBillingAddress.CardType            = cardTypeFromInput;
                aBillingAddress.CardExpirationMonth = cardExpiryMonthFromInput;
                aBillingAddress.CardExpirationYear  = cardExpiryYearFromInput;
                aBillingAddress.CustomerCode        = ThisCustomer.CustomerCode;

                //Try save the new billing address if anonymous
                //if registered the billing will not be created

                aBillingAddress.Save();

                //update the address if user is registered and is already exist

                Address.Update(ThisCustomer, aBillingAddress);

                #endregion

                if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                {
                    //-> Some CCs do not have StartDate, so here we should provide Default if none was supplied.

                    string defaultCardStartMonth = DateTime.Now.Month.ToString();
                    string defaultCardStartYear  = DateTime.Now.Year.ToString();

                    aBillingAddress.CardStartMonth  = (cardStartMonth != "MONTH")? cardStartMonth: defaultCardStartMonth;
                    aBillingAddress.CardStartYear   = (cardStartYear != "YEAR")? cardStartYear : defaultCardStartYear;
                    aBillingAddress.CardIssueNumber = cardIssueNumber;
                }

                //-> Capture the credit card number from the payment page and encrypt it so that the gateway can capture from that credit card

                if (!cardNumberFromInput.StartsWith("X"))
                {
                    string salt          = String.Empty;
                    string iv            = String.Empty;
                    string cardNumberEnc = AppLogic.EncryptCardNumber(cardNumberFromInput, ref salt, ref iv);
                    AppLogic.StoreCardNumberInSession(ThisCustomer, cardNumberEnc, salt, iv);
                }

                if (isCreditCardTokenizationEnabled)
                {
                    InterpriseHelper.MakeDefaultAddress(ThisCustomer.ContactCode, creditCardCode, AddressTypes.Billing);

                    bool saveCreditCardInfo = (AppLogic.AppConfigBool("ForceCreditCardInfoSaving") || ctrlPaymentTerm.SaveCreditCreditCardInfo);
                    ThisCustomer.ThisCustomerSession["SaveCreditCardChecked"] = saveCreditCardInfo.ToString();

                    #region "Update Address w/ CreditCardInfo"

                    string thisCardNumber = Interprise.Framework.Base.Shared.Common.MaskCardNumber(aBillingAddress.CardNumber);

                    if (!maskedCardNumber.IsNullOrEmptyTrimmed())
                    {
                        thisCardNumber = maskedCardNumber;
                    }

                    #region Postal Code Handler

                    var    parsedPostalCode = InterpriseHelper.ParsePostalCode(aBillingAddress.Country, aBillingAddress.PostalCode);
                    string postal           = parsedPostalCode.PostalCode;
                    int    plus4            = parsedPostalCode.Plus4;

                    #endregion

                    var sql = new StringBuilder();

                    sql.Append(" UPDATE CustomerCreditCard ");
                    sql.AppendFormat(" SET CreditCardDescription = {0}, MaskedCardNumber = {1}, NameOnCard = {2}, ", saveCreditCardAsFromInput.ToDbQuote(), thisCardNumber.ToDbQuote(), nameOnCard.ToDbQuote());
                    sql.AppendFormat(" Address = {0}, City = {1}, State={2}, ", aBillingAddress.Address1.ToDbQuote(), aBillingAddress.City.ToDbQuote(), aBillingAddress.State.ToDbQuote());

                    if (plus4 == 0)
                    {
                        sql.AppendFormat(" PostalCode = {0}, Country = {1}, Plus4=NULL, ", postal.ToDbQuote(), aBillingAddress.Country.ToDbQuote());
                    }
                    else
                    {
                        sql.AppendFormat(" PostalCode = {0}, Country = {1}, Plus4={2}, ", postal.ToDbQuote(), aBillingAddress.Country.ToDbQuote(), plus4);
                    }

                    sql.AppendFormat(" ExpMonth={0}, ExpYear={1}, Telephone={2}, ", InterpriseHelper.ToInterpriseExpMonth(aBillingAddress.CardExpirationMonth).ToDbQuote(), aBillingAddress.CardExpirationYear.ToDbQuote(), aBillingAddress.Phone.ToDbQuote());
                    sql.AppendFormat(" CreditCardType = {0}, DateModified=getdate() ", aBillingAddress.CardType.ToDbQuote());

                    sql.AppendFormat(" WHERE CreditCardCode={0} ", creditCardCode.ToDbQuote());

                    DB.ExecuteSQL(sql.ToString());
                    sql.Clear();

                    #endregion

                    DB.ExecuteSQL(@"UPDATE Customer SET Creditcardcode={0} WHERE CustomerCode={1}", DB.SQuote(creditCardCode), DB.SQuote(ThisCustomer.CustomerCode));

                    AppLogic.ClearCreditCardCodeInSession(ThisCustomer);
                }
                else
                {
                    if (ThisCustomer.IsRegistered)
                    {
                        Address.Update(ThisCustomer, aBillingAddress);
                        InterpriseHelper.MakeDefaultAddress(ThisCustomer.ContactCode, creditCardCode, AddressTypes.Billing);
                    }
                }

                AppLogic.StoreCardExtraCodeInSession(ThisCustomer, cVVFromInput);
                AppLogic.SavePostalCode(aBillingAddress);

                //Redirect to Confirmation Page
            }

            InterpriseHelper.UpdateCustomerPaymentTerm(ThisCustomer, paymentTermCodeFromInput);
            Response.Redirect("checkoutreview.aspx");

            #endregion
        }
Exemplo n.º 5
0
        protected void btnCompletePurchase_Click(object sender, EventArgs e)
        {
            if (!this.IsValid)
            {
                return;
            }

            if (_weShouldRequirePayment)
            {
                if (ctrlPaymentTerm.PaymentTerm.ToString().Trim().Equals("PURCHASE ORDER", StringComparison.InvariantCultureIgnoreCase))
                {
                    ThisCustomer.ThisCustomerSession.SetVal("PONumber", ctrlPaymentTerm.PONumber);
                }
                else if (ctrlPaymentTerm.PaymentTerm.ToString().Trim().Equals("REQUEST QUOTE", StringComparison.InvariantCultureIgnoreCase))
                {
                }
                else if (ctrlPaymentTerm.PaymentMethod == DomainConstants.PAYMENT_METHOD_PAYPALX)
                {
                    ThisCustomer.ThisCustomerSession["paypalfrom"] = "checkoutpayment";
                    Response.Redirect(PayPalExpress.CheckoutURL(_cart));
                }
                else if (ctrlPaymentTerm.PaymentMethod == DomainConstants.PAYMENT_METHOD_CREDITCARD)
                {
                    //Validate Card Number
                    bool   blnCcInvalid = false;
                    string cardNumber;
                    string cardNumberInvalidErrorMessage;

                    var ccValidator = new CreditCardValidator();
                    ccValidator.AcceptedCardTypes = ctrlPaymentTerm.CardType;
                    if (ccValidator.AcceptedCardTypes.Contains("0"))
                    {
                        ctrlPaymentTerm.CardTypeInvalidErrorMessage = AppLogic.GetString("checkout1.aspx.14", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                        errorSummary.DisplayErrorMessage(ctrlPaymentTerm.CardTypeInvalidErrorMessage);
                        return;
                    }

                    //See if we should use the card number on file.
                    //We also want to see if the card number starts with an *.
                    //If it doesn't it probably means the user entered a new number.
                    if (ctrlPaymentTerm.CardNumber.StartsWith("*"))
                    {
                        //Get the stored card number.
                        cardNumber = ThisCustomer.PrimaryBillingAddress.CardNumber;
                        cardNumberInvalidErrorMessage = ctrlPaymentTerm.StoredCardNumberInvalidErrorMessage;
                    }
                    else
                    {
                        //Get the card number the user entered.
                        cardNumber = ctrlPaymentTerm.CardNumber;
                        cardNumberInvalidErrorMessage = ctrlPaymentTerm.CardNumberInvalidErrorMessage;
                    }

                    if (!ccValidator.IsValidCardType(cardNumber) || !ccValidator.ValidateCardNumber(cardNumber))
                    {
                        errorSummary.DisplayErrorMessage(cardNumberInvalidErrorMessage);
                        blnCcInvalid = true;
                    }

                    //Validate Expiration Date
                    if (!ccValidator.IsValidExpirationDate(string.Concat(ctrlPaymentTerm.CardExpiryYear, ctrlPaymentTerm.CardExpiryMonth)))
                    {
                        ctrlPaymentTerm.ExpirationMonthInvalidErrorMessage = AppLogic.GetString("checkout1.aspx.15", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                        ctrlPaymentTerm.ExpirationYearInvalidErrorMessage  = AppLogic.GetString("checkout1.aspx.16", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                        errorSummary.DisplayErrorMessage(ctrlPaymentTerm.ExpirationMonthInvalidErrorMessage);
                        errorSummary.DisplayErrorMessage(ctrlPaymentTerm.ExpirationYearInvalidErrorMessage);
                        blnCcInvalid = true;
                    }

                    //If an error was found display them
                    if (blnCcInvalid)
                    {
                        return;
                    }

                    var billingAddress = ThisCustomer.PrimaryBillingAddress;
                    billingAddress.CardNumber = cardNumber;

                    billingAddress.CardName            = ctrlPaymentTerm.NameOnCard;
                    billingAddress.CardType            = ctrlPaymentTerm.CardType;
                    billingAddress.CardExpirationMonth = ctrlPaymentTerm.CardExpiryMonth;
                    billingAddress.CardExpirationYear  = ctrlPaymentTerm.CardExpiryYear;

                    if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                    {
                        //Some CCs do not have StartDate, so here we should provide Default if none was supplied.
                        string defaultCardStartMonth = DateTime.Now.Month.ToString();
                        string defaultCardStartYear  = DateTime.Now.Year.ToString();

                        billingAddress.CardStartMonth = CommonLogic.IIF(ctrlPaymentTerm.CardStartMonth != "MONTH", ctrlPaymentTerm.CardStartMonth, defaultCardStartMonth);
                        billingAddress.CardStartYear  = CommonLogic.IIF(ctrlPaymentTerm.CardStartYear != "YEAR", ctrlPaymentTerm.CardStartYear, defaultCardStartYear);

                        billingAddress.CardIssueNumber = ctrlPaymentTerm.CardIssueNumber;
                    }

                    AppLogic.StoreCardExtraCodeInSession(ThisCustomer, ctrlPaymentTerm.CVV);

                    //Capture the credit card number from the payment page and encrypt it so that the gateway can capture from that credit card
                    string salt          = null;
                    string iv            = null;
                    string cardNumberEnc = AppLogic.EncryptCardNumber(cardNumber, ref salt, ref iv);
                    AppLogic.StoreCardNumberInSession(ThisCustomer, cardNumberEnc, salt, iv);

                    Address.Update(ThisCustomer, billingAddress);
                }

                InterpriseHelper.UpdateCustomerPaymentTerm(ThisCustomer, ctrlPaymentTerm.PaymentTerm);
            }
            Response.Redirect("checkoutreview.aspx");
        }