Beispiel #1
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        public void BindData()
        {
            GenericTable.Rows.Clear();
            Gateway gateway = GetGateways().GetGatewayById(Gateways.SelectedValue);

            if (gateway == null)
            {
                GenericTable.Visible = false;
                return;
            }
            else
            {
                GenericTable.Visible = true;
            }

            TransactionTypeList.Items.Clear();
            foreach (TransactionType type in gateway.TransactionTypes)
            {
                TransactionTypeList.Items.Add(new ListItem(type.FriendlyName, type.Name));
            }
            TransactionTypeList.DataBind();

            // fill in the form fields
            if (_PaymentMethodDto != null && _PaymentMethodDto.PaymentMethodParameter != null)
            {
                PaymentMethodDto.PaymentMethodParameterRow param = null;
                param = GetParameterByName(_TransactionTypeParameterName);

                if (param != null)
                {
                    ManagementHelper.SelectListItemIgnoreCase(TransactionTypeList, param.Value);
                }

                param = GetParameterByName(_GatewayParameterName);
                if (param != null && String.Compare(param.Value, Gateways.SelectedValue, true) == 0)
                {
                    foreach (PaymentMethodDto.PaymentMethodParameterRow pRow in _PaymentMethodDto.PaymentMethodParameter)
                    {
                        // skip parameter with name "Gateway" and process all the other parameters
                        if (String.Compare(pRow.Parameter, _GatewayParameterName, true) != 0 &&
                            String.Compare(pRow.Parameter, _TransactionTypeParameterName, true) != 0)
                        {
                            GatewayProperty prop = gateway.FindPropertyByName(pRow.Parameter);
                            if (prop != null)
                            {
                                CreateRow(prop.Name, prop.FriendlyName, pRow.Value, prop.Required);
                            }
                        }
                    }
                }
                else
                {
                    if (gateway.Properties != null)
                    {
                        foreach (GatewayProperty prop in gateway.Properties)
                        {
                            CreateRow(prop.Name, prop.FriendlyName, "", prop.Required);
                        }
                    }
                }
            }
            else
            {
                this.Visible = false;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Saves the object changes.
        /// </summary>
        /// <param name="dto">The dto.</param>
        public void SaveChanges(object dto)
        {
            if (this.Visible)
            {
                _PaymentMethodDto = dto as PaymentMethodDto;

                if (_PaymentMethodDto != null && _PaymentMethodDto.PaymentMethodParameter != null)
                {
                    Gateway gateway = GetGateways().GetGatewayById(Gateways.SelectedValue);

                    Guid paymentMethodId = Guid.Empty;
                    if (_PaymentMethodDto.PaymentMethod.Count > 0)
                    {
                        paymentMethodId = _PaymentMethodDto.PaymentMethod[0].PaymentMethodId;
                    }

                    // add new parameters
                    StringBuilder paramsFilter = new StringBuilder();

                    if (gateway.Properties != null)
                    {
                        foreach (GatewayProperty prop in gateway.Properties)
                        {
                            System.Web.UI.Control ctrl = GenericTable.FindControl(prop.Name);
                            if (ctrl != null)
                            {
                                string val = ((TextBox)ctrl).Text;

                                PaymentMethodDto.PaymentMethodParameterRow row = GetParameterByName(prop.Name);
                                if (row != null)
                                {
                                    row.Value = val;
                                }
                                else
                                {
                                    CreateParameter(_PaymentMethodDto, prop.Name, val, paymentMethodId);
                                }
                                paramsFilter.AppendFormat("Parameter <> '{0}' AND ", prop.Name);
                            }
                        }
                    }

                    // add gateway parameter
                    PaymentMethodDto.PaymentMethodParameterRow gRow = GetParameterByName(_GatewayParameterName);
                    if (gRow != null)
                    {
                        gRow.Value = Gateways.SelectedValue;
                    }
                    else
                    {
                        CreateParameter(_PaymentMethodDto, _GatewayParameterName, Gateways.SelectedValue, paymentMethodId);
                    }
                    paramsFilter.AppendFormat("Parameter <> '{0}'", _GatewayParameterName);

                    // add transaction type parameter
                    PaymentMethodDto.PaymentMethodParameterRow trRow = GetParameterByName(_TransactionTypeParameterName);
                    if (trRow != null)
                    {
                        trRow.Value = TransactionTypeList.SelectedValue;
                    }
                    else
                    {
                        CreateParameter(_PaymentMethodDto, _TransactionTypeParameterName, TransactionTypeList.SelectedValue, paymentMethodId);
                    }
                    paramsFilter.AppendFormat(" AND Parameter <> '{0}'", _TransactionTypeParameterName);

                    // remove parameters that are not used anymore
                    string filter = paramsFilter.ToString();

                    PaymentMethodDto.PaymentMethodParameterRow[] rows = (PaymentMethodDto.PaymentMethodParameterRow[])_PaymentMethodDto.PaymentMethodParameter.Select(filter);
                    if (rows != null && rows.Length > 0)
                    {
                        foreach (PaymentMethodDto.PaymentMethodParameterRow pRow in rows)
                        {
                            pRow.Delete();
                        }
                    }
                }
            }
        }