[#41] 예약 스키마 재정의 #42

Merged
pricelees merged 41 commits from refactor/#41 into main 2025-09-09 00:43:39 +00:00
3 changed files with 16 additions and 16 deletions
Showing only changes of commit 752943a9f7 - Show all commits

View File

@ -9,7 +9,7 @@ import roomescape.payment.exception.PaymentErrorCode
import roomescape.payment.exception.PaymentException import roomescape.payment.exception.PaymentException
import roomescape.payment.infrastructure.client.PaymentClientCancelResponse import roomescape.payment.infrastructure.client.PaymentClientCancelResponse
import roomescape.payment.infrastructure.client.PaymentClientConfirmResponse import roomescape.payment.infrastructure.client.PaymentClientConfirmResponse
import roomescape.payment.infrastructure.client.TosspaymentClient import roomescape.payment.infrastructure.client.TosspayClient
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository
import roomescape.payment.infrastructure.persistence.PaymentDetailEntity import roomescape.payment.infrastructure.persistence.PaymentDetailEntity
@ -28,7 +28,7 @@ private val log: KLogger = KotlinLogging.logger {}
@Service @Service
class PaymentService( class PaymentService(
private val paymentClient: TosspaymentClient, private val paymentClient: TosspayClient,
private val paymentRepository: PaymentRepository, private val paymentRepository: PaymentRepository,
private val paymentDetailRepository: PaymentDetailRepository, private val paymentDetailRepository: PaymentDetailRepository,
private val canceledPaymentRepository: CanceledPaymentRepository, private val canceledPaymentRepository: CanceledPaymentRepository,

View File

@ -17,23 +17,23 @@ import java.net.URI
private val log: KLogger = KotlinLogging.logger {} private val log: KLogger = KotlinLogging.logger {}
@Component @Component
class TosspaymentClient( class TosspayClient(
objectMapper: ObjectMapper, objectMapper: ObjectMapper,
tossPaymentClientBuilder: RestClient.Builder tosspayClientBuilder: RestClient.Builder
) { ) {
private val confirmClient = ConfirmClient(objectMapper, tossPaymentClientBuilder.build()) private val confirmClient = ConfirmClient(objectMapper, tosspayClientBuilder.build())
private val cancelClient = CancelClient(objectMapper, tossPaymentClientBuilder.build()) private val cancelClient = CancelClient(objectMapper, tosspayClientBuilder.build())
fun confirm( fun confirm(
paymentKey: String, paymentKey: String,
orderId: String, orderId: String,
amount: Int, amount: Int,
): PaymentClientConfirmResponse { ): PaymentClientConfirmResponse {
log.info { "[TossPaymentClient.confirm] 결제 승인 요청: paymentKey=$paymentKey, orderId=$orderId, amount=$amount" } log.info { "[TosspayClient.confirm] 결제 승인 요청: paymentKey=$paymentKey, orderId=$orderId, amount=$amount" }
return confirmClient.request(paymentKey, orderId, amount) return confirmClient.request(paymentKey, orderId, amount)
.also { .also {
log.info { "[TossPaymentClient.confirm] 결제 승인 완료: response=$it" } log.info { "[TosspayClient.confirm] 결제 승인 완료: response=$it" }
} }
} }
@ -43,10 +43,10 @@ class TosspaymentClient(
amount: Int, amount: Int,
cancelReason: String cancelReason: String
): PaymentClientCancelResponse { ): PaymentClientCancelResponse {
log.info { "[TossPaymentClient.cancel] 결제 취소 요청: paymentKey=$paymentKey, amount=$amount, cancelReason=$cancelReason" } log.info { "[TosspayClient.cancel] 결제 취소 요청: paymentKey=$paymentKey, amount=$amount, cancelReason=$cancelReason" }
return cancelClient.request(paymentKey, amount, cancelReason).also { return cancelClient.request(paymentKey, amount, cancelReason).also {
log.info { "[TossPaymentClient.cancel] 결제 취소 완료: response=$it" } log.info { "[TosspayClient.cancel] 결제 취소 완료: response=$it" }
} }
} }
} }
@ -75,7 +75,7 @@ private class ConfirmClient(
.onStatus(errorHandler) .onStatus(errorHandler)
.body(PaymentClientConfirmResponse::class.java) .body(PaymentClientConfirmResponse::class.java)
?: run { ?: run {
log.error { "[TossPaymentConfirmClient.request] 응답 바디 변환 실패" } log.error { "[TosspayConfirmClient.request] 응답 바디 변환 실패" }
throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR) throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
} }
} }
@ -106,7 +106,7 @@ private class CancelClient(
.onStatus(errorHandler) .onStatus(errorHandler)
.body(PaymentClientCancelResponse::class.java) .body(PaymentClientCancelResponse::class.java)
?: run { ?: run {
log.error { "[TossPaymentClient] 응답 바디 변환 실패" } log.error { "[TosspayClient] 응답 바디 변환 실패" }
throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR) throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
} }
} }
@ -126,7 +126,7 @@ private class TosspayErrorHandler(
response: ClientHttpResponse response: ClientHttpResponse
): Nothing { ): Nothing {
val requestType: String = paymentRequestType(url) val requestType: String = paymentRequestType(url)
log.warn { "[TossPaymentClient] $requestType 요청 실패: response: ${parseResponse(response)}" } log.warn { "[TosspayClient] $requestType 요청 실패: response: ${parseResponse(response)}" }
throw PaymentException(paymentErrorCode(response.statusCode)) throw PaymentException(paymentErrorCode(response.statusCode))
} }
@ -146,10 +146,10 @@ private class TosspayErrorHandler(
PaymentErrorCode.PAYMENT_PROVIDER_ERROR PaymentErrorCode.PAYMENT_PROVIDER_ERROR
} }
private fun parseResponse(response: ClientHttpResponse): TossPaymentErrorResponse { private fun parseResponse(response: ClientHttpResponse): TosspayErrorResponse {
val body = response.body val body = response.body
return objectMapper.readValue(body, TossPaymentErrorResponse::class.java).also { return objectMapper.readValue(body, TosspayErrorResponse::class.java).also {
body.close() body.close()
} }
} }

View File

@ -1,6 +1,6 @@
package roomescape.payment.infrastructure.client package roomescape.payment.infrastructure.client
data class TossPaymentErrorResponse( data class TosspayErrorResponse(
val code: String, val code: String,
val message: String val message: String
) )