'Billing service unavailable on device

I'm trying to connect to Google Play, to add a paid subscription, but I get this message in the callback : Billing service unavailable on device. here is my code :

    private fun createClient(): BillingClient {
    val purchasesUpdatedListener =
        PurchasesUpdatedListener { billingResult, purchases ->
            // To be implemented in a later section.
        }

    return BillingClient.newBuilder(requireContext())
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases()
        .build()
}


    suspend fun querySkuDetails() {
    val pay = createClient()
    pay.startConnection(object : BillingClientStateListener {
        override fun onBillingSetupFinished(billingResult: BillingResult) {
            Log.d("showMsg","${billingResult.responseCode}")
            if (billingResult.responseCode ==  BillingClient.BillingResponseCode.OK) {

            }
        }
        override fun onBillingServiceDisconnected() {
        }
    })
}

I added this dependency to the project

    implementation "com.android.billingclient:billing-ktx:$billing_version"

And created a paid subscription in google play console.

Please tell me how can i fix this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source