Exemplo 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));
        }
Exemplo n.º 2
0
        public void TestCcResponse()
        {
            // Open test input file - Credit Card Response containing sample transaction data
            Stream fs = File.OpenRead(@"test_cc_response_tx.ofx");

            // Instantiate an XML serializer which will be used to deserialize the sample data into the Object model
            XmlSerializer serializer = new XmlSerializer(typeof(OFX.Protocol.OFX));

            // Deserialize the XML data
            OFX.Protocol.OFX obj = (OFX.Protocol.OFX)serializer.Deserialize(fs);

            // Expect: 2 response sets
            Assert.IsNotNull(obj.Items);
            Assert.AreEqual(obj.Items.Length, 2);

            // Expect: Response message set 0 is SignonResponse
            Assert.IsInstanceOfType(obj.Items[0], typeof(SignonResponseMessageSetV1));

            // Expect: Response message set 1 is CreditcardResponse
            Assert.IsInstanceOfType(obj.Items[1], typeof(CreditcardResponseMessageSetV1));
        }
Exemplo n.º 3
0
        /// <summary>
        /// List all accounts available from the service
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <Account> > ListAccounts()
        {
            // Ensure service catalog is populated
            await PopulateServiceProfiles();

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

            // Populate the account info request
            var accountInfoRequest = new AccountInfoRequest {
                DTACCTUP = "19970101"
            };
            // Use an early date for "last update" so we always retrieve information

            // Wrap the request in a transaction
            var transaction = new AccountInfoTransactionRequest
            {
                TRNUID     = GetNextTransactionId(),
                ACCTINFORQ = accountInfoRequest
            };

            var messageSet = new SignupRequestMessageSetV1 {
                Items = new AbstractRequest[1] {
                    transaction
                }
            };

            // 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



            // Walk nested elements to find accounts
            List <Account> accountList = new List <Account>();

            foreach (var responseMessageSet in response.Items.Where(item => item.GetType() == typeof(SignupResponseMessageSetV1)).Select(item => (SignupResponseMessageSetV1)item))
            {
                foreach (
                    var transactionResponse in
                    responseMessageSet.Items.Where(item => item.GetType() == typeof(AccountInfoTransactionResponse))
                    .Select(item => (AccountInfoTransactionResponse)item))
                {
                    // Iterate each account
                    foreach (var accountInfo in transactionResponse.ACCTINFORS.ACCTINFO)
                    {
                        var specificAccountInfo = accountInfo.Items[0];
                        // Create appropriate account type entry
                        if (specificAccountInfo.GetType() == typeof(BankAccountInfo))
                        {
                            // There are multiple types of bank accounts we support
                            var bankAccountInfo = (BankAccountInfo)specificAccountInfo;
                            accountList.Add(Account.Create(bankAccountInfo.BANKACCTFROM));
                        }
                        if (specificAccountInfo.GetType() == typeof(CreditCardAccountInfo))
                        {
                            var creditAccountInfo = (CreditCardAccountInfo)specificAccountInfo;
                            accountList.Add(Account.Create(creditAccountInfo.CCACCTFROM));
                        }
                    }
                }
            }

            return(accountList);
        }