From bfc78b0ef9e0c6fa008386647ac04063e4ee5146 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 5 Apr 2024 11:55:46 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=B0=EC=A0=9C=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EC=97=90=20=EA=B5=AC=EA=B8=80=EA=B2=B0=EC=A0=9C?= =?UTF-8?q?=EC=9D=98=20=EA=B2=BD=EC=9A=B0=20orderId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/can/charge/ChargeService.kt | 26 +++++++++---------- .../vividnext/sodalive/can/payment/Payment.kt | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt index d7ca03e..4f3b017 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/charge/ChargeService.kt @@ -231,19 +231,22 @@ class ChargeService( val response = androidPublisher.purchases().products() .get("kr.co.vividnext.sodalive", productId, purchaseToken) .execute() ?: throw SodaException("결제정보에 오류가 있습니다.") + charge.payment!!.orderId = response.orderId if ( response.purchaseState == 0 && charge.payment!!.status == PaymentStatus.REQUEST ) { - consumeWithRetry(productId, purchaseToken, charge, member) - - applicationEventPublisher.publishEvent( - ChargeSpringEvent( - chargeId = charge.id!!, - memberId = member.id!! + if (consumeWithRetry(productId, purchaseToken, charge, member)) { + applicationEventPublisher.publishEvent( + ChargeSpringEvent( + chargeId = charge.id!!, + memberId = member.id!! + ) ) - ) + } else { + throw SodaException("구매를 하지 못했습니다.\n고객센터로 문의해 주세요") + } } else { throw SodaException("결제정보에 오류가 있습니다.") } @@ -252,7 +255,7 @@ class ChargeService( } } - private fun consumeWithRetry(productId: String, purchaseToken: String, charge: Charge, member: Member) { + private fun consumeWithRetry(productId: String, purchaseToken: String, charge: Charge, member: Member): Boolean { var attempt = 0 var delay = 2000L val retries = 3 @@ -269,7 +272,7 @@ class ChargeService( charge.payment!!.status = PaymentStatus.COMPLETE member.charge(charge.chargeCan, 0, "aos") - return + return true } catch (e: Exception) { lastError = e attempt += 1 @@ -278,10 +281,7 @@ class ChargeService( } } lastError?.printStackTrace() - - if (attempt == retries) { - throw SodaException("구매를 하지 못했습니다.\n고객센터로 문의해 주세요") - } + return false } private fun requestRealServerVerify(verifyRequest: AppleVerifyRequest): Boolean { diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/payment/Payment.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/payment/Payment.kt index 7438bbd..2c0c527 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/payment/Payment.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/payment/Payment.kt @@ -27,6 +27,7 @@ data class Payment( var price: Double = 0.toDouble() var locale: String? = null + var orderId: String? = null } enum class PaymentStatus {