/// <summary> /// Retrieve a statement for a single credit card account. Includes transaction details. /// </summary> /// <param name="account">The credit card 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.CreditCardAccount 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 creditAccount = getOFXCreditAccount(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 CreditCardStatementRequest { CCACCTFROM = creditAccount, INCTRAN = transactionInclusion }; // Wrap in transaction var transactionRequest = new CreditCardStatementTransactionRequest { TRNUID = GetNextTransactionId(), CCSTMTRQ = statementRequest }; // Wrap in messageset var messageSet = new CreditcardRequestMessageSetV1 { Items = new AbstractTransactionRequest[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)); }
async Task <AccountTransactions> GetCreditCardTransactions(Account account, TransactionsFilter filter) { var transactionsRequest = new CreditcardRequestMessageSetV1() { Items = new AbstractTransactionRequest[] { new CreditCardStatementTransactionRequest() { TRNUID = _utils.GenerateTransactionId(), CCSTMTRQ = new CreditCardStatementRequest() { CCACCTFROM = new CreditCardAccount() { ACCTID = account.Id }, INCTRAN = new IncTransaction() { DTEND = _utils.DateToString(filter.EndDate), DTSTART = _utils.DateToString(filter.StartDate), INCLUDE = BooleanType.Y } } } } }; var messageSet = await ExecuteRequest <CreditcardRequestMessageSetV1, CreditcardResponseMessageSetV1>(transactionsRequest); var transactionsResponse = messageSet.Items.FirstOrDefault(_ => _ is CreditCardStatementTransactionResponse) as CreditCardStatementTransactionResponse; if (transactionsResponse == null) { throw new OfxResponseException("Required response is not present in message set."); } var transList = transactionsResponse.CCSTMTRS.BANKTRANLIST.STMTTRN != null ? transactionsResponse.CCSTMTRS.BANKTRANLIST.STMTTRN.Select(MapToModel).ToList() : new List <Transaction>(); decimal amount; if (!decimal.TryParse(transactionsResponse.CCSTMTRS.LEDGERBAL.BALAMT, out amount)) { amount = 0; } return(new AccountTransactions(amount, transList)); }