I followed a tutorial online and I'm struggling to launch the billing flow on button click. When the button is clicked absolutely nothing happens. Everything in terms of subscription details is correct. I did upload it for testing and found that it still doesn't work.
subscribeAbstract = view.findViewById(R.id.abstract_subscribe_btn)
subscribeAbstract.setOnClickListener {
billingClient!!.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
val productList = listOf(
QueryProductDetailsParams.Product.newBuilder()
.setProductId("abstract_wallpapers")
.setProductType(BillingClient.ProductType.SUBS)
.build())
val params = QueryProductDetailsParams.newBuilder()
.setProductList(productList)
billingClient!!.queryProductDetailsAsync(params.build()) { billingResult, productDetailsList ->
for (productDetails in productDetailsList) {
val offerToken =
productDetails.subscriptionOfferDetails?.get(0)?.offerToken
val productDetailsParamsList =
listOf(
offerToken?.let {
BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetails)
.setOfferToken(it)
.build()
}
)
val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(productDetailsParamsList)
.build()
val billingResult = billingClient!!.launchBillingFlow(requireActivity(), billingFlowParams)
}
}
}