Beispiel #1
0
        private void comboBoxAccounts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxAccounts.SelectedItem.ToString() != "All accounts")
            {
                Account selectedAccount = (Account)comboBoxAccounts.SelectedItem;

                Institution bankHoldingAccount = Settings.GetCurrentInstitutions().Find(p => p.Accounts.Find(a => a.Id == selectedAccount.Id) != null);
                comboBoxBanks.SelectedItem = bankHoldingAccount;
            }
        }
Beispiel #2
0
        private void PopulateTransactions()
        {
            transactionsToDisplay = new List <Transaction>();

            if (comboBoxAccounts.Items.Count == 0)
            {
                MessageBox.Show("Click \"Get Accounts\" first");
                return;
            }

            if (comboBoxAccounts.SelectedItem.ToString() == "All accounts")
            {
                if (comboBoxBanks.SelectedItem.ToString() == "All banks")
                {
                    foreach (Institution bank in Settings.GetCurrentInstitutions())
                    {
                        List <Transaction> transactionsForBank = PlaidInterface.GetTransactions(bank, dateTimePickerStart.Value, dateTimePickerEnd.Value);
                        PlaidInterface.AddTransactionsToAccounts(bank.Accounts, transactionsForBank);

                        transactionsToDisplay.AddRange(transactionsForBank);
                    }
                }
                else
                {
                    Institution        selectedBank        = (Institution)comboBoxBanks.SelectedItem;
                    List <Transaction> transactionsForBank = PlaidInterface.GetTransactions(selectedBank, dateTimePickerStart.Value, dateTimePickerEnd.Value);
                    PlaidInterface.AddTransactionsToAccounts(selectedBank.Accounts, transactionsForBank);

                    transactionsToDisplay.AddRange(transactionsForBank);
                }
            }
            else
            {
                Account selectedAccount = (Account)comboBoxAccounts.SelectedItem;

                Institution bankHoldingAccount = Settings.GetCurrentInstitutions().Find(p => p.Accounts.Find(a => a.Id == selectedAccount.Id) != null);
                comboBoxBanks.SelectedItem = bankHoldingAccount;

                List <Transaction> transactionsForBank = PlaidInterface.GetTransactions(bankHoldingAccount, dateTimePickerStart.Value, dateTimePickerEnd.Value);
                PlaidInterface.AddTransactionsToAccounts(bankHoldingAccount.Accounts, transactionsForBank);

                transactionsToDisplay.AddRange(selectedAccount.RecentTransactions);
            }

            if ((string)comboBoxSortDirection.SelectedItem == "Ascending")
            {
                transactionsToDisplay.Sort((a, b) => a.Date.CompareTo(b.Date));
            }
            else
            {
                transactionsToDisplay.Sort((a, b) => b.Date.CompareTo(a.Date));
            }

            DisplayTransactions();
        }
Beispiel #3
0
        public static Credentials AuthorizeInstitution(Institution institution, string public_token)
        {
            JObject json         = JObject.FromObject(new { client_id = Settings.Instance.PlaidSettings.Client_Id, secret = GetSecret(), public_token });
            JObject result       = HttpRequestToPlaid("item/public_token/exchange", json);
            string  access_token = result["access_token"].ToString();
            string  item_id      = result["item_id"].ToString();

            return(new Credentials()
            {
                AccessToken = access_token, Item = item_id
            });
        }
Beispiel #4
0
        public static List <Account> GetInstitutionAccounts(Institution institution)
        {
            List <Account> accounts = new List <Account>();

            JObject json = JObject.FromObject(new { client_id    = Settings.Instance.PlaidSettings.Client_Id,
                                                    secret       = GetSecret(),
                                                    access_token = institution.Credentials.AccessToken });
            JObject       result       = HttpRequestToPlaid("accounts/get", json);
            List <JToken> jsonAccounts = result["accounts"].ToList();

            accounts.AddRange(jsonAccounts.Select(p => ConvertToAccount(p)));

            return(accounts);
        }
Beispiel #5
0
        private void pictureBoxExport_Click(object sender, EventArgs e)
        {
            string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Transactions.csv");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            foreach (Transaction transaction in transactionsToDisplay)
            {
                Institution relatedBank       = Settings.GetCurrentInstitutions().Find(b => b.Accounts.Find(a => a.RecentTransactions.Find(t => t.Id == transaction.Id) != null) != null);
                string      transactionString = transaction.Date + "," + relatedBank + "," + transaction.Name + "," + transaction.FormattedAmount;
                File.AppendAllText(filePath, transactionString);
            }

            MessageBox.Show("Transactions exported to " + filePath);
        }
Beispiel #6
0
        public static List <Transaction> GetTransactions(Institution institution, DateTime startDate, DateTime endDate)
        {
            List <Transaction> transactions = new List <Transaction>();

            string start_date = startDate.ToString("yyyy-MM-dd");
            string end_date   = endDate.ToString("yyyy-MM-dd");

            JObject json = JObject.FromObject(new { client_id    = Settings.Instance.PlaidSettings.Client_Id,
                                                    secret       = GetSecret(),
                                                    access_token = institution.Credentials.AccessToken,
                                                    start_date,
                                                    end_date });
            JObject       result           = HttpRequestToPlaid("transactions/get", json);
            List <JToken> jsonTransactions = result["transactions"].ToList();

            transactions.AddRange(jsonTransactions.Select(p => ConvertToTransaction(p)));

            return(transactions);
        }
Beispiel #7
0
        private void DisplayTransactions()
        {
            DataTable transactions = new DataTable();

            transactions.Columns.Add("Date", typeof(DateTime));
            transactions.Columns.Add("Bank", typeof(string));
            transactions.Columns.Add("Name", typeof(string));
            transactions.Columns.Add("Amount", typeof(string));

            foreach (Transaction transaction in transactionsToDisplay)
            {
                Institution relatedBank = Settings.GetCurrentInstitutions().Find(b => b.Accounts.Find(a => a.RecentTransactions.Find(t => t.Id == transaction.Id) != null) != null);
                transactions.Rows.Add(transaction.Date, relatedBank, transaction.Name, transaction.FormattedAmount);
            }

            dataGridView.DataSource = transactions;
            dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
        }
Beispiel #8
0
        private void buttonAuthorize_Click(object sender, EventArgs e)
        {
            Institution bank = PlaidInterface.GetInstitutionById(textBoxInstitutionId.Text);

            bank.Credentials = PlaidInterface.AuthorizeInstitution(bank, textBoxPublicToken.Text);

            if ((Enums.Environment)comboBoxPlaidEnvironments.SelectedItem == Enums.Environment.Sandbox)
            {
                sandboxInstitutions.Add(bank);
            }
            else
            {
                developmentInstitutions.Add(bank);
            }

            SyncListBox();

            labelInstitutionId.Visible   = false;
            textBoxInstitutionId.Visible = false;
            labelPublicToken.Visible     = false;
            textBoxPublicToken.Visible   = false;
            buttonAuthorize.Visible      = false;
        }