Google Play Billing 4.0 Review

Hello everyone, my name is Masha, I am SDK Engineer at qonversion.io

Qonversion is a subscription platform for mobile applications. Our SDKs allow you to embed in-app purchases; handle push notifications triggered by in-app purchases events; analyze the business of subscriptions in their own dashboards and send data to marketing platforms (such as Appsflyer, Amplitude and others). Qonversion also allows you to conduct A / B testing to determine the optimal product offerings: prices, subscription and trial duration, etc.

Today we will talk about the library Google Play Billing Library 4.0.0which should open up new avenues for in-app purchases by the end of this year.

According to Google’s announcementThe fourth version of Billing Library will optimize in-app purchases:

  • It will be possible to purchase several consumable in-app products at the same time. At the moment, you can only buy 1 unit of the product at a time.

  • The user will be able to determine the composition of the subscription himself, that is, purchase several products as part of one subscription.

You can read more about the types of products for in-app sale. here

Since not everyone has switched to Billing Library v4 yet, I would like to tell you what you should pay attention to when migrating to the new version.

Major changes in the 4th version of Google Play Billing Library

1. Background & Main: background and main threads

Now callbacks of methods are called on the background thread (in the previous version they were called from the main thread). To verify this, for example, you can log the name of the current stream in the method onBillingSetupFinished interface BillingClientStateListener:

if (Looper.getMainLooper().thread == Thread.currentThread()) {
   Log.d("TestThread", "Main thread is running.")
} else {
   Log.d("TestThread", "${Thread.currentThread().name} thread is running.")
}

In the logs, you can see the following result for different versions of the library:

If you need to change the user interface directly from the callback, it is important to remember that you cannot interact with the UI without switching back to the main thread.

2.queryPurchasesAsync () to retrieve active purchases of a user
Method queryPurchases () is no longer relevant. Now, to get information about active subscriptions and non-consumable purchases (aka non-consumable) in the application, you need to use the method queryPurchasesAsync ():

private fun queryPurchasesAsync() {
   // Fetch active subscriptions and non-consumable in-app purchases
   billingClient.queryPurchasesAsync(BillingClient.SkuType.SUBS, this)
   billingClient.queryPurchasesAsync(BillingClient.SkuType.INAPP, this)
}

To get the answer, you need to implement the interface PurchasesResponseListener and override its method onQueryPurchasesResponse:

/**
* Callback that will be called when queryPurchasesAsync is called
*/
override fun onQueryPurchasesResponse(
   billingResult: BillingResult,
   purchases: MutableList<Purchase>
) {
   // process purchases
}

3. New way for downgrade / upgrade subscriptions

Formerly for subscription updates it was necessary to provide a value SkuDetails, sku (aka identifier) ​​and old subscription token, as well as optional ProrationMode:

private fun updatePurchase(skuDetails: SkuDetails) {
   val params = BillingFlowParams.newBuilder()
       .setSkuDetails(skuDetails)
       .setOldSku("oldSku", "oldPurchaseToken")
       .setReplaceSkusProrationMode(BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE)
       .build()
 
   billingClient.launchBillingFlow(this, params)
}

Now, to downgrade or upgrade a subscription, you need to call BillingFlowParams.Builder.setSubscriptionUpdateParams () and pass the object SubscriptionUpdateParams as a parameter. Method setOldSku() was removed.

private fun updatePurchase(skuDetails: SkuDetails) {
   val updateParams = BillingFlowParams.SubscriptionUpdateParams.newBuilder()
       .setOldSkuPurchaseToken("oldPurchaseToken")
       .setReplaceSkusProrationMode(BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE)
       .build()
 
   val billingFlowParams = BillingFlowParams.newBuilder()
       .setSkuDetails(skuDetails)
       .setSubscriptionUpdateParams(updateParams)
       .build()
 
   billingClient.launchBillingFlow(this, billingFlowParams)
}

4. Multi-quantity purchases (not yet available, awaiting release)

Google has announced plans to optimize in-app purchases: users will be able to select the desired number of products directly from the shopping cart. From the Google Play Console, it will be possible to configure which product is available for such an option.

This greatly simplifies the buying and selling processes. Users will now be able to buy multiple consumable units (they are consumable in-app products, for example, coins, mana) in one click, and not buy them many times with different transactions.

New methods can be used to get the amount of purchased product Purchase.getQuantity () and PurchaseHistoryRecord.getQuantity ()

5.Multi-line subscriptions (not yet available, awaiting release)

In addition to the previous feature, Google will allow you to sell multiple products under a single subscription. Users will be able to manage the composition of such a subscription at any time (add, cancel, and replace products when subscribing or while using it).

For example, a user can buy a course on learning Java, Kotlin, and then add Swift to this set.

To get the product IDs of a purchase, use the methods Purchase.getSkus () and PurchaseHistoryRecord.getSkus () (method getSku() no longer available).

What is the bottom line?

Of course, Google Play Billing Library 4.0.0 is great for optimizing in-app purchases. In terms of technical details, innovations on the mobile side may not seem fundamental. But you need to take into account the changes on the server. For example, if you are collecting purchase analytics, a new field will appear in the purchase request quantity; an array can now be passed to the field for the product identifier ids… It also looks like the number of requests to your server, albeit by a small fraction, will decrease due to one-time purchases. You can read about other changes in the library in release notes.

Who has already switched to Google billing 4.0.0? What difficulties have you noticed in the transition or use? It will be interesting to discuss.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *