diff --git a/src/FiscalOS.Infra/Accounts/Plaid/PlaidService.cs b/src/FiscalOS.Infra/Accounts/Plaid/PlaidService.cs index f2d9f47..5264d67 100644 --- a/src/FiscalOS.Infra/Accounts/Plaid/PlaidService.cs +++ b/src/FiscalOS.Infra/Accounts/Plaid/PlaidService.cs @@ -1,4 +1,7 @@ + +using System.Reflection; + namespace FiscalOS.Infra.Accounts.Plaid; public sealed class PlaidService @@ -16,6 +19,31 @@ public sealed class PlaidService return new(client); } + public async Task CreateLinkTokenAsync(string id) + { + var assemblyName = Assembly.GetExecutingAssembly().GetName().FullName; + var environmentName = System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + + var ltr = await _client.LinkTokenCreateAsync(new() + { + ClientName = $"{assemblyName}_{environmentName}", + Products = [Products.Transactions], + CountryCodes = [CountryCode.Us], + Language = Language.English, + User = new() + { + ClientUserId = id, + }, + }).ConfigureAwait(false); + + if (ltr.IsSuccessStatusCode is false) + { + throw new PlaidException("Unable to create link token"); + } + + return ltr.LinkToken; + } + public async Task<(string ItemId, string AccessToken)> ExchangeTokenAsync(string publicToken) { var ptr = await _client.ItemPublicTokenExchangeAsync(new()