public void Parse_finds_transaction()
        {
            //{
            //  'dateObj': {
            //    'date': '2018-04-23 00:00:00.000000',
            //    'timezone_type': 3,
            //    'timezone': 'Australia/Sydney'
            //  },
            //  'date': '23-04-2018',
            //  'text': 'CATABY ROADHOUSE CATABY',
            //  'notes': null,
            //  'transactionHash': null,
            //  'hashText': null,
            //  'amount': 112.48,
            //  'type': 'Debit',
            //  'balance': '726.56',
            //  'tags': []
            //},
            var          json     = BankStatementsFixture.Statement2;
            var          response = new BankStatementDownload(json).FetchAllResponse;
            const string text     = @"CATABY ROADHOUSE CATABY";

            var acc = response.Accounts.FindAll(x => x.StatementData.Details.Any(y => y.Text == text));

            var result = acc.First().StatementData.Details.FirstOrDefault(x => x.Text == text);

            result.Text.Should().Be(text);
            result.Amount.Should().Be(112.48);
            result.Type.Should().Be(TypeEnum.Debit);
            result.Balance.Should().Be(726.56);
            result.Date.Should().Be(("23-04-2018"));
        }
        public void With_Unsupported_Json_Schema_Deserialize_Throw_Exception()
        {
            var response = new BankStatementDownload("{wrong}");

            Assert.Throws <ArgumentException>(() =>
            {
                var t = response.FetchAllResponse;
            });
        }
Beispiel #3
0
        public async Task <BankStatementDownload> LoginFetchAllAsync(string userIdentifier, BankLogin bankLogin)
        {
            try
            {
                var credentials =
                    BankStatementsUtil.FormatCredentials(bankLogin, await InstitutionsAsync().ConfigureAwait(false));

                var policy = Policy
                             .Handle <FlurlHttpTimeoutException>()
                             .RetryAsync(3,
                                         (exception, retryCount) =>
                {
                    Trace.TraceWarning(exception.ToString(), "BankStatement download timed out {RetryCount} times",
                                       retryCount);
                });

                var response = await policy.ExecuteAsync(() =>
                                                         (_configuration.ApiUrl + "/login_fetch_all")
                                                         .WithHeader("X-API-KEY", _configuration.ApiKey)
                                                         .WithHeader("REFERRAL-CODE", CreateReferralCode(userIdentifier))
                                                         .WithHeader("Accept", "application/json")
                                                         .PostJsonAsync(new
                {
                    silent = 0,
                    async = 0,
                    credentials
                }).ReceiveString());

                return(new BankStatementDownload(response));
            }
            catch (FlurlHttpException ex)
            {
                Debug.Write(ex, "Failed to download bank statement");

                if (ex.Call.Response == null)
                {
                    throw;
                }

                var response = ex.Call.Exception.Message;

                if (response == null)
                {
                    return(BankStatementDownload.Errored(new BankStatementError
                    {
                        Error = "Empty response from bs.com",
                        ReferralCode = userIdentifier
                    }));
                }

                var deserializer = new XmlSerializer(typeof(BankStatementError));
                var reader       = new StringReader(response);
                var error        = (BankStatementError)deserializer.Deserialize(reader);
                return(BankStatementDownload.Errored(error));
            }
        }
Beispiel #4
0
 public Account GetTestBankAccount()
 {
     return(Cacher.GetOrSet("testaccount-bankstatement2", () =>
     {
         var json = BankStatementsFixture.Statement2;
         var response = new BankStatementDownload(json).FetchAllResponse;
         var account = response.Accounts.First();
         return account;
     }));
 }
        public void Parse_accounts()
        {
            var json     = BankStatementsFixture.Statement2;
            var response = new BankStatementDownload(json).FetchAllResponse;

            response.Accounts.Count.Should().Be(2);
            response.Accounts[0].Name.Should().Be("Credit Card");
            response.Accounts[0].AccountNumber.Should().Be("4509 49xx xxxx 0220");
            response.Accounts[0].Balance.Should().Be(-924.57);
            response.Accounts[0].Available.Should().Be(20922.20);
            response.Accounts[0].AccountType.Should().Be("credit card");
            response.Accounts[0].AccountHolder.Should().Be("MR Fred Flintstone");
            response.Accounts[0].Institution.Should().Be("ANZ");
        }
Beispiel #6
0
        public void Create_list_of_bank_statement_list_item_from_fetch_all_response()
        {
            var json     = BankStatementsFixture.Statement2;
            var response = new BankStatementDownload(json).FetchAllResponse;

            var text = FileUtil.Create(response);

            text.Length.Should().BeGreaterThan(0);

            var file = Path.Combine(Path.GetTempPath(), $"bankstatements-{Guid.NewGuid()}.tsv");

            File.WriteAllText(file, text);

            Console.WriteLine(file);

            var result = FileUtil.Read(File.ReadAllText(file));
            var data   = response.Accounts.SelectMany(x => x.StatementData.Details);

            result.Count().Should().Be(data.Count());
            File.Delete(file);
        }
Beispiel #7
0
        public static IEnumerable <PredictionRequest> ToPredictionRequests(this BankStatementDownload download)
        {
            if (download == null)
            {
                return(null);
            }
            if (download.Error != null)
            {
                return(null);
            }

            var list = new List <PredictionRequest>();

            foreach (var account in download.FetchAllResponse.Accounts)
            {
                foreach (var item in account.StatementData.Details)
                {
                    var pr = new PredictionRequest
                    {
                        Id                 = Guid.NewGuid(),
                        Description        = item.Text,
                        AccountType        = AccountTypeConverter.Convert(account.AccountType),
                        Amount             = Convert.ToDouble(item.Amount),
                        Bank               = account.Institution,
                        TransactionUtcDate = item.DateObj.Date.UtcDateTime
                    };

                    list.Add(pr);
                }
            }

            var missing = list.Where(x => string.IsNullOrEmpty(x.Description));

            Debug.Assert(!missing.Any());
            return(list);
        }
        public void With_Unsupported_Json_Schema_Should_Be_Able_Get_Token()
        {
            var response = new BankStatementDownload(RawJson);

            response.FetchAllResponse.UserToken.Should().Be("IRqO8Gi8Zbx2Glht371_1w");
        }