In researching answers for my question here I found (after several days of very frustrating work) references to the kotlin billing library "billing.ktx" which a couple of Developer pages claim
contains Kotlin extensions and coroutines support that enable you to write idiomatic Kotlin when using Google Play's billing system
but gives neither details nor links for more information. The Play billing examples, "Classy Taxi" and "TrivialDrive" have been rewritten to use Kotlin but hardly "idiomatic Kotlin", and certainly not using coroutines, nor do they use this library. They are now two years old and showing their age in this fast moving arena.
My question is specifically what does this library offer in terms of idiomatic Kotlin or even coroutine support? I am making some headway with some billing client functions (as can be seen in the referenced question) before using this library, but I can't see what difference using it makes. To be even more specific, "launchBillingFlow" looks impossible to convert, but is it?
Just links to somewhere to find information would be enough. Why is it so hard to find more than class definitions for the billing client?
I can find no documentation. Everything in this answer comes from looking through the billing-ktx
aar that appears when I add a dependency on this library to my project.
This library looks pretty minimal. It provides three new "result" classes as well as four extension funtions on BillingClient
to replace callback-based code with suspend fun
s.
package com.android.billingclient.api
public suspend fun BillingClient.acknowledgePurchase(params: AcknowledgePurchaseParams): BillingResult { /* compiled code */ }
public suspend fun BillingClient.consumePurchase(params: ConsumeParams): ConsumeResult { /* compiled code */ }
public suspend fun BillingClient.queryPurchaseHistory(skuType: String): PurchaseHistoryResult { /* compiled code */ }
public suspend fun BillingClient.querySkuDetails(params: SkuDetailsParams): SkuDetailsResult { /* compiled code */ }
With these in place, inside a coroutine you can write:
val result = billingClient.querySkuDetails(params.build())
// you can now access result.billingResult or result.skuDetailsList
Rather than something like what appears in the documentation:
billingClient.querySkuDetailsAsync(params.build()) { billingResult, skuDetailsList ->
// Process the result.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With