0

I am using the billingclient in version 3.0.1 to manage some subscriptions (monthly, bi-annually and annually).

com.android.billingclient:billing-ktx:3.0.1

So far it's working great, user can subscribe and have the benefits from it directly in the app.

But the issue is on the auto-renew. I would except to see some auto-renew every month on the Play Store, I don't see any but users are still premium.

On the tests in debug mode, the auto renew is working nicely (I could test with the version in Play Store and could see on Firebase my auto-renews) but it is working only for test account and not for real users. What am I missing?

I don't use any server, everything is in local and I acknowledge the purchase when user subscribe.

 if (!purchase.isAcknowledged) {
            val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
                .setPurchaseToken(purchase.purchaseToken)
                .build()

            mBillingClient?.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener)
 }

Thank you for your help :)

EDIT: Here the queryPurchases call:

 fun queryPurchases() {
        val queryToExecute = Runnable {
            val time = System.currentTimeMillis()
            val purchases = arrayListOf<Purchase>()
            mBillingClient?.queryPurchases(BillingClient.SkuType.INAPP)?.also { purchasesResult ->
                Timber.d("Querying purchases elapsed time: ${(System.currentTimeMillis() - time)} ms")
                if (purchasesResult.responseCode == BillingClient.BillingResponseCode.OK) {
                    if (!purchasesResult.purchasesList.isNullOrEmpty())
                        purchases.addAll(purchasesResult.purchasesList!!)
                }
                // If there are subscriptions supported, we add subscription rows as well
                when {
                    areSubscriptionsSupported() -> {
                        mBillingClient?.queryPurchases(BillingClient.SkuType.SUBS)?.also { subscriptionResult ->
                            Timber.d("Querying purchases and subscriptions elapsed time: ${(System.currentTimeMillis() - time)} ms")
                            Timber.d("Querying subscriptions result code: ${subscriptionResult.responseCode} res: ${subscriptionResult.purchasesList.orEmpty().size}")
                            if (subscriptionResult.responseCode == BillingClient.BillingResponseCode.OK) {
                                if (!subscriptionResult.purchasesList.isNullOrEmpty())
                                    purchases.addAll(subscriptionResult.purchasesList!!)
                            }
                            else {
                                handleError("queryPurchases() ${BillingClient.SkuType.SUBS}", subscriptionResult.responseCode)
                                Timber.d("Got an error response trying to query subscription purchases")
                                if (subscriptionResult.responseCode == BillingClient.BillingResponseCode.SERVICE_DISCONNECTED) {
                                    startServiceConnection {
                                        // Notifying the listener that billing client is ready
                                        billingUpdatesListener?.onBillingClientSetupFinished()
                                    }
                                }
                            }
                        }
                    }
                    purchasesResult.responseCode == BillingClient.BillingResponseCode.OK -> { }
                    else -> {
                        handleError("queryPurchases() ${BillingClient.SkuType.INAPP}", purchasesResult.responseCode)
                        Timber.d("queryPurchases() got an error response code: ${purchasesResult.billingResult.debugMessage}")
                        if (purchasesResult.responseCode == BillingClient.BillingResponseCode.SERVICE_DISCONNECTED) {
                            startServiceConnection {
                                // Notifying the listener that billing client is ready
                                billingUpdatesListener?.onBillingClientSetupFinished()
                            }
                        }
                    }
                }
                purchasesResult.purchasesList?.also {
                    it.clear()
                    it.addAll(purchases)
                }
                onQueryPurchasesFinished(purchasesResult)
            }
        }
        executeServiceRequest(queryToExecute)
    }

Today I added in the error cases the checks if the service is disconnected to retry the connection as in Firebase I got some logs related to it.

Joadar
  • 1
  • 1
  • 4
  • I think the auto renew is done by Google's billing on their server side, if the item is of subscription type.Show us snippet that calls queryPurchases code if you can – Don Ha Dec 01 '20 at 13:47
  • Thanks @DonHa I just edited the main post with the queryPurchases call. I now it is from Google side there is the auto renew but I don't understand why it is working with a test account and not without, with a real user :/ – Joadar Dec 01 '20 at 14:17
  • I see you query both INAPP and SUBS, INAPP purchases are not auto renewed. – Don Ha Dec 01 '20 at 14:28
  • Yes but I have only SUBS that it is used. I should remove INAPP as I don't use it yet (wanted to use it but never implement something that fit with it). Could it be the issue? – Joadar Dec 01 '20 at 14:39
  • That shouldn't be an issue. Maybe you need to log in into Developer console, look at the subscription report to make sure they are all active. – Don Ha Dec 01 '20 at 15:08
  • Okay thanks. Maybe it comes from this. I got some subscriptions and also some cancel subscriptions. I will wait more months to be sure :) Thanks a lot for your help! – Joadar Dec 01 '20 at 15:25

0 Answers0