CreateOrder.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Domain.Entities.Payments.ValueObject;
  2. using MediatR;
  3. using System.Security.Claims;
  4. using System.Text.Json.Serialization;
  5. using Web.Api.Common;
  6. using Web.Api.Extensions;
  7. namespace Web.Api.Endpoints.Payment;
  8. public sealed class Request
  9. {
  10. [JsonPropertyName("amount")]
  11. public int Amount { get; set; }
  12. [JsonPropertyName("paymentMethod")]
  13. [JsonConverter(typeof(JsonStringEnumConverter))]
  14. public PaymentMethod PaymentMethod { get; set; }
  15. }
  16. /// <summary>결제 주문 생성</summary>
  17. internal sealed class CreateOrder : IEndpoint
  18. {
  19. public void MapEndpoint(IEndpointRouteBuilder app)
  20. {
  21. /// 금액/결제수단으로 주문 생성 → orderId, clientKey, successUrl 반환
  22. app.MapPost("api/payment/order", async (
  23. Request body,
  24. ClaimsPrincipal user,
  25. ISender sender,
  26. CancellationToken ct
  27. ) => {
  28. var memberID = user.GetRequiredMemberID();
  29. var command = new Application.Features.Api.Payment.CreateOrder.Command(
  30. body.Amount,
  31. body.PaymentMethod,
  32. memberID
  33. );
  34. var data = await sender.Send(command, ct);
  35. return ApiResponse.Ok(data);
  36. })
  37. .WithTags("Payment")
  38. .RequireAuthorization();
  39. }
  40. }