/// <summary> /// Construct a Statement from source OFX data - StatementResponse object (credit card account) /// </summary> /// <param name="sourceOFX">OFX CreditCardStatementResponse object retrieved from FI</param> public Statement(CreditCardStatementResponse statementResponse) { // Parse account information OwningAccount = Account.Create(statementResponse.CCACCTFROM); // Parse currency into a string Currency = statementResponse.CURDEF.ToString(); // Parse statement date range StartDate = OFXUtils.DateFromOFX(statementResponse.BANKTRANLIST.DTSTART); EndDate = OFXUtils.DateFromOFX(statementResponse.BANKTRANLIST.DTEND); // Parse account balance AccountBalance = OFXUtils.DecimalStringToFixedInt(statementResponse.LEDGERBAL.BALAMT); // Convert OFX transactions into our normalized Transaction objects if (statementResponse.BANKTRANLIST.STMTTRN != null) { var unorderedTransactions = from ofxTransaction in statementResponse.BANKTRANLIST.STMTTRN select new Transaction(ofxTransaction); Transactions = new List <Transaction>(unorderedTransactions.OrderByDescending(trans => trans.PostDate)); } else { Transactions = new List <Transaction>(); } }
/// <summary> /// Construct a statement transaction by parsing an OFX transaction entity /// </summary> /// <param name="ofxTransaction"></param> public Transaction(StatementTransaction ofxTransaction) { // Assign to internal state PostDate = OFXUtils.DateFromOFX(ofxTransaction.DTPOSTED); TransactionId = ofxTransaction.FITID; Amount = OFXUtils.DecimalStringToFixedInt(ofxTransaction.TRNAMT); Name = (string)ofxTransaction.Item; }
/// <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)); }
public async Task <IActionResult> Delete(List <IFormFile> files) { List <ValidationResult> validationsResults = new List <ValidationResult>(); foreach (var file in files) { var arrayFile = OFXUtils.ReadAsArray(file); var result = OFXUtils.ReadOFXtoXMLFromArray(arrayFile); var ofx = OFX.GetOFXFromString(result); ofx.Id = ofx.GenerateOFXId(); validationsResults.Add(await _OFXAppService.Remove(ofx.Id)); } return(!ModelState.IsValid ? CustomResponse(ModelState) : CustomResponse(validationsResults)); }
/// <summary> /// Populates a signon request for this service using the provided user credentials. /// Some OFX calls can use special credentials different than a FI account holder, so this method /// allows the caller to specify credentials /// </summary> /// <param name="credentials">Authentication credentials to use for this request. If no credentials are specified, the default user credentials for the service are used.</param> /// <param name="requestProfile">Request profile specifying communication parameters for this request</param> /// <returns></returns> protected SignonRequestMessageSetV1 CreateSignonRequest(Credentials credentials = null, MessageSetRequestProfile requestProfile = null) { // If no credentials are specified, use the default user credentials assigned when the service was constructed if (credentials == null) { credentials = userCredentials; } // If no request profile is specified, use the default if (requestProfile == null) { requestProfile = defaultMessageSetProfile; } // Populate the FinancialInstitution data var fi = new FinancialInstitution { ORG = financialInstitution.OrganizationId, FID = financialInstitution.FinancialId }; // Populate a signon request with the current date and provided user credentials var signonRequest = new SignonRequest { DTCLIENT = OFXUtils.DateToOFX(new DateTimeOffset(DateTime.Now)), ItemsElementName = new ItemsChoiceType[2] { ItemsChoiceType.USERID, ItemsChoiceType.USERPASS }, Items = new string[2] { credentials.UserId, credentials.Password }, FI = fi, LANGUAGE = LanguageEnum.ENG, APPID = appId, APPVER = appVer }; // Wrap the signon request in a signon message set, per protocol var signonMessageSet = new SignonRequestMessageSetV1 { SONRQ = signonRequest }; // Return the fully populated request return(signonMessageSet); }
public async Task <IActionResult> Put(List <IFormFile> files) { List <ValidationResult> validationsResults = new List <ValidationResult>(); foreach (var file in files) { var arrayFile = OFXUtils.ReadAsArray(file); var result = OFXUtils.ReadOFXtoXMLFromArray(arrayFile); var ofx = OFX.GetOFXFromString(result); ofx.FileOFX = string.Join('\n', result); var ofxViewModel = new OFXViewModel { OFX = ofx }; validationsResults.Add(await _OFXAppService.Update(ofxViewModel)); } return(!ModelState.IsValid ? CustomResponse(ModelState) : CustomResponse(validationsResults)); }
public static Guid GetGuid(this string input) { return(new Guid(OFXUtils.GetHash(input))); }
public static string GetHash(this string input) { return(OFXUtils.GetHash(input)); }
public void TestReadXML() { var input = OFXUtils.ReadOFXtoXMLFromPath(@"D:\Rubens\Desktop\DevelopersChallenge2-master\DevelopersChallenge2-master\OFX\extrato1.ofx"); var ofx = OFX.GetOFXFromString(input); }