충전이벤트가 적용되지 않는 버그 수정

This commit is contained in:
Klaus 2023-08-27 20:50:18 +09:00
parent a9d3427b6f
commit 9046c10d10
3 changed files with 10 additions and 38 deletions

View File

@ -3,7 +3,7 @@ package kr.co.vividnext.sodalive.can.charge
import com.fasterxml.jackson.databind.ObjectMapper
import kr.co.bootpay.Bootpay
import kr.co.vividnext.sodalive.can.CanRepository
import kr.co.vividnext.sodalive.can.charge.event.ChargeSpringEvent
import kr.co.vividnext.sodalive.can.charge.event.ChargeEventService
import kr.co.vividnext.sodalive.can.payment.Payment
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
import kr.co.vividnext.sodalive.can.payment.PaymentStatus
@ -16,7 +16,6 @@ import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.repository.findByIdOrNull
import org.springframework.http.HttpHeaders
import org.springframework.security.core.userdetails.User
@ -31,7 +30,7 @@ class ChargeService(
private val memberRepository: MemberRepository,
private val objectMapper: ObjectMapper,
private val okHttpClient: OkHttpClient,
private val applicationEventPublisher: ApplicationEventPublisher,
private val chargeEventService: ChargeEventService,
@Value("\${bootpay.application-id}")
private val bootpayApplicationId: String,
@ -85,11 +84,9 @@ class ChargeService(
charge.payment?.status = PaymentStatus.COMPLETE
member.charge(charge.chargeCan, charge.rewardCan, "pg")
applicationEventPublisher.publishEvent(
ChargeSpringEvent(
chargeId = charge.id!!,
memberId = member.id!!
)
chargeEventService.applyChargeEvent(
chargeId = charge.id!!,
memberId = member.id!!
)
} else {
throw SodaException("결제정보에 오류가 있습니다.")
@ -139,11 +136,9 @@ class ChargeService(
charge.payment?.status = PaymentStatus.COMPLETE
member.charge(charge.chargeCan, charge.rewardCan, "ios")
applicationEventPublisher.publishEvent(
ChargeSpringEvent(
chargeId = charge.id!!,
memberId = member.id!!
)
chargeEventService.applyChargeEvent(
chargeId = charge.id!!,
memberId = member.id!!
)
} else {
throw SodaException("결제정보에 오류가 있습니다.")

View File

@ -15,7 +15,6 @@ import kr.co.vividnext.sodalive.member.auth.AuthRepository
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import kotlin.math.ceil
import kotlin.math.round
@ -28,13 +27,12 @@ class ChargeEventService(
private val chargeEventRepository: ChargeEventRepository,
private val applicationEventPublisher: ApplicationEventPublisher
) {
@Transactional
fun applyChargeEvent(chargeId: Long, memberId: Long) {
val charge = chargeRepository.findByIdOrNull(chargeId)
?: throw SodaException("이벤트가 적용되지 않았습니다.\n고객센터에 문의해 주세요.")
?: throw SodaException("결제정보에 오류가 있습니다.")
val member = memberRepository.findByIdOrNull(memberId)
?: throw SodaException("이벤트가 적용되지 않았습니다.\n고객센터에 문의해 주세요.")
?: throw SodaException("결제정보에 오류가 있습니다.")
if (member.auth != null) {
val authDate = authRepository.getOldestCreatedAtByDi(member.auth!!.di)

View File

@ -1,21 +0,0 @@
package kr.co.vividnext.sodalive.can.charge.event
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component
import org.springframework.transaction.event.TransactionalEventListener
class ChargeSpringEvent(
val chargeId: Long,
val memberId: Long
)
@Component
class ChargeSpringEventListener(
private val chargeEventService: ChargeEventService
) {
@Async
@TransactionalEventListener
fun applyChargeEvent(event: ChargeSpringEvent) {
chargeEventService.applyChargeEvent(event.chargeId, event.memberId)
}
}