Android - In app subscription doesn't auto renew

576 Views Asked by At

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.

0

There are 0 best solutions below