From 5da5fb2127060c4c794d02b13d30f5b87c0051f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9luchu?= Date: Sat, 26 Aug 2023 03:11:42 +0200 Subject: [PATCH] Modify conditions of billings --- .../pay/playstore/SubscriptionsHelper.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/jchucomponents-pay/src/main/kotlin/com/jeluchu/pay/playstore/SubscriptionsHelper.kt b/jchucomponents-pay/src/main/kotlin/com/jeluchu/pay/playstore/SubscriptionsHelper.kt index f801eca1..fb40a659 100644 --- a/jchucomponents-pay/src/main/kotlin/com/jeluchu/pay/playstore/SubscriptionsHelper.kt +++ b/jchucomponents-pay/src/main/kotlin/com/jeluchu/pay/playstore/SubscriptionsHelper.kt @@ -201,12 +201,21 @@ data class SubscriptionsHelper(private val context: Context, val subscripttions: val acknowledgePurchaseParams = AcknowledgePurchaseParams .newBuilder() .setPurchaseToken(purchase.purchaseToken) - billingClient.acknowledgePurchase(acknowledgePurchaseParams.build()) { p0 -> - if (p0.responseCode == BillingClient.BillingResponseCode.OK) { - if (purchase.products.contains(productId)) { - onSubscriptionSuccess(purchase) - } else onSubscriptionFailure(p0.debugMessage) - } else onSubscriptionFailure(p0.debugMessage) + billingClient.acknowledgePurchase( + acknowledgePurchaseParams.build() + ) { billingResult -> + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && + purchase.purchaseState == Purchase.PurchaseState.PURCHASED + ) { + if (purchase.products.contains(productId)) onSubscriptionSuccess(purchase) + else onSubscriptionFailure(billingResult.debugMessage) + } + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && + purchase.purchaseState == Purchase.PurchaseState.PENDING + ) onSubscriptionFailure(billingResult.debugMessage) + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && + purchase.purchaseState == Purchase.PurchaseState.UNSPECIFIED_STATE + ) onSubscriptionFailure(billingResult.debugMessage) } } }