generated from pricelees/issue-pr-template
[#41] 예약 스키마 재정의 #42
@ -1,38 +1,138 @@
|
|||||||
package roomescape.payment.web
|
package roomescape.payment.web
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
import roomescape.payment.exception.PaymentErrorCode
|
||||||
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
|
import roomescape.payment.exception.PaymentException
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
import roomescape.payment.infrastructure.common.PaymentStatus
|
||||||
|
import roomescape.payment.infrastructure.common.PaymentType
|
||||||
|
import roomescape.payment.infrastructure.persistence.*
|
||||||
|
import roomescape.payment.web.PaymentDetailResponse.BankTransferDetailResponse
|
||||||
|
import roomescape.payment.web.PaymentDetailResponse.CardDetailResponse
|
||||||
|
import roomescape.payment.web.PaymentDetailResponse.EasyPayPrepaidDetailResponse
|
||||||
|
import java.time.LocalDateTime
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
data class PaymentCancelRequest(
|
data class PaymentConfirmRequest(
|
||||||
val paymentKey: String,
|
val paymentKey: String,
|
||||||
val amount: Long,
|
val orderId: String,
|
||||||
val cancelReason: String
|
val amount: Int,
|
||||||
)
|
val paymentType: PaymentType
|
||||||
|
|
||||||
@JsonDeserialize(using = PaymentCancelResponseDeserializer::class)
|
|
||||||
data class PaymentCancelResponse(
|
|
||||||
val cancelStatus: String,
|
|
||||||
val cancelReason: String,
|
|
||||||
val cancelAmount: Long,
|
|
||||||
val canceledAt: OffsetDateTime
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class PaymentCreateResponse(
|
data class PaymentCreateResponse(
|
||||||
val id: Long,
|
val paymentId: Long,
|
||||||
val orderId: String,
|
val detailId: Long
|
||||||
val paymentKey: String,
|
|
||||||
val totalAmount: Long,
|
|
||||||
val reservationId: Long,
|
|
||||||
val approvedAt: OffsetDateTime
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fun PaymentEntity.toCreateResponse() = PaymentCreateResponse(
|
data class PaymentCancelRequest(
|
||||||
id = this.id!!,
|
val reservationId: Long,
|
||||||
orderId = this.orderId,
|
val cancelReason: String,
|
||||||
paymentKey = this.paymentKey,
|
val requestedAt: LocalDateTime = LocalDateTime.now()
|
||||||
totalAmount = this.totalAmount,
|
|
||||||
reservationId = this.reservation.id!!,
|
|
||||||
approvedAt = this.approvedAt
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class PaymentRetrieveResponse(
|
||||||
|
val orderId: String,
|
||||||
|
val totalAmount: Int,
|
||||||
|
val method: String,
|
||||||
|
val status: PaymentStatus,
|
||||||
|
val requestedAt: OffsetDateTime,
|
||||||
|
val approvedAt: OffsetDateTime,
|
||||||
|
val detail: PaymentDetailResponse,
|
||||||
|
val cancel: PaymentCancelDetailResponse?,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun PaymentEntity.toRetrieveResponse(
|
||||||
|
detail: PaymentDetailResponse,
|
||||||
|
cancel: PaymentCancelDetailResponse?
|
||||||
|
): PaymentRetrieveResponse {
|
||||||
|
return PaymentRetrieveResponse(
|
||||||
|
orderId = this.orderId,
|
||||||
|
totalAmount = this.totalAmount,
|
||||||
|
method = this.method.koreanName,
|
||||||
|
status = this.status,
|
||||||
|
requestedAt = this.requestedAt,
|
||||||
|
approvedAt = this.approvedAt,
|
||||||
|
detail = detail,
|
||||||
|
cancel = cancel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class PaymentDetailResponse {
|
||||||
|
|
||||||
|
data class CardDetailResponse(
|
||||||
|
val type: String = "CARD",
|
||||||
|
val issuerCode: String,
|
||||||
|
val cardType: String,
|
||||||
|
val ownerType: String,
|
||||||
|
val cardNumber: String,
|
||||||
|
val amount: Int,
|
||||||
|
val approvalNumber: String,
|
||||||
|
val installmentPlanMonths: Int,
|
||||||
|
val easypayProviderName: String?,
|
||||||
|
val easypayDiscountAmount: Int?,
|
||||||
|
) : PaymentDetailResponse()
|
||||||
|
|
||||||
|
data class BankTransferDetailResponse(
|
||||||
|
val type: String = "BANK_TRANSFER",
|
||||||
|
val bankName: String,
|
||||||
|
) : PaymentDetailResponse()
|
||||||
|
|
||||||
|
data class EasyPayPrepaidDetailResponse(
|
||||||
|
val type: String = "EASYPAY_PREPAID",
|
||||||
|
val providerName: String,
|
||||||
|
val amount: Int,
|
||||||
|
val discountAmount: Int,
|
||||||
|
) : PaymentDetailResponse()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PaymentDetailEntity.toPaymentDetailResponse(): PaymentDetailResponse {
|
||||||
|
return when (this) {
|
||||||
|
is PaymentCardDetailEntity -> this.toCardDetailResponse()
|
||||||
|
is PaymentBankTransferDetailEntity -> this.toBankTransferDetailResponse()
|
||||||
|
is PaymentEasypayPrepaidDetailEntity -> this.toEasyPayPrepaidDetailResponse()
|
||||||
|
else -> throw PaymentException(PaymentErrorCode.NOT_SUPPORTED_PAYMENT_TYPE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PaymentCardDetailEntity.toCardDetailResponse(): CardDetailResponse {
|
||||||
|
return CardDetailResponse(
|
||||||
|
issuerCode = this.issuerCode.koreanName,
|
||||||
|
cardType = this.cardType.koreanName,
|
||||||
|
ownerType = this.ownerType.koreanName,
|
||||||
|
cardNumber = this.cardNumber,
|
||||||
|
amount = this.amount,
|
||||||
|
approvalNumber = this.approvalNumber,
|
||||||
|
installmentPlanMonths = this.installmentPlanMonths,
|
||||||
|
easypayProviderName = this.easypayProviderCode?.koreanName,
|
||||||
|
easypayDiscountAmount = this.easypayDiscountAmount
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PaymentBankTransferDetailEntity.toBankTransferDetailResponse(): BankTransferDetailResponse {
|
||||||
|
return BankTransferDetailResponse(
|
||||||
|
bankName = this.bankCode.koreanName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PaymentEasypayPrepaidDetailEntity.toEasyPayPrepaidDetailResponse(): EasyPayPrepaidDetailResponse {
|
||||||
|
return EasyPayPrepaidDetailResponse(
|
||||||
|
providerName = this.easypayProviderCode.koreanName,
|
||||||
|
amount = this.amount,
|
||||||
|
discountAmount = this.discountAmount
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class PaymentCancelDetailResponse(
|
||||||
|
val cancellationRequestedAt: LocalDateTime,
|
||||||
|
val cancellationApprovedAt: OffsetDateTime?,
|
||||||
|
val cancelReason: String,
|
||||||
|
val canceledBy: Long,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun CanceledPaymentEntity.toCancelDetailResponse(): PaymentCancelDetailResponse {
|
||||||
|
return PaymentCancelDetailResponse(
|
||||||
|
cancellationRequestedAt = this.requestedAt,
|
||||||
|
cancellationApprovedAt = this.canceledAt,
|
||||||
|
cancelReason = this.cancelReason,
|
||||||
|
canceledBy = this.canceledBy
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user