scope.launch(Dispatchers.IO){valresult=KotBilling.queryProducts(listOf(/* products to query */))when(result){isKBError->{valconnectionState=result.connectionStatevalerrorType=result.errorType// errorType is a sealed class which will tell you the reason and type for the error (connection error, purchase error, acknowledge error, ...)// connectionState will tell you what the connection state was}isKBProductDetailsList->{if(result.details.isEmpty()){// most probably only happens if you try this inside a debug app or an app that's not released on the playstore yet}else{// in all other cases you will get a list with products and all their details (same size as the queried products) which you can handle hereresult.details.forEach{valproduct=it.productvaldetails=it.details// ... }}}}}
scope.launch(Dispatchers.IO){valresult=KotBilling.queryPurchases(ProductType.InApp)// or ProductType.Subscriptionwhen(result){isKBError->{valconnectionState=result.connectionStatevalerrorType=result.errorType// errorType is a sealed class which will tell you the reason and type for the error (connection error, purchase error, acknowledge error, ...)// connectionState will tell you what the connection state was}isKBPurchaseQuery->{if(result.details.isEmpty()){// user did not purchase anything yet}else{valproductType=result.productTypevaldetails=result.details// details holds a list of all purchase details which you can handle here}}}}
scope.launch(Dispatchers.IO){valresult=KotBilling.purchase(context,/* product */,/* optional offerToken */)when(result){isKBError->{valconnectionState=result.connectionStatevalerrorType=result.errorType// errorType is a sealed class which will tell you the reason and type for the error (connection error, purchase error, acknowledge error, ...)// connectionState will tell you what the connection state was}isKBPurchase->{// successvalpurchase=result.purchase// purchase holds the purchase details which you can handle here}}}