generated from pricelees/issue-pr-template
refactor: 새로운 결제, 결제 상세, 취소된 결제 정보를 조회하는 PaymentFinderV2 추가
This commit is contained in:
parent
6bbb35e55f
commit
fb3be3bcaf
@ -9,11 +9,12 @@ enum class PaymentErrorCode(
|
|||||||
override val message: String
|
override val message: String
|
||||||
) : ErrorCode {
|
) : ErrorCode {
|
||||||
PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P001", "결제 정보를 찾을 수 없어요."),
|
PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P001", "결제 정보를 찾을 수 없어요."),
|
||||||
CANCELED_PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P002", "취소된 결제 정보를 찾을 수 없어요."),
|
PAYMENT_DETAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "P002", "결제 상세 정보를 찾을 수 없어요."),
|
||||||
PAYMENT_CLIENT_ERROR(HttpStatus.BAD_REQUEST, "P003", "결제에 실패했어요. 결제 수단을 확인한 후 다시 시도해주세요."),
|
CANCELED_PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P003", "취소된 결제 정보를 찾을 수 없어요."),
|
||||||
ORGANIZATION_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "P004", "은행 / 카드사 정보를 찾을 수 없어요."),
|
PAYMENT_CLIENT_ERROR(HttpStatus.BAD_REQUEST, "P004", "결제에 실패했어요. 결제 수단을 확인한 후 다시 시도해주세요."),
|
||||||
TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "P005", "타입 정보를 찾을 수 없어요."),
|
ORGANIZATION_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "P005", "은행 / 카드사 정보를 찾을 수 없어요."),
|
||||||
NOT_SUPPORTED_PAYMENT_TYPE(HttpStatus.BAD_REQUEST, "P006", "지원하지 않는 결제 수단이에요."),
|
TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "P006", "타입 정보를 찾을 수 없어요."),
|
||||||
|
NOT_SUPPORTED_PAYMENT_TYPE(HttpStatus.BAD_REQUEST, "P007", "지원하지 않는 결제 수단이에요."),
|
||||||
|
|
||||||
PAYMENT_UNEXPECTED_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "P998", "결제 과정중 예상치 못한 예외가 발생했어요."),
|
PAYMENT_UNEXPECTED_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "P998", "결제 과정중 예상치 못한 예외가 발생했어요."),
|
||||||
PAYMENT_PROVIDER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "P999", "시스템에 일시적인 오류가 발생했어요. 잠시 후 다시 시도해주세요."),
|
PAYMENT_PROVIDER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "P999", "시스템에 일시적인 오류가 발생했어요. 잠시 후 다시 시도해주세요."),
|
||||||
|
|||||||
@ -0,0 +1,53 @@
|
|||||||
|
package roomescape.payment.implement
|
||||||
|
|
||||||
|
import io.github.oshai.kotlinlogging.KLogger
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import roomescape.payment.exception.PaymentErrorCode
|
||||||
|
import roomescape.payment.exception.PaymentException
|
||||||
|
import roomescape.payment.infrastructure.persistence.v2.CanceledPaymentEntityV2
|
||||||
|
import roomescape.payment.infrastructure.persistence.v2.CanceledPaymentRepositoryV2
|
||||||
|
import roomescape.payment.infrastructure.persistence.v2.PaymentDetailEntity
|
||||||
|
import roomescape.payment.infrastructure.persistence.v2.PaymentDetailRepository
|
||||||
|
import roomescape.payment.infrastructure.persistence.v2.PaymentEntityV2
|
||||||
|
import roomescape.payment.infrastructure.persistence.v2.PaymentRepositoryV2
|
||||||
|
|
||||||
|
private val log: KLogger = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class PaymentFinderV2(
|
||||||
|
private val paymentRepository: PaymentRepositoryV2,
|
||||||
|
private val paymentDetailRepository: PaymentDetailRepository,
|
||||||
|
private val canceledPaymentRepository: CanceledPaymentRepositoryV2
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun findPaymentByReservationId(reservationId: Long): PaymentEntityV2 {
|
||||||
|
log.debug { "[PaymentFinderV2.findByReservationId] 시작: reservationId=$reservationId" }
|
||||||
|
|
||||||
|
return paymentRepository.findByReservationId(reservationId)?.also {
|
||||||
|
log.debug { "[PaymentFinderV2.findByReservationId] 완료: reservationId=$reservationId, paymentId=${it.id}" }
|
||||||
|
} ?: run {
|
||||||
|
log.warn { "[PaymentFinderV2.findByReservationId] 실패: reservationId=$reservationId" }
|
||||||
|
throw PaymentException(PaymentErrorCode.PAYMENT_NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findPaymentDetailByPaymentId(paymentId: Long): PaymentDetailEntity {
|
||||||
|
log.debug { "[PaymentFinderV2.findPaymentDetailByPaymentId] 시작: paymentId=$paymentId" }
|
||||||
|
|
||||||
|
return paymentDetailRepository.findByPaymentId(paymentId)?.also {
|
||||||
|
log.debug { "[PaymentFinderV2.findPaymentDetailByPaymentId] 완료: paymentId=$paymentId, detailId=${it.id}" }
|
||||||
|
} ?: run {
|
||||||
|
log.warn { "[PaymentFinderV2.findPaymentDetailByPaymentId] 실패: paymentId=$paymentId" }
|
||||||
|
throw PaymentException(PaymentErrorCode.PAYMENT_DETAIL_NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findCanceledPaymentByPaymentIdOrNull(paymentId: Long): CanceledPaymentEntityV2? {
|
||||||
|
log.debug { "[PaymentFinderV2.findCanceledPaymentByKey] 시작: paymentId=$paymentId" }
|
||||||
|
|
||||||
|
return canceledPaymentRepository.findByPaymentId(paymentId)?.also {
|
||||||
|
log.debug { "[PaymentFinderV2.findCanceledPaymentByKey] 완료: paymentId=$paymentId, canceledPaymentId=${it.id}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,4 +2,6 @@ package roomescape.payment.infrastructure.persistence.v2
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
|
||||||
interface CanceledPaymentRepositoryV2 : JpaRepository<CanceledPaymentEntityV2, Long>
|
interface CanceledPaymentRepositoryV2 : JpaRepository<CanceledPaymentEntityV2, Long> {
|
||||||
|
fun findByPaymentId(paymentId: Long): CanceledPaymentEntityV2?
|
||||||
|
}
|
||||||
|
|||||||
@ -2,4 +2,6 @@ package roomescape.payment.infrastructure.persistence.v2
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
|
||||||
interface PaymentDetailRepository: JpaRepository<PaymentDetailEntity, Long>
|
interface PaymentDetailRepository: JpaRepository<PaymentDetailEntity, Long> {
|
||||||
|
fun findByPaymentId(paymentId: Long) : PaymentDetailEntity?
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user