- Я пытаюсь протестировать покупки в приложении через Test with stati c response используя android .test.purchased as sku в моем приложении
- Ниже показано условие для асинхронного запроса skuDetails, которое всегда завершается ошибкой и переходит в другую часть. Я также добавил разрешения в манифесте относительно выставления счетов.
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && skuDetailsList.isNotEmpty()) {}
Вот мой код:
class TestActivity : AppCompatActivity(), PurchasesUpdatedListener {
val TAG = TestActivity::class.java.simpleName
private lateinit var billingClient: BillingClient
private val skuList = listOf("android.test.purchased")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_buy_code)
setupBillingClient()
}
private fun setupBillingClient() {
Log.d(TAG, "setupBillingClient: ")
billingClient = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this)
.build()
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
Log.d(TAG, "onBillingSetupFinished: ")
loadAllSKUs()
}
}
override fun onBillingServiceDisconnected() {
Log.d(TAG, "onBillingServiceDisconnected: ")
}
})
}
private fun loadAllSKUs() {
if (billingClient.isReady) {
val params = SkuDetailsParams
.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.INAPP)
.build()
billingClient.querySkuDetailsAsync(params) { billingResult, skuDetailsList ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && skuDetailsList.isNotEmpty()) {
Log.d(TAG, "Billing result:${billingResult.responseCode} ")
Log.d(TAG, "BillingResponseCode result:${BillingClient.BillingResponseCode.OK} ")
for (skuDetails in skuDetailsList) {
Log.d(TAG, "loadAllSKUs: $skuDetails")
if (skuDetails.sku == "android.test.purchased") {
buttonBuyProduct.setOnClickListener {
val billingFlowParams = BillingFlowParams
.newBuilder()
.setSkuDetails(skuDetails)
.build()
billingClient.launchBillingFlow(this, billingFlowParams)
}
}
}
}else{
Log.d(TAG, "loadAllSKUs: ${billingResult.responseCode} and ${BillingClient.BillingResponseCode.OK}")
}
}
} else {
Log.d(TAG, "Billing Client not ready ")
}
}