using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using GoodBooks.PAY.PAYBLL.Checkout; using static GB5Shared.GB5Constant.Constant; namespace GoodBooks.PAY.PAYSL.Endpoints.Checkout { public class InitiatePayOrder : BaseEndpoint> { private readonly IPayOrderBLL _bll; public InitiatePayOrder(IPayOrderBLL bll) => _bll = bll; public override void Configure() { Post("/Pay/Order/InitiatePayOrder"); AllowAnonymous(); // TODO: wire Claims("PAY_ACCESS") when entitlement middleware is ready } public record InitiatePayOrderParameters( [property: FromHeader] string Login, [property: FromBody] InitiatePayOrderRequest Body ); /// /// Mutation endpoint — no cache key. /// Payment order creation is transactional; results must never be served from cache. /// protected override string? GetCacheKey(InitiatePayOrderParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( InitiatePayOrderParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.InitiatePayOrder(req.Body, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }