-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Payment 도메인 파일 구조 개선 #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 결제(Payment) 도메인 엔티티 추가 - 결제 상태 관리 (대기, 완료, 취소, 실패) - 환불 처리 및 환불 가능 금액 관리 - 7일 환불 제한 기능
- 본인인증 대기(PendingVerification) 도메인 엔티티 추가 - 인증 상태 관리 (대기, 완료, 실패, 만료) - 인증 코드 관리 및 만료 시간 관리
- Payment DTO 추가 (PaymentConfirmResponse, PaymentHistoryResponse, RefundRequest, RefundResponse, WebhookResult) - PaymentServicePort 인터페이스 추가 - PaymentRepositoryPort 인터페이스 추가 - PortOnePort 인터페이스 추가 (PortOne API 연동)
- PaymentApplicationService 비즈니스 로직 구현 - PortOne API를 통한 결제 확인 - 환불 처리 (7일 제한) - 결제 이력 조회
- Verification DTO 추가 (CreateVerificationRequest, VerificationResult, VerificationStatusResponse) - VerificationServicePort 인터페이스 추가 - VerificationRepositoryPort 인터페이스 추가
- VerificationApplicationService 비즈니스 로직 구현 - 본인인증 대기/확인 시스템 - 인증 코드 생성 및 검증
- PaymentJpaRepository JPA 쿼리 메서드 추가 - VerificationJpaRepository JPA 쿼리 메서드 추가 - PaymentRepositoryAdapter 포트 구현 - VerificationRepositoryAdapter 포트 구현 - Hexagonal Architecture 준수
- PortOneAdapter PortOne API 연동 구현 - WebhookVerificationService 웹훅 검증 서비스 구현 - WebClientConfig WebClient 설정 추가 - HMAC-SHA256 서명 검증
- PaymentController API 엔드포인트 추가 - VerificationController API 엔드포인트 추가 - 결제 확인, 환불, 결제 이력 조회 API 제공 - 본인인증 대기/확인 API 제공
- Payment 관련 예외 추가 (PaymentNotFoundException, PaymentProcessingException, PaymentVerificationException, RefundValidationException, RefundProcessingException) - Verification 관련 예외 추가 (VerificationNotFoundException, VerificationProcessingException, VerificationValidationException) - PortOne API 관련 예외 추가 (PortOneApiException, WebhookVerificationException) - InvalidUserException 추가 - PaymentExceptionHandler 추가
- ProductMapper 수정 - ProductServiceImpl 수정 - ProductNotSynchronizedException 수정 - ProductRepository 수정
- build.gradle.kts: WebClient 의존성 추가 - application.yaml: PortOne API 설정 추가
- ProductServiceAdapter.kt: 예외 처리 방식 통일 - ProductNotSynchronizedException.kt: 생성자 파라미터 제거 - application.yaml: 두 버전 병합 (server context-path, portone, payment, verification, jwt 설정 통합)
- global/exception → application/payment/exception으로 이동 - 모든 Exception에 @ResponseStatus 적용 - PaymentNotFoundException, PaymentProcessingException 등 7개 Exception 이동
- application/{domain}/port/out → repository/{domain}으로 이동
- PaymentRepositoryPort, UserRepositoryPort, ProductRepositoryPort, VerificationRepositoryPort 이동
- Repository 인터페이스를 별도 계층으로 분리
- PaymentApplicationService를 Command와 Query로 분리 - PaymentCommandService: 결제 확인, 환불, 웹훅 처리 - PaymentQueryService: 결제 조회, 내역 조회 - PaymentCommandPort, PaymentQueryPort 인터페이스 분리
- WebClient → @FeignClient로 변경 - PortOneClient 인터페이스 생성 - PortOneFeignConfig Bean Config 추가 - PortOneAdapter에서 FeignClient 사용
- ResponseEntity → @ResponseStatus로 변경 - 모든 메서드에 @ResponseStatus 적용 - Exception의 @ResponseStatus로 자동 응답 처리
- Spring Cloud BOM 추가 (2024.0.0) - spring-cloud-starter-openfeign 의존성 추가 - @EnableFeignClients 어노테이션 추가
- 모든 Repository import 경로를 repository 계층으로 수정 - 함수 depth 2 이하로 개선 (handlePaymentPaid) - 불필요한 import 제거 - 사용하지 않는 파라미터 활용
- main 브랜치의 domain 중심 구조 변경사항 반영 - Auth, Product(Item), User 도메인 구조 변경 수용 - Payment 관련 변경사항은 toss 브랜치의 변경사항 유지 - 충돌 해결: 삭제된 파일 제거 및 AuthDetailsService 수정
- PaymentApplicationService 삭제 (PaymentCommandService, PaymentQueryService로 분리 완료) - PaymentServicePort 삭제 (PaymentCommandPort, PaymentQueryPort로 분리 완료) - PaymentHistoryResponse의 사용하지 않는 message 파라미터 제거
- application.yaml에서 portone.api.base-url을 환경 변수로 변경 (PORTONE_BASE_URL) - OccountApplication에서 @EnableFeignClients 제거 (FeignConfig에서 관리) - Bean 설정은 별도 @configuration 클래스에서 관리하도록 정리
- Payment 엔티티 필드를 private으로 변경하고 getter 제공 - 컨트롤러를 CQRS 패턴으로 분리 (PaymentCommandController, PaymentQueryController) - DTO 중첩 클래스를 별도 파일로 분리 - 예외 클래스 @ResponseStatus 어노테이션 제거 - 모든 예외/로그/Validation 메시지 한국어 통일 - RequestMapping 경로 /payment로 변경 - web-flux 의존성 제거
WalkthroughThis PR introduces payment and verification features using hexagonal architecture. It adds domain entities (Payment, PendingVerification), application services for payment commands/queries and verification workflows, infrastructure adapters for PortOne API integration via Feign, comprehensive exception handling, and REST controllers. Configuration is extended with payment/verification-specific properties and dependency management for Spring Cloud. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PaymentCmd as PaymentCommandController
participant PaymentService as PaymentCommandService
participant PortOneAdapter as PortOneAdapter
participant PortOne as PortOne API
participant WebhookVerifier as WebhookVerificationService
participant Repo as PaymentRepository
rect rgb(200, 220, 255)
note over Client,Repo: Payment Confirmation Flow
Client->>PaymentCmd: POST /payment/confirm (paymentId, userEmail)
PaymentCmd->>PaymentService: confirmPayment(paymentId, userEmail)
PaymentService->>PortOneAdapter: confirmPayment(paymentId)
PortOneAdapter->>PortOne: GET /payments/{paymentId}
PortOne-->>PortOneAdapter: PaymentConfirmResponse
PaymentService->>PaymentService: validateEmail(userEmail)
PaymentService-->>PaymentCmd: PaymentConfirmResponse
PaymentCmd-->>Client: 200 PaymentConfirmResponse
end
rect rgb(220, 255, 200)
note over Client,Repo: Webhook Processing Flow
Client->>PaymentCmd: POST /payment/webhook (payload, headers)
PaymentCmd->>PaymentService: processWebhook(payload, headers)
PaymentService->>WebhookVerifier: verify(payload, signature, timestamp)
WebhookVerifier-->>PaymentService: Boolean
alt Verification Failed
PaymentService-->>PaymentCmd: FAILED
else Verification Success
PaymentService->>PaymentService: parseEvent(payload)
PaymentService->>PaymentService: handlePaymentPaid/Refund/Cancelled()
PaymentService->>Repo: save(updatedPayment)
PaymentService-->>PaymentCmd: SUCCESS
end
PaymentCmd-->>Client: 200 WebhookResult
end
rect rgb(255, 220, 200)
note over Client,Repo: Refund Processing Flow
Client->>PaymentCmd: POST /payment/refund (refundRequest, userEmail)
PaymentCmd->>PaymentService: processRefund(refundRequest, userEmail)
PaymentService->>Repo: findByPaymentId(paymentId)
Repo-->>PaymentService: Payment
PaymentService->>PaymentService: validateRefund(payment, userEmail)
PaymentService->>PortOneAdapter: processRefund(paymentId, reason)
PortOneAdapter->>PortOne: POST /payments/{paymentId}/cancel
PortOne-->>PortOneAdapter: RefundResponse
PaymentService->>Repo: save(refundedPayment)
PaymentService-->>PaymentCmd: RefundResponse
PaymentCmd-->>Client: 200 RefundResponse
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Free 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
PaymentRepositoryPort를 application 계층으로 이동
PaymentRepositoryAdapter에 QueryDSL을 도입
PaymentCommandService의 트랜잭션 범위를 메서드 단위로 최적화