예제 #1
0
        /// <summary>
        /// Validates the arguments supplied to the constructor. Entities are loaded from supplied IDs where applicable to ensure existence and a valid state.
        /// </summary>
        /// <param name="errorMessage">Will be set to empty string if arguments are valid. Otherwise a message will be set indicating the problem.</param>
        /// <returns>True if the arguments are valid. False otherwise.</returns>
        public bool AreArgsValid(out string errorMessage)
        {
            errorMessage = string.Empty;

            LoadEntities();

            if (_authorizedPerson == null)
            {
                errorMessage = "The authorizedPersonAliasId did not resolve to a person";
                return(false);
            }

            if (_financialGateway == null)
            {
                errorMessage = "The gatewayId did not resolve";
                return(false);
            }

            if (!_financialGateway.IsActive)
            {
                errorMessage = "The gateway is not active";
                return(false);
            }

            if (_automatedGatewayComponent as IAutomatedGatewayComponent == null)
            {
                errorMessage = "The gateway failed to produce an automated gateway component";
                return(false);
            }

            if (_automatedPaymentArgs.AutomatedPaymentDetails == null || !_automatedPaymentArgs.AutomatedPaymentDetails.Any())
            {
                errorMessage = "At least one item is required in the TransactionDetails";
                return(false);
            }

            if (_financialAccounts.Count != _automatedPaymentArgs.AutomatedPaymentDetails.Count)
            {
                errorMessage = "Each detail must reference a unique financial account";
                return(false);
            }

            var totalAmount = 0m;

            foreach (var detail in _automatedPaymentArgs.AutomatedPaymentDetails)
            {
                if (detail.Amount <= 0m)
                {
                    errorMessage = "The detail amount must be greater than $0";
                    return(false);
                }

                var financialAccount = _financialAccounts[detail.AccountId];

                if (financialAccount == null)
                {
                    errorMessage = string.Format("The accountId '{0}' did not resolve", detail.AccountId);
                    return(false);
                }

                if (!financialAccount.IsActive)
                {
                    errorMessage = string.Format("The account '{0}' is not active", detail.AccountId);
                    return(false);
                }

                totalAmount += detail.Amount;
            }

            if (totalAmount < 1m)
            {
                errorMessage = "The total amount must be at least $1";
                return(false);
            }

            if (_financialPersonSavedAccount == null && _automatedPaymentArgs.FinancialPersonSavedAccountId.HasValue)
            {
                errorMessage = string.Format(
                    "The saved account '{0}' is not valid for the person or gateway",
                    _automatedPaymentArgs.FinancialPersonSavedAccountId.Value);
                return(false);
            }

            if (_financialPersonSavedAccount == null)
            {
                errorMessage = string.Format("The given person does not have a saved account for this gateway");
                return(false);
            }

            if (_referencePaymentInfo == null)
            {
                errorMessage = string.Format("The saved account failed to produce reference payment info");
                return(false);
            }

            if (_transactionType == null)
            {
                errorMessage = string.Format("The transaction type is invalid");
                return(false);
            }

            if (_financialSource == null)
            {
                errorMessage = string.Format("The financial source is invalid");
                return(false);
            }

            if (_automatedPaymentArgs.ScheduledTransactionId.HasValue && _financialScheduledTransaction == null)
            {
                errorMessage = string.Format("The scheduled transaction did not resolve");
                return(false);
            }

            if (_financialScheduledTransaction != null && _financialScheduledTransaction.AuthorizedPersonAliasId != _automatedPaymentArgs.AuthorizedPersonAliasId)
            {
                errorMessage = string.Format("The scheduled transaction and authorized person alias ID are not valid together");
                return(false);
            }

            if (_financialScheduledTransaction != null && _financialScheduledTransaction.FinancialGatewayId != _automatedPaymentArgs.AutomatedGatewayId)
            {
                errorMessage = string.Format("The scheduled transaction and gateway ID are not valid together");
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(_automatedPaymentArgs.AmountCurrencyCode) &&
                !_automatedGatewayComponent.IsCurrencyCodeSupported(GetCurrencyCodeDefinedValueCache(_automatedPaymentArgs.AmountCurrencyCode), _referencePaymentInfo.CreditCardTypeValue))
            {
                errorMessage = "The gateway does not support the currency and credit card combination.";
                return(false);
            }

            return(true);
        }