Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canceled Subscriptions is not working. #520

Open
pavelsust opened this issue Feb 18, 2022 · 5 comments
Open

Canceled Subscriptions is not working. #520

pavelsust opened this issue Feb 18, 2022 · 5 comments

Comments

@pavelsust
Copy link

After successful subscription I had unsubscribe from my google play. But still, now I am getting
purchaseData.autoRenewing true. So how I can solve this issue.

Is there any other way to know user unsubscribed from my service?

@faizan-ali-brainx
Copy link

@pavelsust Faced the same issue. The only solution left for me was to use the official Google API to check this. Let me know if you need any help with that.

@tripping-alien
Copy link

tripping-alien commented Mar 14, 2022

Hello @faizan-ali-brainx, could you explain your method please? I'm facing the same problem, it caches the result but it's unclear when does it refresh the cache.
Maybe it's possible to add a method to refresh the cache.

@tripping-alien
Copy link

After successful subscription I had unsubscribe from my google play. But still, now I am getting purchaseData.autoRenewing true. So how I can solve this issue.

Is there any other way to know user unsubscribed from my service?

You should be using isSubscribed("aaa");

@faizan-ali-brainx
Copy link

@tripping-alien Yes, the problem lies somewhere in cashing. When you subscribe for the first time. It always returns true from onward whether you cancel from the play store or your subscription expires. Yes, I was using the isSubscribed() method provided by the library. The pull request # 517 solved this issue I guess. Not sure though. Either you can wait for it to merge or solve it on your own. I didn't had time to wait this long so I opted to use the official Google API for this. You can use this or modify it according to your needs.

`class SubscriptionUtils() {

private val purchasesUpdatedListener =
    PurchasesUpdatedListener { billingResult, purchases ->

    }

fun startConnection(
    context: Context,
    isMonthlyOrYearly: (Boolean, Boolean) -> Unit
) {
    val billingClient = BillingClient.newBuilder(context)
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases()
        .build()


    billingClient.startConnection(object : BillingClientStateListener {
        override fun onBillingSetupFinished(billingResult: BillingResult) {
            if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
                billingClient.queryPurchasesAsync(
                    BillingClient.SkuType.SUBS
                ) { code, list ->
                    if (list.size > 0) {
                        if (list[0].skus[0] == "Your subscription Id here") {
                            if (list[0].isAutoRenewing) {
                                // Your logic here
                                isMonthlyOrYearly(true,false)
                            }
                        }
                    } else {
                        isMonthlyOrYearly(false, false)
                    }
                }
            }
        }

        override fun onBillingServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    })
}

}`

And then simply call like this where you want to check

SubscriptionUtils().startConnection(this) { isMonthly, isYearly -> }

Here isMonthly or isYearly indicates whether your subscription was canceled or expired. True means yes and false means no. Happy coding!!!

@lee4jun2
Copy link

When I used bp.loadOwnedPurchasesFromGoogleAsync, I got the correct autoRenewing value.

bp.loadOwnedPurchasesFromGoogleAsync(object: BillingProcessor.IPurchasesResponseListener{
            override fun onPurchasesSuccess() {
                if(bp.isPurchased(productId)){
                    // ~~
                }else if(bp.isSubscribed(productId)){
                     // ~~
                }else{
                    // ~~
                }
            }

            override fun onPurchasesError() {
            }

        })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants