protected void SaveCardButton_Click(object sender, EventArgs e)
        {
            int   profileId             = AlwaysConvert.ToInt(HiddenProfileId.Value);
            Label ProfileSuccessMessage = (Label)PageHelper.RecursiveFindControl(Page, "ProfileSuccessMessage");
            Label ProfileErrorMessage   = (Label)PageHelper.RecursiveFindControl(Page, "ProfileErrorMessage");

            if (profileId > 0)
            {
                var profile = GatewayPaymentProfileDataSource.Load(profileId);
                if (profile != null)
                {
                    int            gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(profile.GatewayIdentifier);
                    PaymentGateway gateway   = PaymentGatewayDataSource.Load(gatewayId);

                    if (gateway != null)
                    {
                        var provider = gateway.GetInstance();
                        try
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountNumber"]   = "XXX" + profile.ReferenceNumber.Replace("x", "X");
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            PaymentMethod         method = PaymentMethodDataSource.Load(profile.InstrumentTypeId);
                            PaymentInstrumentData instr  = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                            var rsp = provider.DoUpdatePaymentProfile(new CommerceBuilder.Payments.Providers.UpdatePaymentProfileRequest(AbleContext.Current.User, instr, profile.CustomerProfileId, profile.PaymentProfileId));
                            if (rsp.Successful || rsp.ResponseCode == "E00040")
                            {
                                int id = profile.Id;
                                profile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                profile.Save();
                                if (ProfileSuccessMessage != null)
                                {
                                    ProfileSuccessMessage.Text    = string.Format("Profile '{0} ending in {1}' updated successfully!", profile.InstrumentType, profile.ReferenceNumber);
                                    ProfileSuccessMessage.Visible = true;
                                    ProfileErrorMessage.Visible   = false;
                                }
                            }
                            else
                            {
                                if (ProfileErrorMessage != null)
                                {
                                    ProfileErrorMessage.Text      = string.Format("Somthing went wrong! Unable to update profile '{0} ending in {1}'", profile.InstrumentType, profile.ReferenceNumber);
                                    ProfileSuccessMessage.Visible = false;
                                    ProfileErrorMessage.Visible   = true;
                                }

                                Logger.Error(rsp.ResponseMessage);
                            }
                        }
                        catch (Exception exp)
                        {
                            Logger.Error(exp.Message);
                        }
                    }
                }
            }
            EditCardInfoPopUp.Hide();
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method != null)
            {
                Caption.Text = string.Format(Caption.Text, method.Name);
            }
            else
            {
                this.Controls.Clear();
                Trace.Write(this.GetType().ToString(), "Output suppressed, invalid payment method provided.");
            }

            PayPalButton.ImageUrl = Request.Url.Scheme + "://www.paypal.com/en_US/i/btn/x-click-but1.gif";

            StringBuilder submitScript = new StringBuilder();

            submitScript.Append("if(document.getElementById('" + FormIsSubmitted.ClientID + "').value==1 || Page_ClientValidate('PayPal') == false) { return false; } ");
            submitScript.Append("this.disabled = true; ");
            submitScript.Append("document.getElementById('" + FormIsSubmitted.ClientID + "').value=1;");
            //GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.
            submitScript.Append(Page.ClientScript.GetPostBackEventReference(PayPalButton, string.Empty));
            submitScript.Append(";");
            submitScript.Append("return false;");
            this.PayPalButton.Attributes.Add("onclick", submitScript.ToString());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _PaymentMethod = PaymentMethodDataSource.Load(this.PaymentMethodId);
            if (_PaymentMethod != null)
            {
                UpdateValidationOptions();
                CheckButton.Text = string.Format(CheckButton.Text, _PaymentMethod.Name);
                if (!Page.IsPostBack)
                {
                    AccountHolder.Text = AbleContext.Current.User.PrimaryAddress.FullName;
                }
                trAmount.Visible = AllowPartialPayments();
                DisableAutoComplete();

                // UPDATE MAX PAYMENT AMOUNT TO ORDER TOTAL IF NO VALUE IS SPECIFIED
                if (this.MaxPaymentAmount == 0)
                {
                    this.MaxPaymentAmount = AbleContext.Current.User.Basket.Items.TotalPrice();
                }
            }
            else
            {
                this.Controls.Clear();
            }
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _PaymentMethod = PaymentMethodDataSource.Load(this.PaymentMethodId);
            if (_PaymentMethod != null)
            {
                UpdateValidationOptions();
                CheckButton.Text = string.Format(CheckButton.Text, _PaymentMethod.Name);
                if (!Page.IsPostBack)
                {
                    AccountHolder.Text = AbleContext.Current.User.PrimaryAddress.FullName;
                }
                trAmount.Visible = AllowPartialPayments();
                DisableAutoComplete();

                // javascript to close the help popup when clicked on background
                string jsClosePopup = "window.onload = function() { var popup = $find('PnlHelpPopup'); if(popup) popup._backgroundElement.onclick = function() { $find('PnlHelpPopup').hide(); }};";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "jsClosePopup", jsClosePopup, true);

                // UPDATE MAX PAYMENT AMOUNT TO ORDER TOTAL IF NO VALUE IS SPECIFIED
                if (this.MaxPaymentAmount == 0)
                {
                    this.MaxPaymentAmount = AbleContext.Current.User.Basket.Items.TotalPrice();
                }
            }
            else
            {
                this.Controls.Clear();
            }
        }
예제 #5
0
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         PaymentMethod _PaymentMethod = PaymentMethodDataSource.Load(PaymentMethodId);
         _PaymentMethod.Name = Name.Text;
         _PaymentMethod.PaymentInstrumentType = (PaymentInstrumentType)AlwaysConvert.ToInt16(PaymentInstrumentList.SelectedValue);
         _PaymentMethod.PaymentGateway        = PaymentGatewayDataSource.Load(AlwaysConvert.ToInt(GatewayList.SelectedValue));
         _PaymentMethod.AllowSubscriptions    = AllowSubscriptionPayments.Checked;
         //GROUP RESTRICTION
         _PaymentMethod.Groups.Clear();
         _PaymentMethod.Save();
         if (UseGroupRestriction.SelectedIndex > 0)
         {
             foreach (ListItem item in GroupList.Items)
             {
                 Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                 if (item.Selected)
                 {
                     _PaymentMethod.Groups.Add(group);
                 }
             }
         }
         _PaymentMethod.Save();
         //TRIGER ANY EVENT ATTACHED TO THE UPDATE
         if (ItemUpdated != null)
         {
             ItemUpdated(this, new PersistentItemEventArgs(PaymentMethodId, _PaymentMethod.Name));
         }
     }
 }
예제 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            trAmount.Visible = this.AllowAmountEntry;
            DisableAutoComplete();

            // PREVENT DOUBLE POSTING
            StringBuilder submitScript = new StringBuilder();

            submitScript.Append("if(document.getElementById('" + FormIsSubmitted.ClientID + "').value==1 || Page_ClientValidate('CreditCard') == false) { return false; } ");
            submitScript.Append("this.disabled = true; ");
            submitScript.Append("document.getElementById('" + FormIsSubmitted.ClientID + "').value=1;");
            //GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.
            submitScript.Append(Page.ClientScript.GetPostBackEventReference(CreditCardButton, string.Empty));
            submitScript.Append(";");
            submitScript.Append("return false;");
            this.CreditCardButton.Attributes.Add("onclick", submitScript.ToString());

            if (Page.IsPostBack)
            {
                // VALIDATE IF CORRECT PAYMENT METHOD TYPE IS SELECTED
                PaymentMethod paymentMethod = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                if (paymentMethod != null)
                {
                    // INITIALIZE SELECTED CARD TYPE FOR VALIDATION
                    PaymentInstrumentType paymentInstrumentType = paymentMethod.PaymentInstrumentType;
                    CardNumberValidator1.AcceptedCardType = paymentInstrumentType.ToString();
                }
            }
        }
예제 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (AbleContext.Current.Store.Settings.EnablePaymentProfilesStorage)
            {
                if (!Page.IsPostBack && !_user.IsAnonymous)
                {
                    var profiles = _user.PaymentProfiles
                                   .Where(p => (!p.LastDayOfExpiry.HasValue || p.LastDayOfExpiry > LocaleHelper.LocalNow) &&
                                          PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(p.GatewayIdentifier) > 0)
                                   .ToDictionary(p => p.Id, p => string.Format("{0} ending in {1}", p.InstrumentType, p.ReferenceNumber));

                    if (profiles.Count > 0)
                    {
                        CardPH.Visible     = false;
                        ProfilesPH.Visible = true;
                        profiles.Add(-1, "Add New Payment");
                        ProfilesList.Items.Clear();
                        foreach (var profile in profiles)
                        {
                            ProfilesList.Items.Add(new ListItem()
                            {
                                Text = profile.Value, Value = profile.Key.ToString()
                            });
                        }
                        ListItem item = ProfilesList.Items.FindByValue(_user.Settings.DefaultPaymentProfileId.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                    else
                    {
                        CardPH.Visible     = true;
                        ProfilesPH.Visible = false;
                    }
                }

                CardType.AutoPostBack = true;
            }

            // UPDATE MAX PAYMENT AMOUNT TO ORDER TOTAL IF NO VALUE IS SPECIFIED
            if (this.MaxPaymentAmount == 0)
            {
                this.MaxPaymentAmount = AbleContext.Current.User.Basket.Items.TotalPrice();
            }

            if (Page.IsPostBack)
            {
                // VALIDATE IF CORRECT PAYMENT METHOD TYPE IS SELECTED
                PaymentMethod paymentMethod = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                if (paymentMethod != null)
                {
                    // INITIALIZE SELECTED CARD TYPE FOR VALIDATION
                    PaymentInstrumentType paymentInstrumentType = paymentMethod.PaymentInstrumentType;
                    CardNumberValidator1.AcceptedCardType = paymentInstrumentType.ToString();
                }
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            DisableAutoComplete();
            trAmount.Visible = AllowPartialPayments();
            string eTarget = Request.Form["__EVENTTARGET"] as string;

            if (trAmount.Visible && (string.IsNullOrEmpty(Amount.Text) || CreditCardButton.UniqueID != eTarget))
            {
                Amount.Text = GetPaymentAmount().ToString("F2");
            }

            bool            hasSubscriptions = HasRecurringSubscriptions();
            List <ListItem> itemsToUse       = new List <ListItem>();

            foreach (ListItem item in CardType.Items)
            {
                int id = AlwaysConvert.ToInt(item.Value);
                if (id == 0)
                {
                    continue;
                }

                var method = _methods.Where(m => m.Id == id).SingleOrDefault();
                if (method != null && IsPaymentMethodAllowed(method, hasSubscriptions))
                {
                    itemsToUse.Add(item);
                }
            }
            CardType.Items.Clear();
            CardType.Items.AddRange(itemsToUse.ToArray());

            bool showSaveCard = false;

            if (AbleContext.Current.Store.Settings.EnablePaymentProfilesStorage && !AbleContext.Current.User.IsAnonymousOrGuest)
            {
                PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                if (method != null && method.PaymentGateway != null)
                {
                    var provider = method.PaymentGateway.GetInstance();
                    showSaveCard = (provider.SupportedTransactions & SupportedTransactions.RecurringBillingProfileManaged) == SupportedTransactions.RecurringBillingProfileManaged;
                }
            }

            // IF SUBSCRIPTION IS BEING PURCHASED WITH RECURRING ORDERS ENABLED, SYSTEM MUST NEED TO SAVE THE PROFILE
            if (showSaveCard && AbleContext.Current.Store.Settings.ROCreateNewOrdersEnabled)
            {
                showSaveCard = !AbleContext.Current.User.Basket.Items.HasSubscriptions();
            }

            trSaveCard.Visible = showSaveCard;

            if (NeedsPaymentProfiles())
            {
                CreditCardButton.Visible = false;
                CompleteButton.Visible   = true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method == null)
            {
                AmazonButton.Visible = false;
            }

            AmazonButton.ValidationGroup = ValidationGroup;
        }
예제 #10
0
        private bool CustomValidation()
        {
            bool hasErrors = false;

            //if intl instructions are visible, we must validate additional rules
            if (trIntlInstructions.Visible)
            {
                PaymentMethod m = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                if (m != null)
                {
                    if (m.IsIntlDebitCard())
                    {
                        // INTERNATIONAL DEBIT CARD, ISSUE NUMBER OR START DATE REQUIRED
                        bool invalidIssueNumber = (!Regex.IsMatch(IssueNumber.Text, "\\d{1,2}"));
                        bool invalidStartDate = ((StartDateMonth.SelectedIndex == 0) || (StartDateYear.SelectedIndex == 0));
                        if (invalidIssueNumber && invalidStartDate)
                        {
                            IntlDebitValidator1.IsValid = false;
                            IntlDebitValidator2.IsValid = false;
                            hasErrors = true;
                        }
                        // CHECK START DATE IS IN PAST
                        int selYear = AlwaysConvert.ToInt(StartDateYear.SelectedValue);
                        int curYear = DateTime.Now.Year;
                        if (selYear > curYear)
                        {
                            StartDateValidator1.IsValid = false;
                            hasErrors = true;
                        }
                        else if (selYear == curYear)
                        {
                            int selMonth = AlwaysConvert.ToInt(StartDateMonth.SelectedValue);
                            int curMonth = DateTime.Now.Month;
                            if (selMonth > curMonth)
                            {
                                StartDateValidator1.IsValid = false;
                                hasErrors = true;
                            }
                        }
                    }
                    else
                    {
                        // CREDIT CARD, CVV IS REQUIRED
                        if (!Regex.IsMatch(SecurityCode.Text, "\\d{3,4}"))
                        {
                            SecurityCodeValidator2.IsValid = false;
                            hasErrors = true;
                        }
                    }
                }
            }

            return !hasErrors;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method != null)
            {
                PhoneCallButton.Text          = string.Format(PhoneCallButton.Text, method.Name);
                PhoneCallButton.OnClientClick = "if (Page_ClientValidate('" + this.ValidationGroup + "')) { this.value='Processing...';this.onclick=function(){return false;}; }";
            }
            else
            {
                this.Controls.Clear();
            }
        }
예제 #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method != null)
            {
                PayPalButton.ImageUrl      = Request.Url.Scheme + "://www.paypal.com/en_US/i/btn/x-click-but1.gif";
                PayPalButton.OnClientClick = "if (Page_ClientValidate('" + this.ValidationGroup + "')) { this.onclick=function(){return false;};}";
            }
            else
            {
                this.Controls.Clear();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method != null)
            {
                Caption.Text    = string.Format(Caption.Text, method.Name);
                MailButton.Text = string.Format(MailButton.Text, method.Name);
            }
            else
            {
                this.Controls.Clear();
                Trace.Write(this.GetType().ToString(), "Output suppressed, invalid payment method provided.");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method != null)
            {
                PurchaseOrderButton.Text          = string.Format(PurchaseOrderButton.Text, method.Name);
                PurchaseOrderButton.OnClientClick = "if (Page_ClientValidate('" + this.ValidationGroup + "')) { this.onclick=function(){return false;}; }";
                PurchaseOrderNumber.Attributes.Add("autocomplete", "off");
            }
            else
            {
                this.Controls.Clear();
            }
        }
예제 #15
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.PaymentMethod = PaymentMethodDataSource.Load(this.PaymentMethodId);
            if (this.PaymentAmount > 0)
            {
                payment.Amount = this.PaymentAmount;
            }
            else
            {
                payment.Amount = AbleContext.Current.User.Basket.Items.TotalPrice();
            }
            return(payment);
        }
예제 #16
0
        public void LoadDialog(int paymentMethodId)
        {
            PaymentMethodId = paymentMethodId;
            PaymentMethod _PaymentMethod = PaymentMethodDataSource.Load(PaymentMethodId);

            BindPaymentInstrumentList(_PaymentMethod);
            Name.Text = _PaymentMethod.Name;
            BindGatewayList(_PaymentMethod);
            AllowSubscriptionPayments.Checked = _PaymentMethod.AllowSubscriptions;
            UseGroupRestriction.SelectedIndex = (_PaymentMethod.Groups.Count == 0) ? 0 : 1;
            BindGroups();

            // trAllowSubscriptionPayments.Visible = AbleContext.Current.Store.Settings.ROCreateNewOrdersEnabled;
            refStar.Visible   = !AbleContext.Current.Store.Settings.ROCreateNewOrdersEnabled;
            refStarTr.Visible = refStar.Visible;
        }
예제 #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PaymentMethod method = PaymentMethodDataSource.Load(this.PaymentMethodId);

            if (method != null)
            {
                Caption.Text             = string.Format(Caption.Text, method.Name);
                PurchaseOrderButton.Text = string.Format(PurchaseOrderButton.Text, method.Name);
            }
            else
            {
                this.Controls.Clear();
                Trace.Write(this.GetType().ToString(), "Output suppressed, invalid payment method provided.");
            }
            // DISABLE AUTOCOMPLETE
            PurchaseOrderNumber.Attributes.Add("autocomplete", "off");
        }
예제 #18
0
        protected void PaymentMethodGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int           paymentMethodId = (int)PaymentMethodGrid.DataKeys[e.NewEditIndex].Value;
            PaymentMethod paymentMethod   = PaymentMethodDataSource.Load(paymentMethodId);

            if (paymentMethod != null)
            {
                AddPanel.Visible  = false;
                EditPanel.Visible = true;
                EditCaption.Text  = string.Format(EditCaption.Text, paymentMethod.Name);
                AbleCommerce.Admin.Payment.EditPaymentMethodDialog editDialog = EditPanel.FindControl("EditPaymentMethodDialog1") as AbleCommerce.Admin.Payment.EditPaymentMethodDialog;
                if (editDialog != null)
                {
                    editDialog.LoadDialog(paymentMethodId);
                }
                UpdatePanel1.Update();
            }
        }
예제 #19
0
        protected void BindGroups()
        {
            PaymentMethod _PaymentMethod = PaymentMethodDataSource.Load(PaymentMethodId);

            GroupListPanel.Visible = (UseGroupRestriction.SelectedIndex > 0);
            if (GroupListPanel.Visible)
            {
                GroupList.DataSource = GroupDataSource.LoadAll("Name");
                GroupList.DataBind();
                foreach (Group r in _PaymentMethod.Groups)
                {
                    ListItem item = GroupList.Items.FindByValue(r.Id.ToString());
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }
        }
예제 #20
0
 protected void Page_Load(object sender, EventArgs e)
 {
     _PaymentMethod = PaymentMethodDataSource.Load(this.PaymentMethodId);
     if (_PaymentMethod != null)
     {
         Caption.Text     = string.Format(Caption.Text, _PaymentMethod.Name);
         CheckButton.Text = string.Format(CheckButton.Text, _PaymentMethod.Name);
         if (!Page.IsPostBack)
         {
             AccountHolder.Text = _User.PrimaryAddress.FullName;
         }
         trAmount.Visible = this.AllowAmountEntry;
         DisableAutoComplete();
     }
     else
     {
         this.Controls.Clear();
         Trace.Write(this.GetType().ToString(), "Output suppressed, invalid payment method provided.");
     }
 }
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.PaymentMethod = PaymentMethodDataSource.Load(this.PaymentMethodId);
            if (this.PaymentAmount > 0)
            {
                payment.Amount = this.PaymentAmount;
            }
            else
            {
                payment.Amount = AbleContext.Current.User.Basket.Items.TotalPrice();
            }
            AccountDataDictionary instrumentBuilder = new AccountDataDictionary();

            PurchaseOrderNumber.Text = StringHelper.StripHtml(PurchaseOrderNumber.Text);
            instrumentBuilder["PurchaseOrderNumber"] = PurchaseOrderNumber.Text;
            payment.ReferenceNumber = PurchaseOrderNumber.Text;
            payment.AccountData     = instrumentBuilder.ToString();
            return(payment);
        }
        private Payment GetPayment()
        {
            Payment payment = new Payment();

            payment.Amount = GetPaymentAmount(true);

            if (ProfilesPH.Visible)
            {
                var profile = GatewayPaymentProfileDataSource.Load(AlwaysConvert.ToInt(ProfilesList.SelectedValue));
                payment.PaymentProfile    = profile;
                payment.ReferenceNumber   = profile.ReferenceNumber;
                payment.PaymentMethodName = profile.PaymentMethodName;
            }
            else
            {
                payment.PaymentMethod = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                AccountDataDictionary instrumentBuilder = new AccountDataDictionary();
                instrumentBuilder["AccountName"]     = CardName.Text;
                instrumentBuilder["AccountNumber"]   = CardNumber.Text;
                instrumentBuilder["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                instrumentBuilder["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                instrumentBuilder["SecurityCode"]    = SecurityCode.Text;
                if (payment.PaymentMethod.IsIntlDebitCard())
                {
                    if (IssueNumber.Text.Length > 0)
                    {
                        instrumentBuilder["IssueNumber"] = IssueNumber.Text;
                    }
                    if ((StartDateMonth.SelectedIndex > 0) && (StartDateYear.SelectedIndex > 0))
                    {
                        instrumentBuilder["StartDateMonth"] = StartDateMonth.SelectedItem.Value;
                        instrumentBuilder["StartDateYear"]  = StartDateYear.SelectedItem.Value;
                    }
                }
                payment.ReferenceNumber = Payment.GenerateReferenceNumber(CardNumber.Text);
                payment.AccountData     = instrumentBuilder.ToString();
            }

            return(payment);
        }
예제 #23
0
        protected void SaveCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                AccountDataDictionary cardDetails = new AccountDataDictionary();
                cardDetails["AccountName"] = CardName.Text.Trim();
                cardDetails["AccountNumber"] = CardNumber.Text.Trim();
                cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                cardDetails["ExpirationYear"] = ExpirationYear.SelectedItem.Value;
                cardDetails["SecurityCode"] = SecurityCode.Text.Trim();
                PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                PaymentGateway gateway = method.PaymentGateway;
                if (gateway != null)
                {
                    var provider = gateway.GetInstance();
                    string customerProfileId = string.Empty;
                    var profileResult = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                        .GroupBy(p => p.CustomerProfileId)
                        .Take(1)
                        .Select(g => new { CustomerProfileId = g.Key })
                        .SingleOrDefault();

                    if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                        customerProfileId = profileResult.CustomerProfileId;

                    if (string.IsNullOrEmpty(customerProfileId))
                    {
                        try 
                        {
                            var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                            if (rsp.Successful)
                                customerProfileId = rsp.CustomerProfileId;
                            else if (rsp.ResponseCode == "E00039")
                            {
                                var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.IgnoreCase);
                                if(match.Success)
                                    customerProfileId = match.Value;
                                else
                                    ErrorMessage.Text = rsp.ResponseMessage;
                            }
                            else
                                ErrorMessage.Text = rsp.ResponseMessage;
                        }
                        catch(Exception exp)
                        {
                            ErrorMessage.Text = exp.Message;
                        }

                        if (string.IsNullOrEmpty(customerProfileId)) return;
                    }

                    try
                    {
                        var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId) { ValidateProfile = true });
                        if (rsp.Successful)
                        {
                            GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                            gwprofile.NameOnCard = CardName.Text.Trim(); ;
                            gwprofile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                            gwprofile.CustomerProfileId = customerProfileId;
                            gwprofile.PaymentProfileId = rsp.PaymentProfileId;
                            gwprofile.ReferenceNumber = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                            gwprofile.User = _user;
                            gwprofile.InstrumentType = instr.InstrumentType;
                            gwprofile.PaymentMethodName = method.Name;
                            gwprofile.GatewayIdentifier = gateway.ClassId;
                            gwprofile.Save();
                            if (_user.PaymentProfiles.Count == 0)
                            {
                                _user.Settings.DefaultPaymentProfileId = gwprofile.Id;
                                _user.Settings.Save();
                            }
                            CardName.Text = string.Empty;
                            CardNumber.Text = string.Empty;
                            ExpirationMonth.SelectedIndex = 0;
                            ExpirationYear.SelectedIndex = 0;
                            BindCards();
                        }
                        else
                        {
                            ErrorMessage.Text = rsp.ResponseMessage;
                            Logger.Error(rsp.ResponseMessage);
                        }
                    }
                    catch (Exception exp)
                    {
                        ErrorMessage.Text = exp.Message;
                    }
                }
            }
        }
예제 #24
0
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                // CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();

                // PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }

                if (checkOut)
                {
                    // CONTINUE TO PROCESS THE CHECKOUT
                    Basket           basket           = AbleContext.Current.User.Basket;
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
                    if (checkoutResponse.Success)
                    {
                        if (trSaveCard.Visible && SaveCard.Checked)
                        {
                            AccountDataDictionary cardDetails = new AccountDataDictionary();
                            cardDetails["AccountName"]     = CardName.Text.Trim();
                            cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                            cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                            cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                            cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                            PaymentMethod         method  = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                            PaymentGateway        gateway = method.PaymentGateway;
                            PaymentInstrumentData instr   = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                            if (gateway != null)
                            {
                                var    provider          = gateway.GetInstance();
                                string customerProfileId = string.Empty;
                                var    profileResult     = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                                                           .GroupBy(p => p.CustomerProfileId)
                                                           .Take(1)
                                                           .Select(g => new { CustomerProfileId = g.Key })
                                                           .SingleOrDefault();

                                if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                                {
                                    customerProfileId = profileResult.CustomerProfileId;
                                }

                                if (string.IsNullOrEmpty(customerProfileId))
                                {
                                    try
                                    {
                                        var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                                        if (rsp.Successful)
                                        {
                                            customerProfileId = rsp.CustomerProfileId;
                                        }
                                        else if (rsp.ResponseCode == "E00039")
                                        {
                                            var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant);
                                            if (match.Success)
                                            {
                                                customerProfileId = match.Value;
                                            }
                                            else
                                            {
                                                Logger.Error(rsp.ResponseMessage);
                                            }
                                        }
                                        else
                                        {
                                            Logger.Error(rsp.ResponseMessage);
                                        }
                                    }
                                    catch (Exception exp)
                                    {
                                        Logger.Error(exp.Message);
                                    }
                                }

                                try
                                {
                                    var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId)
                                    {
                                        ValidateProfile = true
                                    });
                                    if (rsp.Successful)
                                    {
                                        GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                                        gwprofile.NameOnCard        = CardName.Text.Trim();;
                                        gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                        gwprofile.CustomerProfileId = customerProfileId;
                                        gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                                        gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                                        gwprofile.User              = _user;
                                        gwprofile.InstrumentType    = instr.InstrumentType;
                                        gwprofile.PaymentMethodName = method.Name;
                                        gwprofile.GatewayIdentifier = gateway.ClassId;
                                        gwprofile.Save();
                                        CardName.Text   = string.Empty;
                                        CardNumber.Text = string.Empty;
                                        ExpirationMonth.SelectedIndex = 0;
                                        ExpirationYear.SelectedIndex  = 0;
                                    }
                                }
                                catch (Exception exp)
                                {
                                    Logger.Error(exp.Message);
                                }
                            }
                        }

                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
        }
        protected void SaveCardButton_Click(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                GatewayPaymentProfile profile = _Subscription.PaymentProfile;
                if (profile != null)
                {
                    AccountDataDictionary cardDetails = new AccountDataDictionary();
                    cardDetails["AccountName"]     = CardName.Text.Trim();
                    cardDetails["AccountNumber"]   = CardNumber.Text.Trim();
                    cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value;
                    cardDetails["ExpirationYear"]  = ExpirationYear.SelectedItem.Value;
                    cardDetails["SecurityCode"]    = SecurityCode.Text.Trim();
                    PaymentMethod         method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                    PaymentInstrumentData instr  = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
                    int            gatewayId     = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(_Subscription.PaymentProfile.GatewayIdentifier);
                    PaymentGateway gateway       = PaymentGatewayDataSource.Load(gatewayId);
                    if (gateway != null)
                    {
                        var provider = gateway.GetInstance();
                        try
                        {
                            var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_Subscription.User, instr, profile.CustomerProfileId)
                            {
                                ValidateProfile = true
                            });
                            if (rsp.Successful)
                            {
                                GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                                gwprofile.NameOnCard        = CardName.Text.Trim();;
                                gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                                gwprofile.CustomerProfileId = profile.CustomerProfileId;
                                gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                                gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                                gwprofile.User              = _Subscription.User;
                                gwprofile.InstrumentType    = instr.InstrumentType;
                                gwprofile.GatewayIdentifier = profile.GatewayIdentifier;
                                gwprofile.Save();
                                BindPayments(gwprofile.Id);
                                CardName.Text   = string.Empty;
                                CardNumber.Text = string.Empty;
                                ExpirationMonth.SelectedIndex = 0;
                                ExpirationYear.SelectedIndex  = 0;
                                AddCardPopup.Hide();
                            }
                            else
                            {
                                ErrorMessage.Text = rsp.ResponseMessage;
                                AddCardPopup.Show();
                            }
                        }
                        catch (Exception exp)
                        {
                            Logger.Error(exp.Message);
                            ErrorMessage.Text = exp.Message;
                            AddCardPopup.Show();
                        }
                    }

                    BindPayments(profile.Id);
                }
            }
            else
            {
                AddCardPopup.Show();
            }
        }
        private bool CustomValidation()
        {
            bool hasErrors = false;

            if (trAmount.Visible)
            {
                decimal amount    = AlwaysConvert.ToDecimal(Request.Form[Amount.UniqueID]);
                decimal maxAmount = AlwaysConvert.ToDecimal(this.MaxPaymentAmount.LSCurrencyFormat("lc"));
                if (amount <= 0 || (maxAmount > 0 && amount > maxAmount))
                {
                    CustomValidator invalidAmount = new CustomValidator();
                    invalidAmount.ValidationGroup = this.ValidationGroup;
                    invalidAmount.Text            = "*";
                    invalidAmount.ErrorMessage    = "Invalid amount.  Payment must be greater than zero and no more than " + MaxPaymentAmount.LSCurrencyFormat("lc") + ".";
                    invalidAmount.IsValid         = false;
                    phAmount.Controls.Add(invalidAmount);
                    hasErrors = true;
                }
            }

            //if intl instructions are visible, we must validate additional rules
            if (trIntlInstructions.Visible)
            {
                PaymentMethod m = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                if (m != null)
                {
                    if (m.IsIntlDebitCard())
                    {
                        // INTERNATIONAL DEBIT CARD, ISSUE NUMBER OR START DATE REQUIRED
                        bool invalidIssueNumber = (!Regex.IsMatch(IssueNumber.Text, "\\d{1,2}"));
                        bool invalidStartDate   = ((StartDateMonth.SelectedIndex == 0) || (StartDateYear.SelectedIndex == 0));
                        if (invalidIssueNumber && invalidStartDate)
                        {
                            IntlDebitValidator1.IsValid = false;
                            IntlDebitValidator2.IsValid = false;
                            hasErrors = true;
                        }
                        // CHECK START DATE IS IN PAST
                        int selYear = AlwaysConvert.ToInt(StartDateYear.SelectedValue);
                        int curYear = DateTime.Now.Year;
                        if (selYear > curYear)
                        {
                            StartDateValidator1.IsValid = false;
                            hasErrors = true;
                        }
                        else if (selYear == curYear)
                        {
                            int selMonth = AlwaysConvert.ToInt(StartDateMonth.SelectedValue);
                            int curMonth = DateTime.Now.Month;
                            if (selMonth > curMonth)
                            {
                                StartDateValidator1.IsValid = false;
                                hasErrors = true;
                            }
                        }
                    }
                    else
                    {
                        // CREDIT CARD, CVV IS REQUIRED
                        if (!Regex.IsMatch(SecurityCode.Text, "\\d{3,4}"))
                        {
                            SecurityCodeValidator2.IsValid = false;
                            hasErrors = true;
                        }
                    }
                }
            }

            return(!hasErrors);
        }
        protected GatewayPaymentProfile CreateProfile(AccountDataDictionary cardDetails)
        {
            PaymentMethod         method  = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
            PaymentGateway        gateway = method.PaymentGateway;
            PaymentInstrumentData instr   = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null);
            GatewayPaymentProfile profile = null;

            if (gateway != null)
            {
                var    provider          = gateway.GetInstance();
                string customerProfileId = string.Empty;
                var    profileResult     = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId)
                                           .GroupBy(p => p.CustomerProfileId)
                                           .Take(1)
                                           .Select(g => new { CustomerProfileId = g.Key })
                                           .SingleOrDefault();

                if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId))
                {
                    customerProfileId = profileResult.CustomerProfileId;
                }

                if (string.IsNullOrEmpty(customerProfileId))
                {
                    try
                    {
                        var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user));
                        if (rsp.Successful)
                        {
                            customerProfileId = rsp.CustomerProfileId;
                        }
                        else if (rsp.ResponseCode == "E00039")
                        {
                            var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant);
                            if (match.Success)
                            {
                                customerProfileId = match.Value;
                            }
                            else
                            {
                                Logger.Error(rsp.ResponseMessage);
                            }
                        }
                        else
                        {
                            Logger.Error(rsp.ResponseMessage);
                        }
                    }
                    catch (Exception exp)
                    {
                        Logger.Error(exp.Message);
                    }
                }

                try
                {
                    var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId)
                    {
                        ValidateProfile = true
                    });
                    if (rsp.Successful)
                    {
                        GatewayPaymentProfile gwprofile = new GatewayPaymentProfile();
                        gwprofile.NameOnCard        = CardName.Text.Trim();;
                        gwprofile.Expiry            = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1));
                        gwprofile.CustomerProfileId = customerProfileId;
                        gwprofile.PaymentProfileId  = rsp.PaymentProfileId;
                        gwprofile.ReferenceNumber   = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]);
                        gwprofile.User              = _user;
                        gwprofile.InstrumentType    = instr.InstrumentType;
                        gwprofile.PaymentMethodName = method.Name;
                        gwprofile.GatewayIdentifier = gateway.ClassId;
                        gwprofile.Save();
                        CardName.Text   = string.Empty;
                        CardNumber.Text = string.Empty;
                        ExpirationMonth.SelectedIndex = 0;
                        ExpirationYear.SelectedIndex  = 0;
                        profile = gwprofile;
                    }
                }
                catch (Exception exp)
                {
                    Logger.Error(exp.Message);
                }
            }

            return(profile);
        }