using AccountsBLL.Payment; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.Payment { // Faithful port of GB4 Payment.svc's PaymentToVoucher — a read-only preview that derives a // proposed VoucherDTO from an existing Payment, without ever persisting it. Distinct from the // separate, mutating PaymentToVoucherPosting operation (not this endpoint). public class GetPaymentToVoucher : BaseEndpoint> { private readonly IPaymentBLL _paymentBLL; public GetPaymentToVoucher(IPaymentBLL paymentBLL) { _paymentBLL = paymentBLL; } public override void Configure() { Get("/Payment/PaymentToVoucher"); AllowAnonymous(); } public record GetPaymentToVoucherParameters( [property: FromHeader] string Login, [property: QueryParam] int PaymentId ); protected override string? GetCacheKey(GetPaymentToVoucherParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( GetPaymentToVoucherParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _paymentBLL.GetPaymentToVoucher(req.PaymentId, LoginDTO!); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }