I've followed a tutorial about implementing subscriptions with Google Billing, but I've left out some methods but it seems to work just fine.
This is one of the methods I left out:
private fun handelPurchase(purchase: Purchase){
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
val listener = ConsumeResponseListener { billingResult, s ->
if(purchase.purchaseState == BillingClient.BillingResponseCode.OK){
}
}
billingClient.consumeAsync(consumeParams, listener)
if(purchase.purchaseState == Purchase.PurchaseState.PURCHASED){
}
}
What is the purpose of it? Should I still implement it?
This is the last step that I'm using so far:
private fun ackPurchase(purchase: Purchase) {
if (!purchase.isAcknowledged) {
val params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.purchaseToken).build()
billingClient.acknowledgePurchase(params) { billingResult ->
if(billingResult.responseCode == BillingClient.BillingResponseCode.OK){
premiumActivate()
}
}
}else{
premiumActivate()
}
}
so do I need both or only one of those? Google docs are as always incomplete
The only other question that I've found that is similar is:
Android In-app billing, How to determine whether to call consumeAsync or acknowledgePurchase?
but it's not answered
Basically, there are the following types of products:
consumeAsync
is used only for the last category. This means acknowledging + marking it as "consumed", allowing you to purchase it again. Otherwise, you will encounter an ITEM_ALREADY_OWNED
error if you try to purchase it more than once.
In Google Play, there is no technical difference between consumable and non-consumable products (unlike, for example, App Store). So, it's up to the developer whether to consume or only acknowledge them.