generated from pricelees/issue-pr-template
feat: PaymentEvent 객체 정의 및 매핑 확장함수 추가
This commit is contained in:
parent
257fcb517d
commit
f4b9d1207e
@ -0,0 +1,22 @@
|
||||
package com.sangdol.roomescape.payment.business.event
|
||||
|
||||
import com.sangdol.roomescape.payment.business.domain.PaymentDetail
|
||||
import com.sangdol.roomescape.payment.business.domain.PaymentMethod
|
||||
import com.sangdol.roomescape.payment.business.domain.PaymentStatus
|
||||
import com.sangdol.roomescape.payment.business.domain.PaymentType
|
||||
import java.time.Instant
|
||||
|
||||
class PaymentEvent(
|
||||
val reservationId: Long,
|
||||
val paymentKey: String,
|
||||
val orderId: String,
|
||||
val type: PaymentType,
|
||||
val status: PaymentStatus,
|
||||
val totalAmount: Int,
|
||||
val vat: Int,
|
||||
val suppliedAmount: Int,
|
||||
val method: PaymentMethod,
|
||||
val requestedAt: Instant,
|
||||
val approvedAt: Instant,
|
||||
val detail: PaymentDetail
|
||||
)
|
||||
@ -0,0 +1,53 @@
|
||||
package com.sangdol.roomescape.payment.mapper
|
||||
|
||||
import com.sangdol.roomescape.payment.business.domain.*
|
||||
import com.sangdol.roomescape.payment.business.event.PaymentEvent
|
||||
import com.sangdol.roomescape.payment.exception.PaymentErrorCode
|
||||
import com.sangdol.roomescape.payment.exception.PaymentException
|
||||
import com.sangdol.roomescape.payment.infrastructure.persistence.PaymentDetailEntity
|
||||
import com.sangdol.roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||
|
||||
fun PaymentEvent.toEntity(id: Long) = PaymentEntity(
|
||||
id = id,
|
||||
reservationId = this.reservationId,
|
||||
paymentKey = this.paymentKey,
|
||||
orderId = this.orderId,
|
||||
totalAmount = this.totalAmount,
|
||||
requestedAt = this.requestedAt,
|
||||
approvedAt = this.approvedAt,
|
||||
type = this.type,
|
||||
method = this.method,
|
||||
status = this.status
|
||||
)
|
||||
|
||||
fun PaymentEvent.toDetailEntity(id: Long, paymentId: Long): PaymentDetailEntity {
|
||||
val suppliedAmount = this.suppliedAmount
|
||||
val vat = this.vat
|
||||
|
||||
return when (this.method) {
|
||||
PaymentMethod.TRANSFER -> {
|
||||
(this.detail as? BankTransferPaymentDetail)
|
||||
?.toEntity(id, paymentId, suppliedAmount, vat)
|
||||
?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
}
|
||||
|
||||
PaymentMethod.EASY_PAY -> {
|
||||
when (this.detail) {
|
||||
is EasypayCardPaymentDetail -> { this.detail.toEntity(id, paymentId, suppliedAmount, vat) }
|
||||
is EasypayPrepaidPaymentDetail -> { this.detail.toEntity(id, paymentId, suppliedAmount, vat) }
|
||||
|
||||
else -> {
|
||||
throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PaymentMethod.CARD -> {
|
||||
(this.detail as? CardPaymentDetail)
|
||||
?.toEntity(id, paymentId, suppliedAmount, vat)
|
||||
?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
}
|
||||
|
||||
else -> throw PaymentException(PaymentErrorCode.NOT_SUPPORTED_PAYMENT_TYPE)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user