HelloCW
HelloCW

Reputation: 2235

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

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)
        }
    }
}

Upvotes: 7

Views: 2554

Answers (2)

Ranjan
Ranjan

Reputation: 1356

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.

Upvotes: 0

from56
from56

Reputation: 4127

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.

Upvotes: 2

Related Questions