Files
fiscalos/src/FiscalOS.Infra/Transactions/Plaid/PlaidTransactionService.cs
T
Stevan Freeborn a9f1ced0d5 feat: add Plaid transaction handling and async queue processing
- introduced new migration to add Cursor column to AccountMetadata.
- updated AppDbContext model snapshot to reflect changes in the database schema.
- implemented async queue processing with ChannelAsyncQueue and AsyncQueueHostedService.
- created Plaid transaction handlers for added, modified, and removed transactions.
- developed PlaidTransactionService and PlaidTransactionSyncer for syncing transactions.
- added SyncUpdatesProcessor to handle sync updates from Plaid.
- updated tests to accommodate changes in institution and account metadata handling.
2026-03-09 04:29:01 -05:00

59 lines
1.4 KiB
C#

namespace FiscalOS.Infra.Transactions.Plaid;
internal interface IPlaidTransactionService
{
IAsyncEnumerable<TransactionsSyncResponse> SyncTransactionsForAccountAsync(
string accessToken,
string accountId,
string? initialCursor = null
);
}
internal sealed class PlaidTransactionService : IPlaidTransactionService
{
private readonly PlaidClient _client;
private PlaidTransactionService(PlaidClient client)
{
_client = client;
}
public static PlaidTransactionService From(IServiceProvider sp)
{
var client = sp.GetRequiredService<PlaidClient>();
return new(client);
}
public async IAsyncEnumerable<TransactionsSyncResponse> SyncTransactionsForAccountAsync(
string accessToken,
string accountId,
string? initialCursor = null
)
{
TransactionsSyncResponse? response;
var cursor = initialCursor;
do
{
response = await _client.TransactionsSyncAsync(new()
{
AccessToken = accessToken,
Cursor = cursor,
Count = 500,
Options = new()
{
AccountId = accountId,
}
}).ConfigureAwait(false);
if (response.Error?.ErrorCode is "TRANSACTIONS_SYNC_MUTATION_DURING_PAGINATION")
{
continue;
}
cursor = response.NextCursor;
yield return response;
} while (response is not null && response.HasMore);
}
}