Get.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Security.Claims;
  2. using MediatR;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.V1.Purchases;
  6. internal sealed class Get : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapGet("v1/purchases/{orderID}", async (
  11. string orderID,
  12. ClaimsPrincipal user,
  13. ISender sender,
  14. CancellationToken ct,
  15. int? marketplace = null
  16. ) => {
  17. var query = new Application.Features.Api.V1.Purchases.Get.Query(
  18. user.GetApplicationID(),
  19. user.GetPatOwnerMemberID(),
  20. orderID,
  21. marketplace
  22. );
  23. var result = await sender.Send(query, ct);
  24. return result.Match(
  25. data => ApiResponse.Ok(data),
  26. CustomResults.Problem
  27. );
  28. })
  29. .WithTags("결제 보고")
  30. .WithGroupName("public")
  31. .WithName("GetPurchase")
  32. .WithSummary("결제 단건 조회")
  33. .WithDescription("""
  34. 등록한 결제의 상태를 조회합니다 (대사용).
  35. - OAuth2 앱 토큰: 해당 앱이 등록한 건만 조회
  36. - PAT: 본인 소유 앱 전체의 등록 건 조회
  37. ### 필수 scope
  38. - `read:purchases`
  39. ### status 값
  40. | 값 | 의미 |
  41. |---|---|
  42. | `Pending` | 보류 — 확정 예정 (`confirmDueAt` 참조) |
  43. | `Confirmed` | 확정 — 채널 수수료 적립 완료 |
  44. | `Canceled` | 취소됨 |
  45. ### 에러
  46. - `400` — 여러 건 조회됨 (marketplace 지정 필요)
  47. - `404` — 등록 내역 없음
  48. """)
  49. .Produces<ApiResponse>(StatusCodes.Status200OK)
  50. .ProducesProblem(StatusCodes.Status400BadRequest)
  51. .ProducesProblem(StatusCodes.Status401Unauthorized)
  52. .ProducesProblem(StatusCodes.Status403Forbidden)
  53. .ProducesProblem(StatusCodes.Status404NotFound)
  54. .RequireAuthorization(policy => policy
  55. .AddAuthenticationSchemes("ApiKey", "OAuth2Bearer")
  56. .RequireAuthenticatedUser())
  57. .RequireScope("read:purchases");
  58. }
  59. }