private AuthorizeDotNetSettingsDto CaptureForm()
        {
            const int PaymentFormSubEntity = 0;
            const int DesignReceiptSubEntity = 1;
            const int EmailConfirmationSubEntity = 2;

            var settings = new AuthorizeDotNetSettingsDto
            {
                //basic fields
                Id = _configurationId,
                Name = GetFieldValue(_viewModel.Fields, _configurationName),
                Environment = GetFieldValue(_viewModel.Fields, _environment),
                ApiLoginId = GetFieldValue(_viewModel.Fields, _liveApiLoginId),
                TransactionKey = GetFieldValue(_viewModel.Fields, _liveTranscationKey),
                TestTransactionKey = GetFieldValue(_viewModel.Fields, _testTranscationKey),
                TestLiveSettings = bool.Parse(GetFieldValue(_viewModel.Fields, _testLiveSettings)),
                TestApiLoginId = GetFieldValue(_viewModel.Fields, _testApiLoginId),
                PaymentMethod = GetFieldValue(_viewModel.Fields, _paymentMethod),
                MD5HashValue = GetFieldValue(_viewModel.Fields, _md5HashValue),
                DuplicateWindow = GetFieldValue(_viewModel.Fields, _duplicateWindow),
                TransactionVersion = GetFieldValue(_viewModel.Fields, _transactionVersion),
                RelayResponse = GetFieldValue(_viewModel.Fields, _relayResponse),
                EnableGateway = bool.Parse(GetFieldValue(_viewModel.Fields, _enableGateway)),
                //payment form options
                HeaderOne = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _header1),
                HeaderTwo = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _header2),
                FooterOne = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _footer1),
                FooterTwo = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _footer2),
                PolicyUrl = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _policyUrl),
                CancelUrl = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _cancelUrl),
                CancelUrlText = GetFieldValue(_viewModel.SubEntities[PaymentFormSubEntity].Records[0].Fields, _cancelUrlText),
                //design receipt page
                ApprovalMessage = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _approvalMessage),
                DeclineMessage = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _declineMessage),
                ErrorMessage = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _errorMessage),
                PartialPaymentMessage = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _partialPaymentMessage),
                ReceiptReturnUrl = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _urlBackToSite),
                ReceiptReturnText = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _textForBackToUrlBackToSite),
                ReceiptHtml = GetFieldValue(_viewModel.SubEntities[DesignReceiptSubEntity].Records[0].Fields, _receiptEditor),
                //email confirmation
                EmailConfirmation = bool.Parse(GetFieldValue(_viewModel.SubEntities[EmailConfirmationSubEntity].Records[0].Fields, _emailConfirmation)),
                EmailHeader = GetFieldValue(_viewModel.SubEntities[EmailConfirmationSubEntity].Records[0].Fields, _emailHeader),
                EmailFooter = GetFieldValue(_viewModel.SubEntities[EmailConfirmationSubEntity].Records[0].Fields, _emailFooter)
            };

            return settings;
        }
        private List<SubEntity> BuildSubEntities(AuthorizeDotNetSettingsDto settings)
        {
            var subEntities = new List<SubEntity>();

            subEntities.Add(BuildPaymentFormSubEntity(settings));
            subEntities.Add(BuildReceiptPageSubEntity(settings));
            subEntities.Add(BuildEmailConfirmationSubEntity(settings));

            _viewModel.SubEntities.Clear();

            return subEntities;
        }
        private SubEntity BuildReceiptPageSubEntity(AuthorizeDotNetSettingsDto settings)
        {
            var newRecord = (_configurationId == 0);
            var subEntity = new SubEntity() { EntityName = "ReceiptPage", DisplayName = "Design Receipt Page", CanAddExisting = false, CanCreateNew = false, CanDelete = false };
            var record = new SubEntityRecord();
            var fields = new List<Field>();

            var approvalMessage = newRecord ? Constants.DefaultValues.ReceiptApprovalMessage : settings.ApprovalMessage;
            fields.Add(new Field(_approvalMessage, "Approval Message", FieldTypes.Text, approvalMessage, false, null, Constants.Tooltips.ApprovalMessage));

            var declineMessage = newRecord ? Constants.DefaultValues.ReceiptDeclineMessage : settings.DeclineMessage;
            fields.Add(new Field(_declineMessage, "Decline Message", FieldTypes.Text, declineMessage, false, null, Constants.Tooltips.DeclineMessage));

            var errorMessage = newRecord ? Constants.DefaultValues.ReceiptErrorMessage : settings.ErrorMessage;
            fields.Add(new Field(_errorMessage, "Error Message", FieldTypes.Text, errorMessage, false, null, Constants.Tooltips.ErrorMessage));

            var partialPaymentMessage = newRecord ? Constants.DefaultValues.ReceiptPartialPaymentMessage : settings.PartialPaymentMessage;
            fields.Add(new Field(_partialPaymentMessage, "Partial Payment Message", FieldTypes.Text, partialPaymentMessage, false, null, Constants.Tooltips.PartialPaymentMessage));

            fields.Add(new Field(_urlBackToSite, "URL Back to Site", FieldTypes.Text, settings.ReceiptReturnUrl, false, null, Constants.Tooltips.UrlBackToSite));
            fields.Add(new Field(_textForBackToUrlBackToSite, "Text for the URL Back to Site", FieldTypes.Text, settings.ReceiptReturnText, false, null, Constants.Tooltips.TextForBackToUrlBackToSite));

            var receiptHtml = newRecord ? Constants.DefaultValues.ReceiptPage : settings.ReceiptHtml;
            fields.Add(new Field(_receiptEditor, "Receipt Editor", FieldTypes.WYSIWYG, receiptHtml, false, true));

            record.Fields = fields;

            subEntity.Records.Add(record);
            return subEntity;
        }
        private SubEntity BuildPaymentFormSubEntity(AuthorizeDotNetSettingsDto settings)
        {
            var subEntity = new SubEntity() { EntityName = "PaymentForm", DisplayName = "Payment Form Options", CanAddExisting = false, CanCreateNew = false, CanDelete = false };

            var record = new SubEntityRecord();
            var fields = new List<Field>();

            fields.Add(new Field(_header1, "Header 1", FieldTypes.MultiLineText, settings.HeaderOne, false, null, Constants.Tooltips.Header1));
            fields.Add(new Field(_header2, "Header 2", FieldTypes.MultiLineText, settings.HeaderTwo, false, null, Constants.Tooltips.Header2));
            fields.Add(new Field(_footer1, "Footer 1", FieldTypes.MultiLineText, settings.FooterOne, false, null, Constants.Tooltips.Footer1));
            fields.Add(new Field(_footer2, "Footer 2", FieldTypes.MultiLineText, settings.FooterTwo, false, null, Constants.Tooltips.Footer2));
            fields.Add(new Field(_policyUrl, "Policy URL", FieldTypes.Text, settings.PolicyUrl, false, null, Constants.Tooltips.PolicyUrl));
            fields.Add(new Field(_cancelUrl, "Cancel URL", FieldTypes.Text, settings.CancelUrl, false, null, Constants.Tooltips.CancelUrl));
            fields.Add(new Field(_cancelUrlText, "Cancel URL Text", FieldTypes.Text, settings.CancelUrlText, false, null, Constants.Tooltips.CancelUrlText));

            record.Fields = fields;

            subEntity.Records.Add(record);
            return subEntity;
        }
        private List<Field> BuildFields(AuthorizeDotNetSettingsDto settings, bool newRecord)
        {
            var fields = new List<Field>();

            //Account Settings
            if (!newRecord)
                fields.Add(new Field(_idField, "Authorize.Net Id", FieldTypes.Label, settings.Id));
            else
                fields.Add(new Field(_idField, "Authorize.Net Id", FieldTypes.Hidden, 0));

            fields.Add(new Field(_configurationName, "Configuration Name", FieldTypes.Text, settings.Name, true, null, Constants.Tooltips.ConfigurationName));
            fields.Add(new Field(_environment, "Environment", FieldTypes.Dropdown, settings.Environment != null ? settings.Environment : "Test", false, null, Constants.Tooltips.Environment)
            {
                Options = new List<KeyValuePair<object, object>>()
                {
                    new KeyValuePair<object,object>("Test","Test"),
                    new KeyValuePair<object,object>("Live","Live")
                }
            });
            fields.Add(new Field(_liveApiLoginId, "Live API Login Id", FieldTypes.Text, settings.ApiLoginId, false, null, Constants.Tooltips.LiveApiLoginId));
            fields.Add(new Field(_liveTranscationKey, "Live Transaction Key", FieldTypes.Text, settings.TransactionKey, false, null, Constants.Tooltips.LiveTranscationKey));
            fields.Add(new Field(_testLiveSettings, "Test Live Settings", FieldTypes.Checkbox, settings.TestLiveSettings, false, null, Constants.Tooltips.TestLiveSettings));
            fields.Add(new Field(_testApiLoginId, "Test API Login Id", FieldTypes.Text, settings.TestApiLoginId, false, null, Constants.Tooltips.TestApiLoginId));
            fields.Add(new Field(_testTranscationKey, "Test Transaction Key", FieldTypes.Text, settings.TestTransactionKey, false, null, Constants.Tooltips.TestTranscationKey));

            fields.Add(new Field(_paymentMethod, "Payment Method", FieldTypes.Dropdown, settings.PaymentMethod != null ? settings.PaymentMethod : "creditcard", false, null, Constants.Tooltips.PaymentMethod)
            {
                Options = new List<KeyValuePair<object, object>>()
                {
                    new KeyValuePair<object,object>("creditcard","Credit Card"),
                    new KeyValuePair<object,object>("echeck","E-Check")
                }
            });

            fields.Add(new Field(_md5HashValue, "MD5 Hash Value", FieldTypes.Text, settings.MD5HashValue, false, null, Constants.Tooltips.Md5HashValue));
            fields.Add(new Field(_duplicateWindow, "Duplicate Window", FieldTypes.Text, settings.DuplicateWindow, false, null, Constants.Tooltips.DuplicateWindow));
            fields.Add(new Field(_transactionVersion, "Transaction version", FieldTypes.Dropdown, settings.TransactionVersion != null ? settings.TransactionVersion : "3.1", false, null, Constants.Tooltips.TransactionVersion)
            {
                Options = new List<KeyValuePair<object, object>>()
                {
                    new KeyValuePair<object,object>("3.0","3.0"),
                    new KeyValuePair<object,object>("3.1","3.1")
                }
            });

            fields.Add(new Field(_relayResponse, "Relay Response", FieldTypes.Dropdown, settings.RelayResponse != null ? settings.RelayResponse : "always", false, null, Constants.Tooltips.RelayResponse)
            {
                Options = new List<KeyValuePair<object, object>>()
                {

                    new KeyValuePair<object,object>("always","Always"),
                    new KeyValuePair<object,object>("notforerrors","Not for Errors, Partial Auths or Declines")
                }
            });
            fields.Add(new Field(_enableGateway, "Enable Gateway", FieldTypes.Checkbox, settings.EnableGateway, false, null, Constants.Tooltips.EnableGateway));
            fields.Add(new Field("enabledGatewayHelperText", "", FieldTypes.Html, "<strong>Note:</strong> When you enable the gateway and save your changes, transactions can be initiated from your site. Please make sure your configuration is complete before enabling the gateway.", false));

            return fields;
        }
        private SubEntity BuildEmailConfirmationSubEntity(AuthorizeDotNetSettingsDto settings)
        {
            var subEntity = new SubEntity() { EntityName = "EmailConfirmation", DisplayName = "Email Confirmation", CanAddExisting = false, CanCreateNew = false, CanDelete = false };
            var record = new SubEntityRecord();
            var fields = new List<Field>();

            fields.Add(new Field(_emailConfirmation, "Email Confirmation", FieldTypes.Checkbox, settings.EmailConfirmation, false, null, Constants.Tooltips.EmailConfirmation));
            fields.Add(new Field(_emailHeader, "Email Header", FieldTypes.WYSIWYG, settings.EmailHeader, false, true, Constants.Tooltips.EmailHeader));
            fields.Add(new Field(_emailFooter, "Email Footer", FieldTypes.WYSIWYG, settings.EmailFooter, false, true, Constants.Tooltips.EmailFooter));

            record.Fields = fields;
            subEntity.Records.Add(record);
            return subEntity;
        }