versionCode 57, versionName 1.9.11

인 앱 결제 로직 수정
- 결제 완료 후 서버에서 데이터 처리 후 로컬에서 다시 소비처리를 하도록 수정
This commit is contained in:
klaus 2024-04-22 14:40:16 +09:00
parent a6ce994fd0
commit 2bd30aa346
2 changed files with 35 additions and 35 deletions

View File

@ -40,8 +40,8 @@ android {
applicationId "kr.co.vividnext.sodalive" applicationId "kr.co.vividnext.sodalive"
minSdk 23 minSdk 23
targetSdk 33 targetSdk 33
versionCode 49 versionCode 57
versionName "1.9.2" versionName "1.9.10"
} }
buildTypes { buildTypes {

View File

@ -56,29 +56,9 @@ class CanChargeIapFragment : BaseFragment<FragmentCanChargeIapBinding>(
setupBillingClient() setupBillingClient()
} }
override fun onStart() { override fun onDestroy() {
super.onStart()
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
viewModel.showToast("인 앱 결제 이용이 불가능 합니다. 다시 시도해 주세요.")
viewModel.setLoading(false)
}
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
queryAndConsumeUnconsumedPurchases()
} else {
viewModel.showToast("인 앱 결제 이용이 불가능 합니다. 다시 시도해 주세요.")
viewModel.setLoading(false)
}
}
})
}
override fun onStop() {
super.onStop()
billingClient.endConnection() billingClient.endConnection()
super.onDestroy()
} }
private fun bindData() { private fun bindData() {
@ -171,6 +151,22 @@ class CanChargeIapFragment : BaseFragment<FragmentCanChargeIapBinding>(
.build() .build()
loadingDialog.show(screenWidth) loadingDialog.show(screenWidth)
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
viewModel.showToast("인 앱 결제 이용이 불가능 합니다. 다시 시도해 주세요.")
viewModel.setLoading(false)
}
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
queryAndConsumeUnconsumedPurchases()
} else {
viewModel.showToast("인 앱 결제 이용이 불가능 합니다. 다시 시도해 주세요.")
viewModel.setLoading(false)
}
}
})
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@ -219,7 +215,9 @@ class CanChargeIapFragment : BaseFragment<FragmentCanChargeIapBinding>(
if (purchaseList.isNotEmpty()) { if (purchaseList.isNotEmpty()) {
for (purchase in purchaseList) { for (purchase in purchaseList) {
if (!purchase.isAcknowledged) { if (!purchase.isAcknowledged) {
consumePurchase(purchase) consumePurchase(purchase) {
queryAvailableCans()
}
} }
} }
} else { } else {
@ -229,14 +227,14 @@ class CanChargeIapFragment : BaseFragment<FragmentCanChargeIapBinding>(
} }
} }
private fun consumePurchase(purchase: Purchase) { private fun consumePurchase(purchase: Purchase, onSuccess: () -> Unit) {
val params = ConsumeParams.newBuilder() val params = ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken) .setPurchaseToken(purchase.purchaseToken)
.build() .build()
billingClient.consumeAsync(params) { billingResult, _ -> billingClient.consumeAsync(params) { billingResult, _ ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
queryAvailableCans() onSuccess()
} }
} }
} }
@ -251,6 +249,7 @@ class CanChargeIapFragment : BaseFragment<FragmentCanChargeIapBinding>(
selectedProductDetails = selectedProductDetails!!, selectedProductDetails = selectedProductDetails!!,
purchase = purchase purchase = purchase
) { chargeCan -> ) { chargeCan ->
consumePurchase(purchase) {
handler.post { handler.post {
viewModel.showToast("캔이 충전되었습니다") viewModel.showToast("캔이 충전되었습니다")
SharedPreferenceManager.can += chargeCan SharedPreferenceManager.can += chargeCan
@ -266,6 +265,7 @@ class CanChargeIapFragment : BaseFragment<FragmentCanChargeIapBinding>(
} }
} }
} }
}
private fun launchPurchaseFlow(productDetails: ProductDetails) { private fun launchPurchaseFlow(productDetails: ProductDetails) {
val billingFlowParams = BillingFlowParams.newBuilder() val billingFlowParams = BillingFlowParams.newBuilder()