I am implementing a subscription with Google billing in my android application. I have followed Google Play Billing official documentation. I have created subscriptions in Play Console and added relevant functionalities to my application.
The problem is, no subscriptions coming to the app from the Play console, always billingClient!!.queryProductDetailsAsync method returns an empty productDetailsList.
Can anyone please help me to identify the problem here?
here is my implementation,
In my app-level gradle file,
implementation "com.android.billingclient:billing-ktx:5.1.0"
In my subscription file
private var billingClient: BillingClient? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//Setup billing
billingSetup()
}
private fun billingSetup() {
billingClient = BillingClient.newBuilder(this)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build()
//Connect to Google Play
connectToGooglePlay()
}
private fun connectToGooglePlay() {
billingClient!!.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
Log.i("payment_flow", "OnBillingSetupFinish connected")
queryProduct()
} else {
Log.i("payment_flow", "OnBillingSetupFinish failed")
}
}
override fun onBillingServiceDisconnected() {
Log.i("payment_flow", "OnBillingSetupFinish connection lost")
//Re-connect to Google Play
connectToGooglePlay()
}
})
}
private fun queryProduct() {
val productList = ImmutableList.of(
Product.newBuilder()
.setProductId("monthly_plan")
.setProductType(BillingClient.ProductType.SUBS)
.build(),
Product.newBuilder()
.setProductId("yearly_plan")
.setProductType(BillingClient.ProductType.SUBS)
.build()
)
val queryProductDetailsParams = QueryProductDetailsParams.newBuilder()
.setProductList(productList).build()
billingClient!!.queryProductDetailsAsync(queryProductDetailsParams) {
billingResult: BillingResult, productDetailsList: List<ProductDetails> ->
Log.d("payment_flow", "onProductDetailsResponse: 1: $billingResult")
if (productDetailsList.isNotEmpty()) {
tmpProductDetailsList.addAll(productDetailsList)
Log.d("payment_flow", "onProductDetailsResponse: " + productDetailsList.size)
} else {
Log.i("payment_flow", "onProductDetailsResponse: No products")
}
}
}
Subscriptions on the Play Console

Logs when opening the subscriptions page in the app

Thanks in advance

Ok my issue was that my products were not showing up in my UI so I surrounded my looping and displaying of my products in a thread. Below is my code, hope it helps. Other than that, your code looks the same as mine. So key point,
runOnUiThread. My products are loading perfectly now and can purchase.