mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
64e34d0ef5
* Separate coinswitch as a system plugin * Decouple Coinswitch from Checkout UI * remove dummy csproj * Remove CoinSwitchTests.cs per @NicolasDorier feedback Co-authored-by: rockstardev <rockstardev@users.noreply.github.com>
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Data;
|
|
using BTCPayServer.Services.Stores;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace BTCPayServer.Plugins.CoinSwitch
|
|
{
|
|
public class CoinSwitchService: IDisposable
|
|
{
|
|
private readonly StoreRepository _storeRepository;
|
|
private readonly IMemoryCache _memoryCache;
|
|
|
|
public CoinSwitchService(StoreRepository storeRepository, IMemoryCache memoryCache)
|
|
{
|
|
_storeRepository = storeRepository;
|
|
_memoryCache = memoryCache;
|
|
}
|
|
|
|
public async Task<CoinSwitchSettings> GetCoinSwitchForInvoice(string id)
|
|
{
|
|
return await _memoryCache.GetOrCreateAsync($"{nameof(CoinSwitchService)}-{id}", async entry =>
|
|
{
|
|
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1);
|
|
var d = await _storeRepository.GetStoreByInvoiceId(id);
|
|
|
|
return d?.GetStoreBlob()?.GetCoinSwitchSettings();
|
|
});
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_memoryCache?.Dispose();
|
|
}
|
|
}
|
|
}
|