This commit is contained in:
Tizian.Breuch
2025-07-29 19:11:34 +02:00
parent 3907cba29d
commit 6fc6aaef3e
14 changed files with 375 additions and 31 deletions

View File

@@ -0,0 +1,16 @@
// src/Webshop.Application/Services/Public/IPaymentMethodService.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Application.DTOs.Payments; // Für PaymentMethodDto
namespace Webshop.Application.Services.Public
{
public interface IPaymentMethodService
{
/// <summary>
/// Ruft alle aktiven Zahlungsmethoden ab, die im Checkout für den Kunden sichtbar sein sollen.
/// </summary>
/// <returns>Eine Liste von PaymentMethodDto mit öffentlichen Konfigurationsdaten.</returns>
Task<IEnumerable<PaymentMethodDto>> GetAllActiveAsync();
}
}

View File

@@ -0,0 +1,67 @@
// src/Webshop.Application/Services/Public/PaymentMethodService.cs
using System.Collections.Generic;
using System.Linq;
using System.Text.Json; // Für JSON-Verarbeitung
using System.Threading.Tasks;
using Webshop.Application.DTOs.Payments;
using Webshop.Domain.Enums;
using Webshop.Domain.Interfaces;
namespace Webshop.Application.Services.Public
{
public class PaymentMethodService : IPaymentMethodService
{
private readonly IPaymentMethodRepository _paymentMethodRepository;
public PaymentMethodService(IPaymentMethodRepository paymentMethodRepository)
{
_paymentMethodRepository = paymentMethodRepository;
}
public async Task<IEnumerable<PaymentMethodDto>> GetAllActiveAsync()
{
var paymentMethods = await _paymentMethodRepository.GetAllAsync();
return paymentMethods
.Where(pm => pm.IsActive)
.Select(pm => new PaymentMethodDto
{
Id = pm.Id,
Name = pm.Name,
Description = pm.Description,
PaymentGatewayType = pm.PaymentGatewayType,
ProcessingFee = pm.ProcessingFee,
PublicConfiguration = GetPublicConfiguration(pm.PaymentGatewayType, pm.Configuration)
}).ToList();
}
private object? GetPublicConfiguration(PaymentGatewayType type, string? configJson)
{
if (string.IsNullOrEmpty(configJson)) return null;
// Beispiel: Nur für BankTransfer geben wir IBAN etc. preis
if (type == PaymentGatewayType.BankTransfer)
{
var config = JsonSerializer.Deserialize<Dictionary<string, string>>(configJson);
if (config != null)
{
// Filter, um geheime Schlüssel NICHT an das Frontend zu senden
return new { IBAN = config.GetValueOrDefault("IBAN"), BIC = config.GetValueOrDefault("BIC"), BankName = config.GetValueOrDefault("BankName") };
}
}
// Für Stripe/PayPal geben wir nur den Public Key preis
if (type == PaymentGatewayType.Stripe)
{
var config = JsonSerializer.Deserialize<Dictionary<string, string>>(configJson);
if (config != null)
{
return new { PublicKey = config.GetValueOrDefault("PublicKey") };
}
}
return null; // Für andere Typen geben wir keine Konfigurationsdetails preis
}
}
}