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

A Deep Dive into Google Play Billing

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.

30966c6e1a52faf6b287b59a01195938?s=128

Kai Koenig

October 24, 2019
Tweet

Transcript

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

    WITH BILLINGCLIENT KAI KOENIG (@AGENTK)
  2. None
  3. None
  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. None
  11. THE JOURNEY

  12. GOOGLE PLAY IN-APP BILLING SERVICE

  13. 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
  14. GOOGLE PLAY BILLING LIBRARY https://www.flickr.com/photos/vpickering/6488181673/

  15. Client Server APP Google Play Google Play Server G
 P


    B
 L Backend application Google Play 
 Developer API
  16. 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
  17. 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
  18. SETUP GOOGLE PLAY BILLING

  19. SETUP - INTERNAL GOOGLE PLAY BILLING

  20. GOOGLE PLAY BILLING LIBRARY GOOGLE PLAY BILLING

  21. BILLINGCLIENT & FRIENDS GOOGLE PLAY BILLING

  22. READ THE COMMENTS GOOGLE PLAY BILLING

  23. NATVIE CALLBACKS GOOGLE PLAY BILLING

  24. MANAGEMENT AND HELPERS GOOGLE PLAY BILLING

  25. CONNECTION GOOGLE PLAY BILLING

  26. CONNECTION - INTERNAL GOOGLE PLAY BILLING

  27. GPBL AND IN-APP-BILLING SERVICE VERSIONS GOOGLE PLAY BILLING

  28. 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
  29. PRODUCTS AND SUBSCRIPTIONS https://www.flickr.com/photos/tschiae/8080742303/

  30. 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
  31. 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
  32. 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
  33. GETTING A LIST OF PRODUCTS PRODUCTS AND SUBSCRIPTIONS

  34. QUERYING PURCHASE HISTORY - INTERNAL PRODUCTS AND SUBSCRIPTIONS

  35. QUERYING PURCHASE HISTORY - INTERNAL PRODUCTS AND SUBSCRIPTIONS

  36. 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
  37. PURCHASE FLOW (II) PRODUCTS AND SUBSCRIPTIONS

  38. PURCHASE FLOW (OLDER STLYE) PRODUCTS AND SUBSCRIPTIONS

  39. PURCHASE FLOW (NEWER STYLE) PRODUCTS AND SUBSCRIPTIONS

  40. PURCHASE FLOW - INTERNAL PRODUCTS AND SUBSCRIPTIONS

  41. SAMPLE GOTCHAS PRODUCTS AND SUBSCRIPTIONS

  42. INTEGRATION CONCERNS

  43. 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
  44. 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
  45. 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
  46. ACKNOWLEDGING A PURCHASE ▸ Consumable: BillingClient.consumeAsync() ▸ Non-consumable: BillingClient.acknowledgePurchase() INTEGRATION

    CONCERNS
  47. REAL-TIME NOTIFICATIONS INTEGRATION CONCERNS GCP Pub/Sub Backend application Google Play

    
 Developer API
  48. TESTING AND 3RD PARTY LIBRARIES https://www.flickr.com/photos/tschiae/8080742303/ https://www.flickr.com/photos/37149125@N04/10170683255

  49. 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
  50. TESTING SUBSCRIPTIONS TESTING AND 3RD PARTY LIBRARIES

  51. BILLINGX TESTING AND 3RD PARTY LIBRARIES debugImplementation 'com.pixiteapps.billingx:billingx:0.8.2' releaseImplementation ‘com.android.billingclient:billing:1.2'

  52. BILLINGX - DEBUG TESTING AND 3RD PARTY LIBRARIES

  53. BILLINGX - RELEASE TESTING AND 3RD PARTY LIBRARIES

  54. 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
  55. FINAL THOUGHTS https://www.flickr.com/photos/chrispiascik/4054331891

  56. None
  57. OTHER THINGS GET IN TOUCH Kai Koenig Email: kai@ventego-creative.co.nz Work:

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

  58. 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

  59. 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