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

Merged
pricelees merged 41 commits from refactor/#41 into main 2025-09-09 00:43:39 +00:00
Showing only changes of commit 9ce66d8074 - Show all commits

View File

@ -52,7 +52,7 @@ class TosspayClient(
} }
private class ConfirmClient( private class ConfirmClient(
objectMapper: ObjectMapper, private val objectMapper: ObjectMapper,
private val client: RestClient, private val client: RestClient,
) { ) {
companion object { companion object {
@ -61,27 +61,33 @@ private class ConfirmClient(
private val errorHandler: TosspayErrorHandler = TosspayErrorHandler(objectMapper) private val errorHandler: TosspayErrorHandler = TosspayErrorHandler(objectMapper)
fun request(paymentKey: String, orderId: String, amount: Int): PaymentClientConfirmResponse = client.post() fun request(paymentKey: String, orderId: String, amount: Int): PaymentClientConfirmResponse {
.uri(CONFIRM_URI) val response = client.post()
.contentType(MediaType.APPLICATION_JSON) .uri(CONFIRM_URI)
.body( .contentType(MediaType.APPLICATION_JSON)
mapOf( .body(
"paymentKey" to paymentKey, mapOf(
"orderId" to orderId, "paymentKey" to paymentKey,
"amount" to amount "orderId" to orderId,
"amount" to amount
)
) )
) .retrieve()
.retrieve() .onStatus(errorHandler)
.onStatus(errorHandler) .body(String::class.java)
.body(PaymentClientConfirmResponse::class.java) ?: run {
?: run { log.error { "[TosspayClient] 응답 바디 변환 실패" }
log.error { "[TosspayConfirmClient.request] 응답 바디 변환 실패" } throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR) }
}
log.debug { "[TosspayClient.confirm] 응답 수신: json = $response" }
return objectMapper.readValue(response, PaymentClientConfirmResponse::class.java)
}
} }
private class CancelClient( private class CancelClient(
objectMapper: ObjectMapper, private val objectMapper: ObjectMapper,
private val client: RestClient, private val client: RestClient,
) { ) {
companion object { companion object {
@ -94,21 +100,26 @@ private class CancelClient(
paymentKey: String, paymentKey: String,
amount: Int, amount: Int,
cancelReason: String cancelReason: String
): PaymentClientCancelResponse = client.post() ): PaymentClientCancelResponse {
.uri(CANCEL_URI, paymentKey) val response = client.post()
.body( .uri(CANCEL_URI, paymentKey)
mapOf( .body(
"cancelReason" to cancelReason, mapOf(
"cancelAmount" to amount, "cancelReason" to cancelReason,
"cancelAmount" to amount,
)
) )
) .retrieve()
.retrieve() .onStatus(errorHandler)
.onStatus(errorHandler) .body(String::class.java)
.body(PaymentClientCancelResponse::class.java) ?: run {
?: run { log.error { "[TosspayClient] 응답 바디 변환 실패" }
log.error { "[TosspayClient] 응답 바디 변환 실패" } throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR) }
}
log.debug { "[TosspayClient.cancel] 응답 수신: json = $response" }
return objectMapper.readValue(response, PaymentClientCancelResponse::class.java)
}
} }
private class TosspayErrorHandler( private class TosspayErrorHandler(