Example #1
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();
            }
        }
        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();
        }
Example #3
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));
         }
     }
 }
Example #4
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();
            }
        }
Example #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();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ICriteria criteria = NHibernateHelper.CreateCriteria <PaymentMethod>();

            criteria.Add(Restrictions.Not(Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GiftCertificate)));
            criteria.Add(Restrictions.Not(Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GoogleCheckout)));

            methods = PaymentMethodDataSource.LoadForCriteria(criteria);

            if (!Page.IsPostBack)
            {
                CancelLink.NavigateUrl          += "?OrderNumber=" + Order.OrderNumber.ToString();
                SelectedPaymentMethod.DataSource = methods;
                SelectedPaymentMethod.DataBind();
                Amount.Text = string.Format("{0:F2}", Order.GetBalance(true));
                //LOAD PAYMENT STATUSES
                foreach (PaymentStatus status in Enum.GetValues(typeof(PaymentStatus)))
                {
                    selPaymentStatus.Items.Add(new ListItem(status.ToString(), ((int)status).ToString()));
                }

                //ListItem completed = selPaymentStatus.Items.FindByValue(((int)PaymentStatus.Captured).ToString());
                //if (completed != null) completed.Selected = true;
            }
        }
Example #8
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;
        }
        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();
            }
        }
Example #13
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();
            }
        }
Example #16
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);
        }
        protected void LoadPaymentMethods()
        {
            _PaymentMethods = new List <PaymentMethod>();
            IList <PaymentMethod> allPaymentMethods = PaymentMethodDataSource.LoadAll("Name");

            foreach (PaymentMethod method in allPaymentMethods)
            {
                if (IsMethodVisible(method))
                {
                    _PaymentMethods.Add(method);
                }
            }
            PaymentMethodList.DataSource = _PaymentMethods;
            PaymentMethodList.DataBind();
            trPaymentMethods.Visible = (_PaymentMethods.Count > 0);
        }
Example #18
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;
        }
        private void InitOnlinePaymentMethods()
        {
            ICriteria criteria = NHibernateHelper.CreateCriteria <PaymentMethod>();

            criteria.Add(Restrictions.Not(Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GiftCertificate)));
            criteria.Add(Restrictions.Not(Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GoogleCheckout)));
            IList <PaymentMethod> allMethods = PaymentMethodDataSource.LoadForCriteria(criteria);

            _OnlinePaymentMethods = new List <PaymentMethod>();
            foreach (PaymentMethod m in allMethods)
            {
                if ((m.PaymentGateway != null) && (m.PaymentInstrumentType != PaymentInstrumentType.PayPal))
                {
                    _OnlinePaymentMethods.Add(m);
                }
            }
        }
Example #20
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");
        }
Example #21
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();
            }
        }
Example #22
0
        public static int GetGCPaymentMethodId(GoogleCheckout gatewayInstance)
        {
            PaymentMethodCollection gcPayMethods =
                PaymentMethodDataSource.LoadForPaymentGateway(gatewayInstance.PaymentGatewayId);

            if (gcPayMethods == null || gcPayMethods.Count == 0)
            {
                PaymentMethod gcPayMethod = new PaymentMethod();
                gcPayMethod.Name              = "GoogleCheckout";
                gcPayMethod.PaymentGatewayId  = gatewayInstance.PaymentGatewayId;
                gcPayMethod.PaymentInstrument = PaymentInstrument.GoogleCheckout;
                gcPayMethod.Save();
                return(gcPayMethod.PaymentMethodId);
            }
            else
            {
                return(gcPayMethods[0].PaymentMethodId);
            }
        }
Example #23
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;
                    }
                }
            }
        }
Example #24
0
 protected void PaymentMethodGrid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "MoveUp")
     {
         IList <PaymentMethod> paymentMethods = PaymentMethodDataSource.LoadAll();
         int itemIndex = AlwaysConvert.ToInt(e.CommandArgument);
         if ((itemIndex < 1) || (itemIndex > paymentMethods.Count - 1))
         {
             return;
         }
         PaymentMethod selectedItem = paymentMethods[itemIndex];
         PaymentMethod swapItem     = paymentMethods[itemIndex - 1];
         paymentMethods.RemoveAt(itemIndex - 1);
         paymentMethods.Insert(itemIndex, swapItem);
         for (int i = 0; i < paymentMethods.Count; i++)
         {
             paymentMethods[i].OrderBy = (short)i;
         }
         paymentMethods.Save();
         AbleContext.Current.Database.FlushSession();
     }
     else if (e.CommandName == "MoveDown")
     {
         IList <PaymentMethod> paymentMethods = PaymentMethodDataSource.LoadAll();
         int itemIndex = AlwaysConvert.ToInt(e.CommandArgument);
         if ((itemIndex > paymentMethods.Count - 2) || (itemIndex < 0))
         {
             return;
         }
         PaymentMethod selectedItem = paymentMethods[itemIndex];
         PaymentMethod swapItem     = paymentMethods[itemIndex + 1];
         paymentMethods.RemoveAt(itemIndex + 1);
         paymentMethods.Insert(itemIndex, swapItem);
         for (int i = 0; i < paymentMethods.Count; i++)
         {
             paymentMethods[i].OrderBy = (short)i;
         }
         paymentMethods.Save();
         AbleContext.Current.Database.FlushSession();
     }
     PaymentMethodGrid.DataBind();
 }
Example #25
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);
        }
        protected void AddButton_Click(object sender, System.EventArgs e)
        {
            PaymentMethod method = new PaymentMethod();

            method.Name = Name.Text;
            method.PaymentInstrumentType = (PaymentInstrumentType)AlwaysConvert.ToInt16(PaymentInstrumentList.SelectedValue);
            method.PaymentGateway        = PaymentGatewayDataSource.Load(AlwaysConvert.ToInt(GatewayList.SelectedValue));
            method.AllowSubscriptions    = AllowSubscriptionPayments.Checked;
            //GROUP RESTRICTION
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in GroupList.Items)
                {
                    Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        method.Groups.Add(group);
                    }
                }
            }
            method.OrderBy = (short)PaymentMethodDataSource.GetNextOrderBy();
            method.Save();
            //UPDATE THE ADD MESSAGE
            AddedMessage.Text    = string.Format(AddedMessage.Text, method.Name);
            AddedMessage.Visible = true;
            //RESET THE ADD FORM
            PaymentInstrumentList.SelectedIndex = -1;
            Name.Text = string.Empty;
            GatewayList.SelectedIndex         = -1;
            AllowSubscriptionPayments.Checked = false;
            UseGroupRestriction.SelectedIndex = 0;
            BindGroups();
            //TRIGER ANY EVENT ATTACHED TO THE UPDATE
            if (ItemAdded != null)
            {
                ItemAdded(this, new PersistentItemEventArgs(method.Id, method.Name));
            }
        }
        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;
                    }
                }
            }
        }
        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();
            }
        }