static void Main(string[] args) { var txn_client = new TransactionsApi(new FireflyIII.Client.Configuration() { BasePath = ff3_demo_url, AccessToken = ff3_demo_pat, }); var txn = new FireflyIII.Model.TransactionSplit( date: DateTime.Now, description: "Test FireflyIII .Net Transaction", amount: 12.54, currencyCode: "EUR", type: TransactionSplit.TypeEnum.Withdrawal, // Can set source/dest by account ID or name // sourceId: 1, sourceName: "Checking Account", destinationId: 7 ); var txn_rsp = txn_client.StoreTransaction(new FireflyIII.Model.Transaction(new[] { txn }.ToList())); Console.WriteLine($"Created transaction {txn_rsp.Data.Id}"); // Set a breakpoint here: txn_client.DeleteTransaction(txn_rsp.Data.Id); Console.WriteLine($"Deleted transaction"); }
private void sindle_sided_transaction(ImportDbContext db, Acklann.Plaid.Entity.Transaction txn) { Console.WriteLine("Creating single sided transaction"); var txn_config = config.account.FirstOrDefault(a => a.plaid_account_id == txn.AccountId); if (txn_config == null) { Console.WriteLine($"Dropping transaction; account not configured for sync: {txn.AccountId}"); // Record transaction as imported db.Transactions.Add(new ImportedTransaction { PlaidId = txn.TransactionId, FireflyId = null, }); db.SaveChanges(); return; } var is_source = txn.Amount > 0; var name = txn.Name; // TODO: fill name with PaymentInfo if non-null var transfer = new FireflyIII.Model.TransactionSplit( date: txn.Date, description: txn.Name, amount: (double)Math.Abs(txn.Amount), currencyCode: txn.CurrencyCode, externalId: txn.TransactionId, tags: txn.Categories?.ToList() ); if (is_source) { transfer.Type = TransactionSplit.TypeEnum.Withdrawal; transfer.SourceId = txn_config.firefly_account_id; transfer.DestinationName = name; } else { transfer.Type = TransactionSplit.TypeEnum.Deposit; transfer.SourceName = name; transfer.DestinationId = txn_config.firefly_account_id; } var storedtransfer = firefly.StoreTransaction(new FireflyIII.Model.Transaction(new[] { transfer }.ToList())); // Record transaction as imported db.Transactions.Add(new ImportedTransaction { PlaidId = txn.TransactionId, FireflyId = storedtransfer.Data.Id, }); db.SaveChanges(); }
private void transfer_between_two_plaid_accounts(ImportDbContext db, Acklann.Plaid.Entity.Transaction txn, Acklann.Plaid.Entity.Transaction other) { var source = txn.Amount > 0 ? txn : other; var dest = txn.Amount < 0 ? txn : other; var source_config = config.account.FirstOrDefault(a => a.plaid_account_id == source.AccountId); var dest_config = config.account.FirstOrDefault(a => a.plaid_account_id == dest.AccountId); if (source_config == null || dest_config == null) { throw new Exception($"Account not found in config: {source.AccountId} or {dest.AccountId}"); } // TODO: shrink txn names? (too verbose: "Requested transfer from... account XXXXXX0123 -> Incoming transfer from ...") var transfer = new FireflyIII.Model.TransactionSplit( date: source.Date, processDate: dest.Date, description: source.Name + " -> " + dest.Name, amount: (double)source.Amount, currencyCode: source.CurrencyCode, externalId: source.TransactionId + " -> " + dest.TransactionId, type: TransactionSplit.TypeEnum.Transfer, sourceId: source_config.firefly_account_id, destinationId: dest_config.firefly_account_id ); var storedtransfer = firefly.StoreTransaction(new FireflyIII.Model.Transaction(new[] { transfer }.ToList())); // Record both transactions as imported db.Transactions.AddRange(new[] { new ImportedTransaction { PlaidId = txn.TransactionId, FireflyId = storedtransfer.Data.Id, }, new ImportedTransaction { PlaidId = other.TransactionId, FireflyId = storedtransfer.Data.Id, } }); db.SaveChanges(); }
private void single_sided_transaction(ImportDbContext db, Acklann.Plaid.Entity.Transaction txn) { Console.WriteLine("Creating single sided transaction"); var txn_config = config.account.FirstOrDefault(a => a.plaid_account_id == txn.AccountId); if (txn_config == null) { Console.WriteLine($"Dropping transaction; account not configured for sync: {txn.AccountId}"); // Record transaction as imported db.Transactions.Add(new ImportedTransaction { PlaidId = txn.TransactionId, FireflyId = null, }); db.SaveChanges(); return; } if (txn.Amount == 0) { Console.WriteLine("Ignoring zero-amount transaction"); // Record transaction as imported db.Transactions.Add(new ImportedTransaction { PlaidId = txn.TransactionId, FireflyId = null, }); db.SaveChanges(); return; } var is_source = txn.Amount > 0; var name = txn.Name; if (name.Length > 255) { Console.WriteLine($"Transaction name was {name.Length} characters long. Truncating to FF3's 255 character limit."); name = name.Substring(0, 255); } // TODO: fill name with PaymentInfo if non-null var transfer = new FireflyIII.Model.TransactionSplit( date: txn.Date, description: txn.Name, amount: (double)Math.Abs(txn.Amount), currencyCode: txn.CurrencyCode, externalId: txn.TransactionId, tags: txn.Categories?.ToList() ); if (is_source) { transfer.Type = TransactionSplit.TypeEnum.Withdrawal; transfer.SourceId = txn_config.firefly_account_id; transfer.DestinationName = name; } else { transfer.Type = TransactionSplit.TypeEnum.Deposit; transfer.SourceName = name; transfer.DestinationId = txn_config.firefly_account_id; } var storedtransfer = firefly.StoreTransaction(new FireflyIII.Model.Transaction(new[] { transfer }.ToList())); if (storedtransfer == null || storedtransfer.Data == null) { Console.WriteLine($"failed to store single_sided_transaction"); Console.WriteLine($"txn: {txn.Name}, {txn.Date}, {txn.Amount} {txn.CurrencyCode}, {txn.TransactionId}"); Console.WriteLine($"transfer: {transfer}"); Console.WriteLine($"storedtransfer: {storedtransfer}"); throw new ApplicationException("failed to store transaction with firefly-iii"); } // Record transaction as imported db.Transactions.Add(new ImportedTransaction { PlaidId = txn.TransactionId, FireflyId = storedtransfer.Data.Id, }); db.SaveChanges(); }