라이브 예약 취소 API
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package kr.co.vividnext.sodalive.can.payment
|
||||
|
||||
import kr.co.vividnext.sodalive.can.CanRepository
|
||||
import kr.co.vividnext.sodalive.can.charge.Charge
|
||||
import kr.co.vividnext.sodalive.can.charge.ChargeRepository
|
||||
import kr.co.vividnext.sodalive.can.charge.ChargeStatus
|
||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
||||
import kr.co.vividnext.sodalive.can.use.SpentCan
|
||||
import kr.co.vividnext.sodalive.can.use.TotalSpentCan
|
||||
@@ -18,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
@Service
|
||||
class CanPaymentService(
|
||||
private val repository: CanRepository,
|
||||
private val memberRepository: MemberRepository,
|
||||
private val chargeRepository: ChargeRepository,
|
||||
private val useCanRepository: UseCanRepository,
|
||||
@@ -242,4 +246,41 @@ class CanPaymentService(
|
||||
TotalSpentCan(total = 0)
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun refund(memberId: Long, roomId: Long) {
|
||||
val member = memberRepository.findByIdOrNull(memberId)
|
||||
?: throw SodaException("잘못된 예약정보 입니다.")
|
||||
|
||||
val useCan = repository.getCanUsedForLiveRoomNotRefund(
|
||||
memberId = memberId,
|
||||
roomId = roomId,
|
||||
canUsage = CanUsage.LIVE
|
||||
) ?: throw SodaException("잘못된 예약정보 입니다.")
|
||||
useCan.isRefund = true
|
||||
|
||||
val useCoinCalculates = useCanCalculateRepository.findByUseCanIdAndStatus(useCan.id!!)
|
||||
useCoinCalculates.forEach {
|
||||
it.status = UseCanCalculateStatus.REFUND
|
||||
val charge = Charge(0, it.can, status = ChargeStatus.REFUND_CHARGE)
|
||||
charge.title = "${it.can} 캔"
|
||||
charge.useCan = useCan
|
||||
|
||||
when (it.paymentGateway) {
|
||||
PaymentGateway.PG -> member.pgRewardCan += charge.rewardCan
|
||||
PaymentGateway.GOOGLE_IAP -> member.googleRewardCan += charge.rewardCan
|
||||
PaymentGateway.APPLE_IAP -> member.appleRewardCan += charge.rewardCan
|
||||
}
|
||||
charge.member = member
|
||||
|
||||
val payment = Payment(
|
||||
status = PaymentStatus.COMPLETE,
|
||||
paymentGateway = it.paymentGateway
|
||||
)
|
||||
payment.method = "환불"
|
||||
charge.payment = payment
|
||||
|
||||
chargeRepository.save(charge)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user