구글 인 앱 결제 처리과정 축소 #150

Merged
klaus merged 1 commits from test into main 2024-03-22 15:27:25 +00:00
3 changed files with 10 additions and 29 deletions

View File

@ -61,10 +61,4 @@ class ChargeController(private val service: ChargeService) {
ApiResponse.ok(service.googleCharge(member, request))
}
@PostMapping("/google/verify")
fun googleVerify(
@RequestBody request: GoogleVerifyRequest,
@AuthenticationPrincipal user: User
) = ApiResponse.ok(service.googleVerify(user, request))
}

View File

@ -39,7 +39,7 @@ data class GoogleChargeRequest(
val chargeCan: Int,
val price: Double,
val currencyCode: String,
val productId: String,
val purchaseToken: String,
val paymentGateway: PaymentGateway
)
data class GoogleVerifyRequest(val productId: String, val purchaseToken: String, val chargeId: Long)

View File

@ -187,7 +187,7 @@ class ChargeService(
}
@Transactional
fun googleCharge(member: Member, request: GoogleChargeRequest): ChargeResponse {
fun googleCharge(member: Member, request: GoogleChargeRequest) {
val charge = Charge(request.chargeCan, 0)
charge.title = request.title
charge.member = member
@ -195,38 +195,25 @@ class ChargeService(
val payment = Payment(paymentGateway = request.paymentGateway)
payment.locale = request.currencyCode
payment.price = request.price
payment.receiptId = request.purchaseToken
payment.method = "구글(인 앱 결제)"
charge.payment = payment
chargeRepository.save(charge)
return ChargeResponse(chargeId = charge.id!!)
}
@Transactional
fun googleVerify(user: User, request: GoogleVerifyRequest) {
val charge = chargeRepository.findByIdOrNull(request.chargeId)
?: throw SodaException("결제정보에 오류가 있습니다.")
val member = memberRepository.findByEmail(user.username)
?: throw SodaException("로그인 정보를 확인해주세요.")
if (charge.payment!!.paymentGateway == PaymentGateway.GOOGLE_IAP) {
if (request.paymentGateway == PaymentGateway.GOOGLE_IAP) {
try {
androidPublisher.purchases().products()
.consume("kr.co.vividnext.sodalive", request.productId, request.purchaseToken)
.execute()
val response = androidPublisher.purchases().products()
.get("kr.co.vividnext.sodalive", request.productId, request.purchaseToken)
.execute() ?: throw SodaException("결제정보에 오류가 있습니다.")
if (
response.purchaseState == 0 &&
response.consumptionState == 1 &&
charge.payment?.status == PaymentStatus.REQUEST
payment.status == PaymentStatus.REQUEST
) {
charge.payment?.receiptId = response.purchaseToken
charge.payment?.method = "구글(인 앱 결제)"
charge.payment?.status = PaymentStatus.COMPLETE
member.charge(charge.chargeCan, charge.rewardCan, "aos")
payment.status = PaymentStatus.COMPLETE
member.charge(request.chargeCan, 0, "aos")
applicationEventPublisher.publishEvent(
ChargeSpringEvent(