Florian Mihalits 4772d0d462 Add auto-payout feature for wallets with balances
Introduced new methods in `IWalletService` and `WalletService` to retrieve wallets with positive balances. Added `AutoPayout` and `RunAutoPayout` methods in `ToolsController` to automate payouts, including synchronization with MangoPay balances.

Created `AutoPayoutVm` and `RunAutoPayoutVm` view models. Added Razor views `AutoPayout.cshtml` and `RunAutoPayout.cshtml` for managing and displaying payout processes.

Updated `appsettings` files to reduce `MinPayoutAmmount` from 1000 to 1. Refactored `ToolsController` for better wallet handling, added error handling, and improved code formatting. Commented out KYC check logic in `ApiPaymentController` with a TODO for review.
2025-11-21 13:19:58 +01:00

95 lines
3.1 KiB
C#

using gehGassi.Core.Interfaces;
using gehGassi.Domain.Common;
using gehGassi.Domain.Dogs;
using gehGassi.Domain.Payment;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace gehGassi.Core.Services
{
/// <summary>
/// Service der die Verwaltung von Wallets ermöglicht
/// </summary>
public class WalletService : ServiceBase<Wallet>, IWalletService
{
/// <summary>
/// Erstellt eine Instanz
/// </summary>
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
public WalletService(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
/// <summary>
/// Erstellen eines Wallets für einen AppUser
/// </summary>
/// <param name="appUserId">Id des AppUsers</param>
/// <param name="walletId">ID des Walltes bei Mangopay</param>
/// <param name="type">Typ des Wallets</param>
/// <param name="ownerId">Id des Payment Owners (PaymentId)</param>
/// <param name="currency">Währung ISO 4217 Code</param>
/// <param name="description">Beschreibung</param>
/// <returns>Wallet</returns>
public Wallet Create(string appUserId, string walletId, WalletType type, string ownerId, string currency, string description)
{
var wallet = new Wallet
{
Id = Guid.NewGuid().ToString("N"),
AppUserId = appUserId,
Type = type,
OwnerId = ownerId,
WalletId = walletId,
Currency = currency,
Description = description,
Balance = 0,
UpdatedAt = DateTimeOffset.UtcNow
};
return wallet;
}
/// <summary>
/// Gibt ein Wallet für einen AppUser mit einem Typ zurück
/// </summary>
/// <param name="appUserId">Id des AppUsers</param>
/// <param name="type">Typ des Wallets</param>
/// <returns>Wallet oder null, wenn nicht gefunden</returns>
public async Task<Wallet> GetAsync(string appUserId, WalletType type)
{
var wallet = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.Type == type).ConfigureAwait(false);
return wallet;
}
/// <summary>
/// Gibt eine Liste aller Wallets eines AppUsers zurück
/// </summary>
/// <param name="appUserId">Id des AppUsers</param>
/// <returns>Liste von Wallets</returns>
public async Task<List<Wallet>> GetAllAsync(string appUserId)
{
return (await Repository.FindAsync(c => c.AppUserId == appUserId).ConfigureAwait(false)).ToList();
}
/// <summary>
/// Gibt eine Liste aller Wallets mit positivem Kontostand zurück
/// </summary>
/// <param name="type">Wallet typ</param>
/// <returns>Liste von Wallets</returns>
public async Task<List<Wallet>> GetAllWithPositiveBalanceAsync(WalletType type)
{
return (await Repository.FindAsync(c => c.Type == type && c.Balance > 0).ConfigureAwait(false)).ToList();
}
/// <summary>
/// Gibt eine Liste aller Wallets mit positivem Kontostand zurück
/// </summary>
/// <returns>Liste von Wallets</returns>
public async Task<List<Wallet>> GetAllWithPositiveBalanceAsync()
{
return (await Repository.FindAsync(c => c.Balance > 0).ConfigureAwait(false)).ToList();
}
}
}