CreateOrder.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Domain.Entities.Payments.ValueObject;
  2. using Application.Abstractions.Messaging;
  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. /// <summary>충전할 포인트 (VAT 제외). PG 결제 총액은 서버에서 VAT 10% 별도 가산.</summary>
  11. [JsonPropertyName("amount")]
  12. public int Amount { get; set; }
  13. [JsonPropertyName("paymentMethod")]
  14. [JsonConverter(typeof(JsonStringEnumConverter))]
  15. public PaymentMethod PaymentMethod { get; set; }
  16. }
  17. /// <summary>결제 주문 생성</summary>
  18. internal sealed class CreateOrder : IEndpoint
  19. {
  20. public void MapEndpoint(IEndpointRouteBuilder app)
  21. {
  22. /// 금액/결제수단으로 주문 생성 → orderId, clientKey, successUrl 반환
  23. app.MapPost("api/payment/order", async (
  24. Request body,
  25. ClaimsPrincipal user,
  26. ISender sender,
  27. CancellationToken ct
  28. ) => {
  29. var memberID = user.GetRequiredMemberID();
  30. var command = new Application.Features.Api.Payment.CreateOrder.Command(
  31. body.Amount,
  32. body.PaymentMethod,
  33. memberID
  34. );
  35. var data = await sender.Send(command, ct);
  36. return ApiResponse.Ok(data);
  37. })
  38. .WithTags("Payment")
  39. .RequireAuthorization();
  40. }
  41. }