<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kamo Spertsyan</title>
    <description>The latest articles on Forem by Kamo Spertsyan (@spertsyankm).</description>
    <link>https://forem.com/spertsyankm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F867166%2F0a35416b-4c56-422f-a87f-53aaa8faa798.png</url>
      <title>Forem: Kamo Spertsyan</title>
      <link>https://forem.com/spertsyankm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/spertsyankm"/>
    <language>en</language>
    <item>
      <title>The new subscription model and Google Play Billing Library 5.0 overview</title>
      <dc:creator>Kamo Spertsyan</dc:creator>
      <pubDate>Thu, 26 May 2022 07:43:25 +0000</pubDate>
      <link>https://forem.com/qonversion/the-new-subscription-model-and-google-play-billing-library-50-overview-2lo9</link>
      <guid>https://forem.com/qonversion/the-new-subscription-model-and-google-play-billing-library-50-overview-2lo9</guid>
      <description>&lt;p&gt;During the annual I/O conference, Google introduced its new major version of the Google Play Billing Library. Besides classic method deprecations and removals, there was also vast information about the new architecture of subscriptions, which aims to simplify the way you can create, manage and sell in-app purchases. In this article, I will explore the updates to Google Play Billing Library 5.0 and dig deeper into the most interesting ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  The new subscription model
&lt;/h2&gt;

&lt;p&gt;Google Play Billing System is the main tool that helps you to monetize your application with subscriptions. If you’re not familiar with this service yet, please read &lt;a href="https://qonversion.io/blog/a-complete-guide-to-google-play-in-app-purchases-and-subscriptions-implementation/" rel="noopener noreferrer"&gt;this article&lt;/a&gt;. With the latest version of its library, Google has changed the structure of how subscription products are defined, and this has led to changes in how they are sold in-app and managed on your backend. &lt;/p&gt;

&lt;p&gt;With Google Play Billing Library 5.0. Google has introduced new subscription architecture, which adds such entities as &lt;a href="https://support.google.com/googleplay/android-developer/answer/12154973" rel="noopener noreferrer"&gt;base plans and offers&lt;/a&gt;. Let’s take a look. &lt;/p&gt;

&lt;p&gt;Let’s say you have a premium subscription in your app and offer your clients weekly, monthly and annual subscriptions. Before these updates, you would have needed to create three different subscriptions - one per period. Then imagine that you wanted to offer a free trial to users who’ve left your app to persuade them to return. So, then you would also need to create one more annual subscription with a free trial.&lt;/p&gt;

&lt;p&gt;These are just two of the most common cases, causing the creation of lots of subscriptions with the previous subscription model - there could be many more examples. &lt;/p&gt;

&lt;p&gt;But from now on, you can handle all of these scenarios with just a single subscription. Google has divided a subscription model into three entities - subscription itself, base plans, and offers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffb4mot3yt1hjhgswx9au.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffb4mot3yt1hjhgswx9au.png" alt="The new subscription model"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The new subscription entity includes: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an identifier&lt;/li&gt;
&lt;li&gt;title&lt;/li&gt;
&lt;li&gt;description&lt;/li&gt;
&lt;li&gt;taxes information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rest of the information is set up via base plans and offers. &lt;/p&gt;

&lt;p&gt;A base plan contains: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;its identifier &lt;/li&gt;
&lt;li&gt;renewal type (auto-renewing or prepaid) &lt;/li&gt;
&lt;li&gt;duration &lt;/li&gt;
&lt;li&gt;grace period &lt;/li&gt;
&lt;li&gt;prices and availability for different regions&lt;/li&gt;
&lt;li&gt;and some less important settings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the whole list of details in &lt;a href="https://support.google.com/googleplay/android-developer/answer/12154973" rel="noopener noreferrer"&gt;the official documentation&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;An offer contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;its identifier&lt;/li&gt;
&lt;li&gt;eligibility criteria - an option determining which users can access this offer (first-time subscribers, those who upgrade from another subscription, or developer determined), &lt;/li&gt;
&lt;li&gt;phases including free trials and single or recurring payments (phases usage is shown in the screenshot below) &lt;/li&gt;
&lt;li&gt;and a price discount - either fixed amount or percentage or absolute discount depending on the base plan price &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frindbqcgis2tsltgb9w3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frindbqcgis2tsltgb9w3.png" alt="Subscription phases"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each subscription can contain one or more base plans, which in turn may contain several offers (see the scheme above). So, for the example above you can create one premium subscription with three base plans - one per period, and an offer with a free trial for the annual base plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Purchasing new subscriptions
&lt;/h2&gt;

&lt;p&gt;Speaking of code, in Google Play Billing Library 5.0, the &lt;code&gt;SkuDetails&lt;/code&gt; class is deprecated as well as every other entity or method containing &lt;code&gt;Sku&lt;/code&gt; in its name. Now you should consider using &lt;code&gt;ProductDetails&lt;/code&gt; for that purpose. Product details contain information about a subscription, including its base plans and offers.&lt;/p&gt;

&lt;p&gt;Before, you requested subscription details like those below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val params = SkuDetailsParams.newBuilder()
    .setType(BillingClient.SkuType.SUBS)
    .setSkusList(listOf("premium"))
    .build()

billingClient.querySkuDetailsAsync(params) { 
        billingResult, skuDetailsList -&amp;gt; // Process the result
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you should do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val productList = listOf(
    QueryProductDetailsParams.Product.newBuilder()
        .setProductType(BillingClient.SkuType.SUBS)
        .setProductId("premium")
        .build()
)

val params = QueryProductDetailsParams.newBuilder()
    .setProductList(productList)
    .build()

billingClient.queryProductDetailsAsync(params) {
    billingResult, productDetailsList -&amp;gt; // Process the result
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, for launching the purchase flow, you used the following constructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val billingFlowParams = BillingFlowParams.newBuilder()
    .setSkuDetails(skuDetails)
    .build()

val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whereas now they should look like those that follow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Note that `subscriptionOfferDetails` can be null if it is an in-app product, not a subscription.
val offerToken = productDetails.subscriptionOfferDetails?.get(selectedOfferIndex)?.offerToken ?: return

val productDetailsParamsList = listOf(
    BillingFlowParams.ProductDetailsParams.newBuilder()
        .setProductDetails(productDetails)
        .setOfferToken(offerToken)
        .build()
)

val billingFlowParams = BillingFlowParams.newBuilder()
    .setProductDetailsParamsList(productDetailsParamsList)

val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also look at the migration examples in &lt;a href="https://developer.android.com/google/play/billing/migrate-gpblv5" rel="noopener noreferrer"&gt;the Google official migration steps&lt;/a&gt;. Note, that there are a few typos in their examples which are fixed here.&lt;/p&gt;

&lt;p&gt;Let’s overview the changes. &lt;/p&gt;

&lt;p&gt;As I mentioned, you should now use &lt;code&gt;ProductDetails&lt;/code&gt; for querying subscription details and purchasing flow. In addition, you should provide an &lt;code&gt;offerToken&lt;/code&gt; to billing flow params as each &lt;code&gt;ProductDetails&lt;/code&gt; may contain several offers. Note, that the offer details array (&lt;code&gt;productDetails.subscriptionOfferDetails&lt;/code&gt;) always contains base plan details (if any base plan exists), so even if your subscription contains only a base plan without offers it will still have &lt;code&gt;offerToken&lt;/code&gt; for purchase.&lt;/p&gt;

&lt;p&gt;You could notice that the new purchase flow accepts multiple &lt;code&gt;ProductDetails&lt;/code&gt; instead of one &lt;code&gt;SkuDetails&lt;/code&gt; like in the previous version. But if you provide more than one &lt;code&gt;ProductDetails&lt;/code&gt;, the flow will end up with an error. &lt;a href="https://developer.android.com/google/play/billing/integrate#launch" rel="noopener noreferrer"&gt;The official integration guide&lt;/a&gt; gives the wrong example of using the &lt;code&gt;setProductDetails&lt;/code&gt; and &lt;code&gt;setOfferToken&lt;/code&gt; methods right on the &lt;code&gt;BillingFlowParams.Builder&lt;/code&gt; class, but there is only the &lt;code&gt;setProductDetailsParamsList&lt;/code&gt; &lt;a href="https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder#setProductDetailsParamsList(java.util.List%3Ccom.android.billingclient.api.BillingFlowParams.ProductDetailsParams%3E)" rel="noopener noreferrer"&gt;method available&lt;/a&gt; for those purposes. It seems as if Google decided to switch from single product details to multiple quite recently with a vision for the future when Billing will support multiple different subscription purchases at once.&lt;/p&gt;

&lt;p&gt;The rest flow - namely processing the purchase - remains the same as in the Google Play Billing Library 4.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Subscriptions backward compatibility
&lt;/h2&gt;

&lt;p&gt;Well, everything sounds good so far, but what if you don’t want to migrate right now? Google has taken care of it.&lt;/p&gt;

&lt;p&gt;Despite Google Play Console already working only with the new subscription model, all the old subscriptions are converted to the new format automatically, saving their backward compatibility. This means that you see your subscriptions in the new format on Google Console but can still work with them as you did before on your app. &lt;/p&gt;

&lt;p&gt;You will also notice that all the old subscriptions are made read-only after migration. Google warns you that editing will disable InAppProducts API support for that subscription.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu95s1fvvp29ywow8y5hp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu95s1fvvp29ywow8y5hp.png" alt="Read-only subscription editing warning"&gt;&lt;/a&gt;&lt;br&gt;
You might be using this API in your backend for fetching some product details, so be careful - after making the subscription editable you will receive errors (as shown below) from that API if you try to fetch converted subscription info. The same will happen to all new subscriptions created after May, 11th.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP code - 422
Non-existent in-app product: com.qonversion.sample\/ProductId{productId=article_test_trial}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if you use InAppProducts API, consider &lt;a href="https://developer.android.com/google/play/billing/compatibility#managing_subscription_status" rel="noopener noreferrer"&gt;upgrading it&lt;/a&gt; before creating new subscriptions or editing old ones.&lt;/p&gt;

&lt;p&gt;While surfing through the new subscriptions UI in Google Play Console, you will find “Backwards compatible” tags near base plans and offers of subscriptions. This means that if you purchase those subscriptions using deprecated &lt;code&gt;SkuDetails&lt;/code&gt; (as you do in Google Play Billing Library 4.0), you will buy exactly those compatible base plans/offers. If there is only a compatible base plan, without any compatible offer, then that base plan will be purchased. If there are both compatible base plan and offer available then if the offer is eligible to the current user, it will be purchased, else - base plan. You can choose another base plan/offer as backward compatible if you would like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1apgby5mnzt30fu9tr2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1apgby5mnzt30fu9tr2w.png" alt="Choosing backward compatible base plan or offer"&gt;&lt;/a&gt;&lt;br&gt;
Note - this Backwards compatibility relates to Google Play Billing Library but not to InAppProducts API. As mentioned, if you begin using new features, for example, multiple base plans or offers for one subscription or just convert it from read-only to editable, that subscription can still be Backwards compatible for an app, but not for API.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other updates
&lt;/h2&gt;

&lt;p&gt;There were several minor updates in the Google Play Billing Library 5.0 which are worth briefly mentioning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The method &lt;code&gt;queryPurchases&lt;/code&gt; deprecated in Google Play Billing Library 4.0 was removed - no more synchronized requests, only &lt;code&gt;queryPurchasesAsync&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;launchPriceChangeFlow&lt;/code&gt; has been deprecated - &lt;a href="https://developer.android.com/google/play/billing/subscriptions#price-change" rel="noopener noreferrer"&gt;the new recommended price change flow&lt;/a&gt; requires clients' confirmation via the Google Play subscriptions page, so you should use deep links for navigation there instead of calling the &lt;code&gt;BillingClient&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;Added the &lt;code&gt;setIsOfferPersonalized&lt;/code&gt; method to &lt;a href="https://developer.android.com/google/play/billing/integrate#personalized-price" rel="noopener noreferrer"&gt;indicate a personalized price&lt;/a&gt; for EU clients following the Consumer Rights Directive. This option adds a line to the bottom of the Google Billing purchase screen noting that a price is personalized.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The new subscriptions model and Qonversion
&lt;/h2&gt;

&lt;p&gt;While we are working on Google Play Billing Library 5.0 support, you can still use Qonversion SDK for your in-app purchases. We are now using Google Play Billing Library 4.0, which means we can manage only subscriptions with backward-compatible base plans and offers. You are still able to edit properties that were available in the previous subscriptions model like a price, grace period, trial duration, and so on as well as create new subscriptions. Just be sure that after you still have at least one backward compatible base plan and, if needed, a backward-compatible offer. And, we still require a whole subscription identifier for configuring products on our Product Center, not base plan or offer identifiers.&lt;/p&gt;

&lt;p&gt;If you have any questions, please let us know. We will be happy to assist you. &lt;/p&gt;

&lt;h2&gt;
  
  
  Useful links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/google/play/billing/release-notes#5-0" rel="noopener noreferrer"&gt;Google Play Billing Library 5.0 release notes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/google/play/billing/migrate-gpblv5" rel="noopener noreferrer"&gt;Google Play Billing Library 4 to 5 Migration Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/google/play/billing/compatibility" rel="noopener noreferrer"&gt;May 2022 subscription changes guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://support.google.com/googleplay/android-developer/answer/12124625" rel="noopener noreferrer"&gt;Recent changes to subscriptions in Play Console&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://support.google.com/googleplay/android-developer/answer/12154973?hl=en" rel="noopener noreferrer"&gt;Understanding subscriptions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>billing</category>
      <category>googleplay</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
