Example #1
0
        private bool IsValidCreditCardInfo()
        {
            var ccValidator = new CreditCardValidator();

            //-> Validate Expiration Date
            if (!ccValidator.IsValidExpirationDate(string.Concat(ctrlPaymentTerm.CardExpiryYear, ctrlPaymentTerm.CardExpiryMonth)))
            {
                errorSummary.DisplayErrorMessage(ctrlPaymentTerm.ExpirationMonthInvalidErrorMessage);
                errorSummary.DisplayErrorMessage(ctrlPaymentTerm.ExpirationYearInvalidErrorMessage);
                return(false);
            }

            ccValidator.AcceptedCardTypes = ctrlPaymentTerm.CardType;

            if (ccValidator.AcceptedCardTypes.Contains("0"))
            {
                errorSummary.DisplayErrorMessage(ctrlPaymentTerm.CardTypeInvalidErrorMessage);
                return(false);
            }

            string cardNumber = ctrlPaymentTerm.CardNumber;

            if (((!ccValidator.IsValidCardType(cardNumber) || !ccValidator.ValidateCardNumber(cardNumber))))
            {
                errorSummary.DisplayErrorMessage(ctrlPaymentTerm.CardNumberInvalidErrorMessage);
                return(false);
            }

            return(true);
        }
Example #2
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");
        }