충전이벤트가 적용되지 않는 버그 수정
This commit is contained in:
parent
a9d3427b6f
commit
9046c10d10
|
@ -3,7 +3,7 @@ package kr.co.vividnext.sodalive.can.charge
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import kr.co.bootpay.Bootpay
|
import kr.co.bootpay.Bootpay
|
||||||
import kr.co.vividnext.sodalive.can.CanRepository
|
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.Payment
|
||||||
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
|
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
|
||||||
import kr.co.vividnext.sodalive.can.payment.PaymentStatus
|
import kr.co.vividnext.sodalive.can.payment.PaymentStatus
|
||||||
|
@ -16,7 +16,6 @@ import okhttp3.Request
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.http.HttpHeaders
|
import org.springframework.http.HttpHeaders
|
||||||
import org.springframework.security.core.userdetails.User
|
import org.springframework.security.core.userdetails.User
|
||||||
|
@ -31,7 +30,7 @@ class ChargeService(
|
||||||
private val memberRepository: MemberRepository,
|
private val memberRepository: MemberRepository,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val okHttpClient: OkHttpClient,
|
private val okHttpClient: OkHttpClient,
|
||||||
private val applicationEventPublisher: ApplicationEventPublisher,
|
private val chargeEventService: ChargeEventService,
|
||||||
|
|
||||||
@Value("\${bootpay.application-id}")
|
@Value("\${bootpay.application-id}")
|
||||||
private val bootpayApplicationId: String,
|
private val bootpayApplicationId: String,
|
||||||
|
@ -85,11 +84,9 @@ class ChargeService(
|
||||||
charge.payment?.status = PaymentStatus.COMPLETE
|
charge.payment?.status = PaymentStatus.COMPLETE
|
||||||
member.charge(charge.chargeCan, charge.rewardCan, "pg")
|
member.charge(charge.chargeCan, charge.rewardCan, "pg")
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
chargeEventService.applyChargeEvent(
|
||||||
ChargeSpringEvent(
|
chargeId = charge.id!!,
|
||||||
chargeId = charge.id!!,
|
memberId = member.id!!
|
||||||
memberId = member.id!!
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw SodaException("결제정보에 오류가 있습니다.")
|
throw SodaException("결제정보에 오류가 있습니다.")
|
||||||
|
@ -139,11 +136,9 @@ class ChargeService(
|
||||||
charge.payment?.status = PaymentStatus.COMPLETE
|
charge.payment?.status = PaymentStatus.COMPLETE
|
||||||
member.charge(charge.chargeCan, charge.rewardCan, "ios")
|
member.charge(charge.chargeCan, charge.rewardCan, "ios")
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
chargeEventService.applyChargeEvent(
|
||||||
ChargeSpringEvent(
|
chargeId = charge.id!!,
|
||||||
chargeId = charge.id!!,
|
memberId = member.id!!
|
||||||
memberId = member.id!!
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw SodaException("결제정보에 오류가 있습니다.")
|
throw SodaException("결제정보에 오류가 있습니다.")
|
||||||
|
|
|
@ -15,7 +15,6 @@ import kr.co.vividnext.sodalive.member.auth.AuthRepository
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Transactional
|
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
|
|
||||||
|
@ -28,13 +27,12 @@ class ChargeEventService(
|
||||||
private val chargeEventRepository: ChargeEventRepository,
|
private val chargeEventRepository: ChargeEventRepository,
|
||||||
private val applicationEventPublisher: ApplicationEventPublisher
|
private val applicationEventPublisher: ApplicationEventPublisher
|
||||||
) {
|
) {
|
||||||
@Transactional
|
|
||||||
fun applyChargeEvent(chargeId: Long, memberId: Long) {
|
fun applyChargeEvent(chargeId: Long, memberId: Long) {
|
||||||
val charge = chargeRepository.findByIdOrNull(chargeId)
|
val charge = chargeRepository.findByIdOrNull(chargeId)
|
||||||
?: throw SodaException("이벤트가 적용되지 않았습니다.\n고객센터에 문의해 주세요.")
|
?: throw SodaException("결제정보에 오류가 있습니다.")
|
||||||
|
|
||||||
val member = memberRepository.findByIdOrNull(memberId)
|
val member = memberRepository.findByIdOrNull(memberId)
|
||||||
?: throw SodaException("이벤트가 적용되지 않았습니다.\n고객센터에 문의해 주세요.")
|
?: throw SodaException("결제정보에 오류가 있습니다.")
|
||||||
|
|
||||||
if (member.auth != null) {
|
if (member.auth != null) {
|
||||||
val authDate = authRepository.getOldestCreatedAtByDi(member.auth!!.di)
|
val authDate = authRepository.getOldestCreatedAtByDi(member.auth!!.di)
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue