Can I purchase multiple items at one time through Google Play in Android App?
Asked Answered
P

2

7

In my mind, I can only puchase one item at one time in Google App.

The Code A is from the project play-billing-samples, you can see here.

purchases: MutableList<Purchase> maybe exist multiple items, it seems that I can purchase these items simultaneously through Google Play, right?

Code A

override fun onPurchasesUpdated(
        billingResult: BillingResult,
        purchases: MutableList<Purchase>?
) {
    when (billingResult.responseCode) {
        BillingClient.BillingResponseCode.OK -> {
            // will handle server verification, consumables, and updating the local cache
            purchases?.apply { processPurchases(this.toSet()) }
        }
        BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> {
            // item already owned? call queryPurchasesAsync to verify and process all such items
            Log.d(LOG_TAG, billingResult.debugMessage)
            queryPurchasesAsync()
        }
        BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
            connectToPlayBillingService()
        }
        else -> {
            Log.i(LOG_TAG, billingResult.debugMessage)
        }
    }
}
Prattle answered 20/5, 2020 at 7:24 Comment(1)
This stackoverflow post can be helpful.Brooking
T
2

An user can own the same in-app item only once, but he can own different items at the same time.

Other solution is to consider the item as consumable:

if billingClient.consumeAsync() is called at the end of the purchase process then he can buy the same item again, but you have to keep track of how many times he bought it by your own means, probably through a backend server.

Topee answered 5/6, 2020 at 15:4 Comment(4)
Thanks! I mean an user can purchase different items simultaneously via Google in-app, right?Prattle
No, the different items must be bought one by one, there is no method to buy several simultaneouslyTopee
Thanks! Why does Google Play API design it as purchases: MutableList<Purchase> ? you know purchases?.apply { processPurchases(this.toSet()) } seems to purchase different items simultaneously.Prattle
Just because a purchase list exists doesn't mean you can buy multiple items at once. billingClient.launchBillingFlow() only allows one item to be purchased.Topee
B
0

Yes, there is no method to buy all them at once. As you have to consume it before using again or using another one. But what you can do is create a single combined in app product which is a sum of all of your packages.

Suppose you have item A with $2,B with $3, C with $5. Then you can crate a item with sum of (A+B+C) i.e., $10 and provide all the benefits of Item A,B and C to the user.

Balkh answered 6/6, 2020 at 13:56 Comment(1)
Thanks! Why does Google Play API design it as purchases: MutableList<Purchase> ? you know purchases?.apply { processPurchases(this.toSet()) } seems to purchase different items simultaneously.Prattle

© 2022 - 2024 — McMap. All rights reserved.