generated from pricelees/issue-pr-template
refactor: payment에서 client에 승인 요청 / 응답에만 사용되는 DTO 패키지 이동
This commit is contained in:
parent
9681de5e88
commit
f585c83197
@ -5,11 +5,15 @@ import org.springframework.stereotype.Service
|
|||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomescapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
|
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||||
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.PaymentEntity
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentRepository
|
import roomescape.payment.infrastructure.persistence.PaymentRepository
|
||||||
import roomescape.payment.web.*
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
|
import roomescape.payment.web.PaymentCancelResponse
|
||||||
|
import roomescape.payment.web.PaymentCreateResponse
|
||||||
|
import roomescape.payment.web.toCreateResponse
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@ -22,15 +26,15 @@ class PaymentService(
|
|||||||
fun createPayment(
|
fun createPayment(
|
||||||
paymentResponse: PaymentApproveResponse,
|
paymentResponse: PaymentApproveResponse,
|
||||||
reservation: ReservationEntity
|
reservation: ReservationEntity
|
||||||
): ReservationPaymentResponse = PaymentEntity(
|
): PaymentCreateResponse = PaymentEntity(
|
||||||
orderId = paymentResponse.orderId,
|
orderId = paymentResponse.orderId,
|
||||||
paymentKey = paymentResponse.paymentKey,
|
paymentKey = paymentResponse.paymentKey,
|
||||||
totalAmount = paymentResponse.totalAmount,
|
totalAmount = paymentResponse.amount,
|
||||||
reservation = reservation,
|
reservation = reservation,
|
||||||
approvedAt = paymentResponse.approvedAt
|
approvedAt = paymentResponse.approvedAt
|
||||||
).also {
|
).also {
|
||||||
paymentRepository.save(it)
|
paymentRepository.save(it)
|
||||||
}.toReservationPaymentResponse()
|
}.toCreateResponse()
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
fun isReservationPaid(
|
fun isReservationPaid(
|
||||||
|
|||||||
@ -12,8 +12,6 @@ import org.springframework.stereotype.Component
|
|||||||
import org.springframework.web.client.RestClient
|
import org.springframework.web.client.RestClient
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomescapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
import roomescape.payment.web.PaymentApproveRequest
|
|
||||||
import roomescape.payment.web.PaymentApproveResponse
|
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import roomescape.payment.web.PaymentCancelResponse
|
import roomescape.payment.web.PaymentCancelResponse
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
package roomescape.payment.infrastructure.client
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
|
data class TossPaymentErrorResponse(
|
||||||
|
val code: String,
|
||||||
|
val message: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PaymentApproveRequest(
|
||||||
|
val paymentKey: String,
|
||||||
|
val orderId: String,
|
||||||
|
val amount: Long,
|
||||||
|
val paymentType: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
data class PaymentApproveResponse(
|
||||||
|
val paymentKey: String,
|
||||||
|
val orderId: String,
|
||||||
|
val totalAmount: Long,
|
||||||
|
val approvedAt: OffsetDateTime
|
||||||
|
)
|
||||||
@ -1,6 +0,0 @@
|
|||||||
package roomescape.payment.infrastructure.client
|
|
||||||
|
|
||||||
data class TossPaymentErrorResponse(
|
|
||||||
val code: String,
|
|
||||||
val message: String
|
|
||||||
)
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
package roomescape.payment.web
|
package roomescape.payment.web
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||||
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
|
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||||
@ -8,21 +7,6 @@ import roomescape.reservation.web.ReservationResponse
|
|||||||
import roomescape.reservation.web.toCreateResponse
|
import roomescape.reservation.web.toCreateResponse
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
data class PaymentApproveRequest(
|
|
||||||
val paymentKey: String,
|
|
||||||
val orderId: String,
|
|
||||||
val amount: Long,
|
|
||||||
val paymentType: String
|
|
||||||
)
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
data class PaymentApproveResponse(
|
|
||||||
val paymentKey: String,
|
|
||||||
val orderId: String,
|
|
||||||
val approvedAt: OffsetDateTime,
|
|
||||||
val totalAmount: Long
|
|
||||||
)
|
|
||||||
|
|
||||||
data class PaymentCancelRequest(
|
data class PaymentCancelRequest(
|
||||||
val paymentKey: String,
|
val paymentKey: String,
|
||||||
val amount: Long,
|
val amount: Long,
|
||||||
@ -37,7 +21,7 @@ data class PaymentCancelResponse(
|
|||||||
val canceledAt: OffsetDateTime
|
val canceledAt: OffsetDateTime
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ReservationPaymentResponse(
|
data class PaymentCreateResponse(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val orderId: String,
|
val orderId: String,
|
||||||
val paymentKey: String,
|
val paymentKey: String,
|
||||||
@ -46,7 +30,7 @@ data class ReservationPaymentResponse(
|
|||||||
val approvedAt: OffsetDateTime
|
val approvedAt: OffsetDateTime
|
||||||
)
|
)
|
||||||
|
|
||||||
fun PaymentEntity.toReservationPaymentResponse(): ReservationPaymentResponse = ReservationPaymentResponse(
|
fun PaymentEntity.toCreateResponse(): PaymentCreateResponse = PaymentCreateResponse(
|
||||||
id = this.id!!,
|
id = this.id!!,
|
||||||
orderId = this.orderId,
|
orderId = this.orderId,
|
||||||
paymentKey = this.paymentKey,
|
paymentKey = this.paymentKey,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package roomescape.reservation.business
|
|||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import roomescape.payment.business.PaymentService
|
import roomescape.payment.business.PaymentService
|
||||||
import roomescape.payment.web.PaymentApproveResponse
|
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import roomescape.payment.web.PaymentCancelResponse
|
import roomescape.payment.web.PaymentCancelResponse
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
|
|||||||
@ -7,9 +7,9 @@ import org.springframework.web.bind.annotation.*
|
|||||||
import roomescape.auth.web.support.MemberId
|
import roomescape.auth.web.support.MemberId
|
||||||
import roomescape.common.dto.response.CommonApiResponse
|
import roomescape.common.dto.response.CommonApiResponse
|
||||||
import roomescape.common.exception.RoomescapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
|
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||||
import roomescape.payment.infrastructure.client.TossPaymentClient
|
import roomescape.payment.infrastructure.client.TossPaymentClient
|
||||||
import roomescape.payment.web.PaymentApproveRequest
|
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||||
import roomescape.payment.web.PaymentApproveResponse
|
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import roomescape.reservation.business.ReservationService
|
import roomescape.reservation.business.ReservationService
|
||||||
import roomescape.reservation.business.ReservationWithPaymentService
|
import roomescape.reservation.business.ReservationWithPaymentService
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package roomescape.reservation.web
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import roomescape.payment.web.PaymentApproveRequest
|
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
@Schema(name = "관리자 예약 저장 요청", description = "관리자의 예약 저장 요청시 사용됩니다.")
|
@Schema(name = "관리자 예약 저장 요청", description = "관리자의 예약 저장 요청시 사용됩니다.")
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package roomescape.payment.infrastructure.client
|
package roomescape.payment.infrastructure.client
|
||||||
|
|
||||||
import roomescape.payment.web.PaymentApproveRequest
|
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import org.springframework.test.web.client.response.MockRestResponseCreators.wit
|
|||||||
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
|
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomescapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
import roomescape.payment.web.PaymentApproveResponse
|
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import roomescape.payment.web.PaymentCancelResponse
|
import roomescape.payment.web.PaymentCancelResponse
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ class TossPaymentClientTest(
|
|||||||
assertSoftly(paymentResponse) {
|
assertSoftly(paymentResponse) {
|
||||||
this.paymentKey shouldBe paymentRequest.paymentKey
|
this.paymentKey shouldBe paymentRequest.paymentKey
|
||||||
this.orderId shouldBe paymentRequest.orderId
|
this.orderId shouldBe paymentRequest.orderId
|
||||||
this.totalAmount shouldBe paymentRequest.amount
|
this.amount shouldBe paymentRequest.amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import io.mockk.mockk
|
|||||||
import roomescape.payment.business.PaymentService
|
import roomescape.payment.business.PaymentService
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import roomescape.payment.web.toReservationPaymentResponse
|
import roomescape.payment.web.toCreateResponse
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
||||||
import roomescape.reservation.web.ReservationRequest
|
import roomescape.reservation.web.ReservationRequest
|
||||||
@ -53,7 +53,7 @@ class ReservationWithPaymentServiceTest : FunSpec({
|
|||||||
|
|
||||||
every {
|
every {
|
||||||
paymentService.createPayment(paymentApproveResponse, reservationEntity)
|
paymentService.createPayment(paymentApproveResponse, reservationEntity)
|
||||||
} returns paymentEntity.toReservationPaymentResponse()
|
} returns paymentEntity.toCreateResponse()
|
||||||
|
|
||||||
val result: ReservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
val result: ReservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
||||||
request = reservationRequest,
|
request = reservationRequest,
|
||||||
|
|||||||
@ -66,7 +66,7 @@ class ReservationControllerTest(
|
|||||||
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
|
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
|
||||||
paymentKey = reservationRequest.paymentKey,
|
paymentKey = reservationRequest.paymentKey,
|
||||||
orderId = reservationRequest.orderId,
|
orderId = reservationRequest.orderId,
|
||||||
totalAmount = reservationRequest.amount,
|
amount = reservationRequest.amount,
|
||||||
)
|
)
|
||||||
|
|
||||||
every {
|
every {
|
||||||
@ -116,7 +116,7 @@ class ReservationControllerTest(
|
|||||||
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
|
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
|
||||||
paymentKey = reservationRequest.paymentKey,
|
paymentKey = reservationRequest.paymentKey,
|
||||||
orderId = reservationRequest.orderId,
|
orderId = reservationRequest.orderId,
|
||||||
totalAmount = reservationRequest.amount,
|
amount = reservationRequest.amount,
|
||||||
)
|
)
|
||||||
|
|
||||||
every {
|
every {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import roomescape.member.infrastructure.persistence.MemberEntity
|
|||||||
import roomescape.member.infrastructure.persistence.Role
|
import roomescape.member.infrastructure.persistence.Role
|
||||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity
|
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||||
import roomescape.payment.web.PaymentApproveRequest
|
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||||
import roomescape.payment.web.PaymentApproveResponse
|
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||||
import roomescape.payment.web.PaymentCancelRequest
|
import roomescape.payment.web.PaymentCancelRequest
|
||||||
import roomescape.payment.web.PaymentCancelResponse
|
import roomescape.payment.web.PaymentCancelResponse
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
@ -168,7 +168,7 @@ object PaymentFixture {
|
|||||||
paymentKey = PAYMENT_KEY,
|
paymentKey = PAYMENT_KEY,
|
||||||
orderId = ORDER_ID,
|
orderId = ORDER_ID,
|
||||||
approvedAt = OffsetDateTime.now(),
|
approvedAt = OffsetDateTime.now(),
|
||||||
totalAmount = AMOUNT
|
amount = AMOUNT
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createCancelRequest(): PaymentCancelRequest = PaymentCancelRequest(
|
fun createCancelRequest(): PaymentCancelRequest = PaymentCancelRequest(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user