Esempio n. 1
0
        /// <summary>
        /// Retrieve a statement for a single bank account. Includes transaction details.
        /// </summary>
        /// <param name="account">The bank account to retrieve statement data for</param>
        /// <param name="startDate">Start of date range for transactions</param>
        /// <param name="endDate">End of date range for transactions</param>
        /// <returns>List of statements containing the requested data.</returns>
        public async Task <Tuple <IEnumerable <Statement>, string> > GetStatement(Types.BankAccount account, DateTimeOffset startDate, DateTimeOffset endDate)
        {
            // Ensure service catalog is populated
            await PopulateServiceProfiles();

            // Retrieve request profile for this message set
            var requestProfile = GetMessageSetRequestProfile(typeof(BankMessageSetV1));

            // Form specification of the account to retrieve information for
            var bankAccount = getOFXBankAccount(account);

            // Form transaction inclusion specification for date range. Always include transaction details
            var transactionInclusion = new IncTransaction
            {
                DTSTART = OFXUtils.DateToOFX(startDate),
                DTEND   = OFXUtils.DateToOFX(endDate),
                INCLUDE = BooleanType.Y
            };

            // Wrap in statement request
            var statementRequest = new StatementRequest
            {
                BANKACCTFROM = bankAccount,
                INCTRAN      = transactionInclusion
            };

            // Wrap in transaction
            var transactionRequest = new StatementTransactionRequest
            {
                TRNUID = GetNextTransactionId(),
                STMTRQ = statementRequest
            };

            // Wrap in messageset
            var messageSet = new BankRequestMessageSetV1 {
                Items = new AbstractRequest[1] {
                    transactionRequest
                }
            };

            // Gather all message sets in the request
            var requestMessageSets = new List <AbstractTopLevelMessageSet>
            {
                CreateSignonRequest(userCredentials, requestProfile),
                messageSet
            };

            // Send to service and await response
            Protocol.OFX response = await new Transport(requestProfile.ServiceEndpoint).sendRequestAsync(requestMessageSets.ToArray());

            // TODO: Check response for errors
            string errorMessage;

            // Extract statement data and return
            return(Tuple.Create(Statement.CreateFromOFXResponse(response, out errorMessage), errorMessage));
        }
Esempio n. 2
0
        /// <summary>
        /// Helper method which creates and fills in a BankAccount with information from the passed account info
        /// </summary>
        /// <param name="account">Populated Types.BankAccount with bank info</param>
        /// <returns>Populated OFX BankAccount</returns>
        protected BankAccount getOFXBankAccount(Types.BankAccount account)
        {
            var bankAccount = new BankAccount
            {
                BANKID = account.RoutingId,
                ACCTID = account.AccountId
            };

            if (account is CheckingAccount)
            {
                bankAccount.ACCTTYPE = AccountEnum.CHECKING;
            }
            else
            {
                bankAccount.ACCTTYPE = AccountEnum.SAVINGS;
            }

            return(bankAccount);
        }