Подписка / покупка Android не найдена в коде, несмотря на то, что она определена в консоли Google Play

#android #kotlin #android-inapp-purchase #revenuecat

#Android #kotlin #android-inapp-покупка #revenuecat

Вопрос:

Я пытаюсь добавить подписку в свое приложение. Я создал подписку под названием «pro_subscription» в консоли Google Play и убедился, что она включена. Затем я создал новую альфа-сборку и выпустил ее для себя с учетной записью, которую я настроил для тестирования.

Мы добавили com.android.vending.BILLING разрешения и уже получили разрешение на доступ в Интернет.

Что бы мы ни пробовали, когда мы пытаемся получить подписку, чтобы приобрести ее, результатов не найдено.

Мы попытались напрямую получить данные с помощью API-интерфейсов Android, в которых mutableList?.isEmpty() true :

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

    var billingClient = BillingClient.newBuilder(activity as MainActivity)
        .setListener(purchasesUpdatedListener)
        .enablePendingPurchases()
        .build()

    billingClient.startConnection(object : BillingClientStateListener {
        override fun onBillingSetupFinished(billingResult: BillingResult) {
            if (billingResult.responseCode ==  BillingClient.BillingResponseCode.OK) {
                // The BillingClient is ready. You can query purchases here.
                val skuList = ArrayList<String>()
                skuList.add("subscription")
                skuList.add("pro_subscription")
                val params = SkuDetailsParams.newBuilder()
                params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP)
                billingClient.querySkuDetailsAsync(params.build(), SkuDetailsResponseListener() { billingResult: BillingResult, mutableList: MutableList<SkuDetails>? ->
                    if (mutableList?.isEmpty()!!) {
                        Log.d("OFFERS: ", "mutableList is empty")
                        return@SkuDetailsResponseListener
                    }
                })
            }
        }
        override fun onBillingServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    })
 

И мы также попытались использовать сторонний revenuecat, настроив предложение, а затем выбрав его, в котором offerings.all.isEmpty() true :

 Purchases.sharedInstance.getOfferingsWith(
    onError = { error ->
        /* Optional error handling */
        throw IllegalArgumentException()
    },
    onSuccess = { offerings ->
        if (offerings.current == null) {
            Log.d("OFFERS: ", "offerings.current is null")
        }
        if (offerings.all.isEmpty()) {
            Log.d("OFFERS: ", "offerings.all.size is 0")
        }
        // Display current offering with offerings.current
        Purchases.sharedInstance.purchasePackageWith(
            activity as MainActivity,
            offerings.current?.getPackage("pro")!!,
            onError = { error, userCancelled -> /* No purchase */
                if (userCancelled) {
                    val requestCancelledToast = Toast.makeText(
                        context,
                        R.string.purchase_request_cancelled_toast,
                        Toast.LENGTH_LONG
                    )
                    requestCancelledToast.show()
                } else {
                    throw IllegalArgumentException()
                }
            },
            onSuccess = { product, purchaserInfo ->
                if (purchaserInfo.entitlements["pro"]?.isActive == true) {
                    // Unlock that great "pro" content
                    try {
                        val adView =
                            container!!.findViewById<AdView>(R.id.adView)
                        (adView.parent as ViewGroup).removeView(
                            adView
                        )
                    } catch (e: Exception) {
                        val errorRemoveToast = Toast.makeText(
                            context,
                            R.string.error_remove_ad,
                            Toast.LENGTH_LONG
                        )
                        errorRemoveToast.show()
                    }
                }
            })
    })
 

В обоих случаях ошибка не печатается, не обнаруживается или иным образом не идентифицируется.

Кто-нибудь знает, почему мы не можем получать покупки на основе описанных выше шагов? Спасибо!

Ответ №1:

Вы добавили библиотеку выставления счетов в gradle приложения?

Это;

 dependencies {
    val billing_version = "4.0.0"

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