public async Task <ActionResult> AddAccounts(AddAccounts accounts)
        {
            var response = new GenericResponse <List <DiscoveryPatchResponse> >();

            try
            {
                var addedAccounts = _transactionService.AddAccounts(accounts.AccountsIds);
                if (addedAccounts.IsSuccess)
                {
                    var discoveryResult = await _transactionService.DiscoverPayments(addedAccounts.Data);

                    if (discoveryResult.IsSuccess)
                    {
                        var responseData = new List <DiscoveryPatchResponse>();
                        discoveryResult.Data.ForEach(d =>
                        {
                            responseData.Add(new DiscoveryPatchResponse()
                            {
                                AccountId          = d.Account.PublicKey,
                                IsSuccess          = d.Status == PatchStatus.Success,
                                PulledRecordsCount = d.PulledRecordsCount
                            });
                        });
                        response.Success(responseData);
                    }
                    else
                    {
                        response.Failed("Failed to discover payments");
                    }
                }
                else
                {
                    response.Failed("Failed to Add Account to Database Please check Logs");
                }
            }
            catch (Exception ex)
            {
                response.Failed("Failed to Add Account to Database or discover paymets  Please check Logs");
            }
            return(Ok(response));
        }
Exemple #2
0
        private void cmdAddAccounts_Click(object sender, RoutedEventArgs e)
        {
            if (cboLauncherServerList.SelectedItem is Server server)
            {
                var dialog = new AddAccounts();
                dialog.Owner = this;

                var result = dialog.ShowDialog();

                if (result == true)
                {
                    foreach (var account in dialog.Accounts)
                    {
                        server.Accounts.Add(account);
                    }

                    cmdEditAccount.IsEnabled   = (server.Accounts.Count > 0);
                    cmdDeleteAccount.IsEnabled = (server.Accounts.Count > 0);
                }
            }
        }
Exemple #3
0
        public async Task AddAccounts(AddAccounts command)
        {
            try
            {
                var exchangeTokenResponse = await _plaid.ExchangeToken(command.PublicToken, _tokenSource.Token);

                if (exchangeTokenResponse != null && !string.IsNullOrEmpty(exchangeTokenResponse.AccessToken))
                {
                    List <IEvent> events = new List <IEvent>();

                    var bankAddedEvent = new BankAdded(command.BankId, command.BankName, exchangeTokenResponse.AccessToken, command.BoardId);
                    events.Add(bankAddedEvent);

                    var config          = _settings.Get <TransactionWebhookConfig>(TransactionWebhookConfig.SettingsPrefix);
                    var url             = config.Url.Replace("{boardid}", command.BoardId);
                    var webhookResponse = await _plaid.UpdateWebhook(exchangeTokenResponse.AccessToken, url, _tokenSource.Token);

                    var bankWebhookAdded = new BankWebhookAdded(command.BankId, webhookResponse?.Item?.Webhook, command.BoardId);
                    events.Add(bankWebhookAdded);

                    var authResponse = await _plaid.RetrieveBalances(exchangeTokenResponse.AccessToken, _tokenSource.Token);

                    if (authResponse?.Accounts?.Any() ?? false)
                    {
                        var accountAddedEvents = authResponse.Accounts.Select(a =>
                                                                              new AccountAdded(command.BoardId, exchangeTokenResponse.AccessToken, a.AccountId, command.BankName, command.BankId, a.Name, a.Type, a.OfficialName, a.SubType, a.Balances.Available, a.Balances.Current, a.Balances.Limit)
                                                                              );
                        events.AddRange(accountAddedEvents);
                        RaiseEvents(events);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #4
0
 public void Handle(Core.Boundaries.Add.Response response)
 {
     AddAccounts.Add(response);
 }