Confirm.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Web.Api.Common;
  2. using Web.Api.Extensions;
  3. using Application.Abstractions.Messaging;
  4. using System.Security.Claims;
  5. namespace Web.Api.Endpoints.Payment;
  6. /// <summary>토스 결제 승인</summary>
  7. internal sealed class Confirm : IEndpoint
  8. {
  9. public sealed record Request(string PaymentKey, string OrderID, int Amount);
  10. public void MapEndpoint(IEndpointRouteBuilder app)
  11. {
  12. /// successUrl 콜백의 {paymentKey, orderId, amount} 로 승인 — 서버 저장 금액과 대조 후 지갑 캐시 충전
  13. app.MapPost("api/payments/confirm", async (
  14. Request body,
  15. ClaimsPrincipal user,
  16. ISender sender,
  17. CancellationToken ct
  18. ) => {
  19. var memberID = user.GetRequiredMemberID();
  20. var data = await sender.Send(new Application.Features.Api.Payment.Toss.Confirm.Command(
  21. body.PaymentKey,
  22. body.OrderID,
  23. body.Amount,
  24. memberID
  25. ), ct);
  26. return ApiResponse.Ok(data);
  27. })
  28. .WithTags("Payment")
  29. .RequireAuthorization();
  30. }
  31. }