I'm implementing Android in app purchases, with BillingClient api.
I successfully set up billing client, like this:
billingClient = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this).build()
And I implement the code I want to make the in app purchase, which in my case is a subscription.
My issue is as follows, I need to check (periodicly) if the user still has an active subscription, or if they canceled it. From what I read, I can do a call of the method, queryPurchases(PRODUCT_ID). I am doing this as follows:
override fun onBillingSetupFinished(billingResult: BillingResult?) {
if (billingResult != null) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK){
// The BillingClient is ready. You can query purchases here.
Log.d(TAG_PURCHASES_ACTIVITY, "BillingClient ready and connected")
billingClient.queryPurchases(MONTHLY_AGENT_SUBSCRIPTION_PRODUCT_ID)
}
else{
Log.d(TAG_PURCHASES_ACTIVITY, "BillingClient ERROR: ${billingResult.responseCode}")
}
}
}
However, I get this message in the console:
W/BillingClient: getPurchase() failed. Response code: 3
Now after researching, many have said that this is coming from old phones, with older versions of google play services. But I am using new phone (Pixel 3a), which is up to date. This phone also has the google account registered in the google play console for testing.
Why I am getting this message?
Also, is this really the correct way to check if the subscription is still active?
I've tried for ages to find this solution, thanks for any help!
I was making a mistake, passing the product id as a parameter to the query request. This is what I needed to do:
var list = billingClient.queryPurchases(SkuType.SUBS)