65 lines
2.0 KiB
Kotlin

package roomescape.payment.web
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
import roomescape.payment.infrastructure.persistence.PaymentEntity
import roomescape.reservation.dto.response.ReservationResponse
import java.time.OffsetDateTime
class PaymentApprove {
@JvmRecord
data class Request(
@JvmField val paymentKey: String,
@JvmField val orderId: String,
@JvmField val amount: Long,
@JvmField val paymentType: String
)
@JvmRecord
@JsonIgnoreProperties(ignoreUnknown = true)
data class Response(
@JvmField val paymentKey: String,
@JvmField val orderId: String,
@JvmField val approvedAt: OffsetDateTime,
@JvmField val totalAmount: Long
)
}
class PaymentCancel {
@JvmRecord
data class Request(
@JvmField val paymentKey: String,
@JvmField val amount: Long,
@JvmField val cancelReason: String
)
@JvmRecord
@JsonDeserialize(using = PaymentCancelResponseDeserializer::class)
data class Response(
@JvmField val cancelStatus: String,
@JvmField val cancelReason: String,
@JvmField val cancelAmount: Long,
@JvmField val canceledAt: OffsetDateTime
)
}
@JvmRecord
data class ReservationPaymentResponse(
val id: Long,
val orderId: String,
val paymentKey: String,
val totalAmount: Long,
val reservation: ReservationResponse,
val approvedAt: OffsetDateTime
)
fun PaymentEntity.toReservationPaymentResponse(): ReservationPaymentResponse = ReservationPaymentResponse(
id = this.id!!,
orderId = this.orderId,
paymentKey = this.paymentKey,
totalAmount = this.totalAmount,
reservation = ReservationResponse.from(this.reservation),
approvedAt = this.approvedAt
)