using System.Text.Json.Nodes; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Csob.Models; using Csob.Services; namespace Csob.Controllers; /// /// PISP – single payment initiation and its authorization (sign) flow. Requires the ČSOB credential /// headers. After POST /payments the response carries signInfo.signId; use it with the /// sign endpoints to drive Strong Customer Authentication (SCA). /// [ApiController] [Route("payments")] [Produces("application/json")] [Tags("PISP – Payments")] public sealed class PaymentsController : ControllerBase { private readonly PaymentsService _service; public PaymentsController(PaymentsService service) => _service = service; /// Initiate a domestic (DMCT) or SEPA (ESCT) payment. [HttpPost] public async Task Initiate([FromBody] PaymentInitiationRequest request, CancellationToken ct) => Ok(await _service.InitiateAsync(request, ct)); /// Get the full payment detail. [HttpGet("{id}")] public async Task Detail(string id, CancellationToken ct) => Ok(await _service.DetailAsync(id, ct)); /// Get the payment instruction status. [HttpGet("{id}/status")] public async Task Status(string id, CancellationToken ct) => Ok(await _service.StatusAsync(id, ct)); /// Cancel a not-yet-authorized payment. [HttpDelete("{id}")] public async Task Cancel(string id, CancellationToken ct) => Ok(await _service.CancelAsync(id, ct)); /// Start the authorization (SCA) of a payment. Returns the PSU redirect details. [HttpPost("{id}/sign/{signId}")] public async Task StartSign(string id, string signId, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] JsonNode? body, CancellationToken ct) => Ok(await _service.StartSignAsync(id, signId, body, ct)); /// Get the current state of an authorization (sign) transaction. [HttpGet("{id}/sign/{signId}")] public async Task SignStatus(string id, string signId, CancellationToken ct) => Ok(await _service.SignStatusAsync(id, signId, ct)); /// Finalize an authorization (sign) transaction. [HttpPut("{id}/sign/{signId}")] public async Task FinalizeSign(string id, string signId, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] JsonNode? body, CancellationToken ct) => Ok(await _service.FinalizeSignAsync(id, signId, body, ct)); }