Files
csob/Controllers/PaymentsController.cs
JiriUhlir 09db30a3ca first
2026-06-18 11:05:46 +02:00

59 lines
2.6 KiB
C#
Raw Permalink Blame History

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