From f4b9d1207e78f8707ac195e6bf3a9e1d27f8814f Mon Sep 17 00:00:00 2001 From: pricelees Date: Thu, 16 Oct 2025 10:26:34 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20PaymentEvent=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=20=EB=B0=8F=20=EB=A7=A4=ED=95=91=20=ED=99=95?= =?UTF-8?q?=EC=9E=A5=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/business/event/PaymentEvent.kt | 22 ++++++++ .../mapper/PaymentEventMappingExtensions.kt | 53 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 service/src/main/kotlin/com/sangdol/roomescape/payment/business/event/PaymentEvent.kt create mode 100644 service/src/main/kotlin/com/sangdol/roomescape/payment/mapper/PaymentEventMappingExtensions.kt diff --git a/service/src/main/kotlin/com/sangdol/roomescape/payment/business/event/PaymentEvent.kt b/service/src/main/kotlin/com/sangdol/roomescape/payment/business/event/PaymentEvent.kt new file mode 100644 index 00000000..d8db4678 --- /dev/null +++ b/service/src/main/kotlin/com/sangdol/roomescape/payment/business/event/PaymentEvent.kt @@ -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 +) diff --git a/service/src/main/kotlin/com/sangdol/roomescape/payment/mapper/PaymentEventMappingExtensions.kt b/service/src/main/kotlin/com/sangdol/roomescape/payment/mapper/PaymentEventMappingExtensions.kt new file mode 100644 index 00000000..c25c8cc2 --- /dev/null +++ b/service/src/main/kotlin/com/sangdol/roomescape/payment/mapper/PaymentEventMappingExtensions.kt @@ -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) + } +}