generated from pricelees/issue-pr-template
feat: PaymentClient에서 받은 외부 API 응답을 이벤트로 매핑하는 확장함수 추가 및 이전 커밋의 PaymentEventListenerTest 패키지 이동
This commit is contained in:
parent
e0e7902654
commit
dbd2b9fb0c
@ -1,5 +1,7 @@
|
||||
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.dto.CancelDetail
|
||||
import com.sangdol.roomescape.payment.dto.PaymentGatewayResponse
|
||||
import com.sangdol.roomescape.payment.exception.PaymentErrorCode
|
||||
@ -94,3 +96,88 @@ fun CancelDetail.toEntity(
|
||||
transferDiscountAmount = this.transferDiscountAmount,
|
||||
easypayDiscountAmount = this.easyPayDiscountAmount
|
||||
)
|
||||
|
||||
fun PaymentGatewayResponse.toEvent(reservationId: Long): PaymentEvent {
|
||||
return PaymentEvent(
|
||||
reservationId = reservationId,
|
||||
paymentKey = this.paymentKey,
|
||||
orderId = this.orderId,
|
||||
type = this.type,
|
||||
status = this.status,
|
||||
totalAmount = this.totalAmount,
|
||||
vat = this.vat,
|
||||
suppliedAmount = this.suppliedAmount,
|
||||
method = this.method,
|
||||
requestedAt = this.requestedAt.toInstant(),
|
||||
approvedAt = this.approvedAt.toInstant(),
|
||||
detail = this.toDetail()
|
||||
)
|
||||
}
|
||||
|
||||
fun PaymentGatewayResponse.toDetail(): PaymentDetail {
|
||||
return when(this.method) {
|
||||
PaymentMethod.TRANSFER -> this.toBankTransferDetail()
|
||||
PaymentMethod.CARD -> this.toCardDetail()
|
||||
PaymentMethod.EASY_PAY -> {
|
||||
if (this.card != null) {
|
||||
this.toEasypayCardDetail()
|
||||
} else {
|
||||
this.toEasypayPrepaidDetail()
|
||||
}
|
||||
}
|
||||
|
||||
else -> throw PaymentException(PaymentErrorCode.NOT_SUPPORTED_PAYMENT_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun PaymentGatewayResponse.toBankTransferDetail(): BankTransferPaymentDetail {
|
||||
val bankTransfer = this.transfer ?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
|
||||
return BankTransferPaymentDetail(
|
||||
bankCode = bankTransfer.bankCode,
|
||||
settlementStatus = bankTransfer.settlementStatus
|
||||
)
|
||||
}
|
||||
|
||||
private fun PaymentGatewayResponse.toCardDetail(): CardPaymentDetail {
|
||||
val cardDetail = this.card ?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
|
||||
return CardPaymentDetail(
|
||||
issuerCode = cardDetail.issuerCode,
|
||||
number = cardDetail.number,
|
||||
amount = cardDetail.amount,
|
||||
cardType = cardDetail.cardType,
|
||||
ownerType = cardDetail.ownerType,
|
||||
isInterestFree = cardDetail.isInterestFree,
|
||||
approveNo = cardDetail.approveNo,
|
||||
installmentPlanMonths = cardDetail.installmentPlanMonths
|
||||
)
|
||||
}
|
||||
|
||||
private fun PaymentGatewayResponse.toEasypayCardDetail(): EasypayCardPaymentDetail {
|
||||
val cardDetail = this.card ?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
val easypay = this.easyPay ?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
|
||||
return EasypayCardPaymentDetail(
|
||||
issuerCode = cardDetail.issuerCode,
|
||||
number = cardDetail.number,
|
||||
amount = cardDetail.amount,
|
||||
cardType = cardDetail.cardType,
|
||||
ownerType = cardDetail.ownerType,
|
||||
isInterestFree = cardDetail.isInterestFree,
|
||||
approveNo = cardDetail.approveNo,
|
||||
installmentPlanMonths = cardDetail.installmentPlanMonths,
|
||||
easypayProvider = easypay.provider,
|
||||
easypayDiscountAmount = easypay.discountAmount
|
||||
)
|
||||
}
|
||||
|
||||
private fun PaymentGatewayResponse.toEasypayPrepaidDetail(): EasypayPrepaidPaymentDetail {
|
||||
val easypay = this.easyPay ?: throw PaymentException(PaymentErrorCode.PAYMENT_UNEXPECTED_ERROR)
|
||||
|
||||
return EasypayPrepaidPaymentDetail(
|
||||
provider = easypay.provider,
|
||||
amount = easypay.amount,
|
||||
discountAmount = easypay.discountAmount
|
||||
)
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.sangdol.roomescape.payment.business.event
|
||||
package com.sangdol.roomescape.payment
|
||||
|
||||
import com.sangdol.roomescape.payment.business.domain.PaymentMethod
|
||||
import com.sangdol.roomescape.payment.business.event.PaymentEventListener
|
||||
import com.sangdol.roomescape.payment.infrastructure.persistence.PaymentCardDetailEntity
|
||||
import com.sangdol.roomescape.payment.infrastructure.persistence.PaymentDetailRepository
|
||||
import com.sangdol.roomescape.payment.infrastructure.persistence.PaymentRepository
|
||||
@ -50,4 +51,4 @@ class PaymentEventListenerTest(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user