Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Deep Dive into Google Play Billing

Kai Koenig
October 24, 2019

A Deep Dive into Google Play Billing

A talk about Google Play Billing 2.0 that I gave at Droidcon London 2019.

Google's APIs and libraries used for in-app-billing users from inside of your app, are confusing at best. The new star on the horizon is Google Play Billing Library, centered around a BillingClient class. GPBL is supposed to make your life much easier - but does it really?

In this session, you will discover the infrastructure around Google Play Billing Library and its usage. You will briefly explore the setup and basic implementation patterns inside of your app and then look behind the scenes and into the internals and implementation of the library itself. This approach will help significantly in gaining a better understanding of the library developer's intent.

A part of the session will be a close look into and a discussion of the provided samples and the issues they pose. Looking at them with a critical eye it'll be possible to understand what the good and what the bad parts of GPBL are and how to structure your implementation the best way.

Kai Koenig

October 24, 2019
Tweet

More Decks by Kai Koenig

Other Decks in Programming

Transcript

  1. TAKING YOUR USERS’ MONEY 
 A DEEP DIVE INTO IN-APP-BILLING

    WITH BILLINGCLIENT KAI KOENIG (@AGENTK)
  2. OVERVIEW ▸ Service that lets you sell digital content on

    Android: ▸ One-off purchases (consumable and non-consumable) ▸ Recurring subscriptions ▸ Can be accessed via IPC/AIDL or Google Play Billing library (GPBL) GOOGLE PLAY BILLING
  3. Client Server APP Google Play Google Play Server G
 P


    B
 L Backend application Google Play 
 Developer API
  4. FROM 30,000 FEET (I) ▸ In your app: Google Play

    Billing library ▸ Retrieve products, subscriptions, prices etc ▸ Check previous purchases ▸ Buy and consume products ▸ Acknowledge purchases ▸ Start subscriptions GOOGLE PLAY BILLING
  5. FROM 30,000 FEET (II) ▸ On the back end: Google

    Play Developer API ▸ Implement an integration between your server and the REST API ▸ Verify product purchases or subscriptions ▸ Notify back end when customers change or cancel subscriptions GOOGLE PLAY BILLING
  6. GOTCHAS ▸ The this-reference in setListener(this) in the setup process

    points to the PurchasesUpdatedListener interface. ▸ Not overriding onBillingServiceDisconnected can lead to weird errors. GOOGLE PLAY BILLING
  7. GENERAL ▸ All in-app purchase options are managed in the

    Google Play Console. ▸ An app can have multiple in-app purchase options. ▸ Watch out for international pricing or sets of apps with similar/identical prices. PRODUCTS AND SUBSCRIPTIONS
  8. PRODUCTS ▸ One-time product: ▸ Single, non-recurring charge to a

    payment method ▸ “Managed product” in Google Play Console ▸ Rewarded product: ▸ New since GPBL 1.2.1 (mid-March 2019) ▸ In-app product requiring user to watch a video ad PRODUCTS AND SUBSCRIPTIONS TYPE: INAPP
  9. SUBSCRIPTIONS ▸ In-app product with recurring billing: ▸ Weekly ▸

    Monthly (1, 3 and 6 months) ▸ Annually ▸ Free trial and introduction pricing ▸ Since GPBL 1.2 (October 2018) support for a pricing change flow PRODUCTS AND SUBSCRIPTIONS TYPE: SUBS
  10. PURCHASE FLOW (I) ▸ GBPL uses the Google Play app

    to drive the purchase flow. ▸ Depending on version of Android, Google Play app and Play Services, certain feature might not be available. ▸ BillingClient.isFeatureSupported() PRODUCTS AND SUBSCRIPTIONS
  11. VERIFICATION OF A PURCHASE ▸ Google Play Developer API: ▸

    Pass token and customer ID to your own backend ▸ Call REST API, make sure the token and purchase/subscription exist. ▸ Inside of the app: ▸ Check signature of original JSON payload in onPurchasesUpdated() INTEGRATION CONCERNS
  12. CONSUMING PURCHASES (I) ▸ A product can usually only be

    purchased once per Google Play account. ▸ Consume purchase with BillingClient.consumeAsync() ▸ Callback via onConsumeResponse() in ConsumeResponseListener INTEGRATION CONCERNS
  13. CONSUMING AND RESTORING PURCHASES (II) ▸ Sometimes products with a

    successful consumeAsync() callback sometimes still show up in BillingClient.queryPurchases() & BillingClient.queryPurchaseHistoryAsync() ▸ Use the server side API to check if a product really has been consumed.
 INTEGRATION CONCERNS
  14. TESTING ▸ Unpublished/local build with draft Google Play products ▸

    Unpublished/local build with static product SKUs to trigger responses ▸ Published build with actual Google Play products (closed testing track) ▸ Fiddling with user accounts ▸ Only physical device ▸ “Licensed” testers TESTING AND 3RD PARTY LIBRARIES
  15. REGISTER ▸ Register is an Android library for easier testing

    of Google Play's In-app Billing, not GPBL. ▸ Register comes with a companion app that acts as a mock billing server. TESTING AND 3RD PARTY LIBRARIES
  16. OTHER THINGS GET IN TOUCH Kai Koenig Email: [email protected] Work:

    http://www.ventego-creative.co.nz Twitter: @AgentK Slides: https://speakerdeck.com/therealagentk 

  17. OTHER THINGS RESOURCES (I) ▸ Google Play Billing library release

    notes:
 https://developer.android.com/google/play/billing/billing_library_releases_notes.html ▸ Google Play Billing library developer docs:
 https://developer.android.com/google/play/billing/billing_overview ▸ Google Play Developer API:
 https://developers.google.com/android-publisher/ ▸ Google Play Developer API for creating/editing in-app products:
 https://developers.google.com/android-publisher/api-ref/inappproducts ▸ Gradle Play Publisher:
 https://github.com/Triple-T/gradle-play-publisher

  18. OTHER THINGS RESOURCES (II) ▸ Various in-app-billing sample apps:
 https://github.com/googlesamples/android-play-billing

    ▸ Google Play Developer API for purchases and subscriptions:
 https://developers.google.com/android-publisher/api-ref/purchases/products
 https://developers.google.com/android-publisher/api-ref/purchases/subscriptions ▸ Google Play Billing Testing documentation:
 https://developer.android.com/google/play/billing/billing_testing.html ▸ NY Times Register: 
 https://github.com/NYTimes/Register ▸ BillingX:
 https://github.com/pixiteapps/billingx