SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Billing Library 2.0 Overview
2019/05/17
Shibuya.apk #34
Namito Satoyama
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Community
Video Market Corporation
執⾏役員 VP of Engineering
/ProductManager
Twitter: @ns_twt
Writing
Namito Satoyama
Profile
⿊帯エンジニアが教えるプロの技術
Android開発の教科書
(共著︓SB Creative)
ステップバイステップで⼒がつく
Googleアシスタント
アプリ開発⼊⾨
(共著︓ソシム)
Speaker
Developers Summit 2017/2019
Interop Tokyo Conference 2018
Android Bazaar and Conference 2018a / 2017a / 2018s
GDG DevFest Tokyo 2016
7⽉にFlutterアプリ(iOS版)を出します
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Billing
Library 2.0
n Pending Transactions
n New Surface Interface(out-of-app subscriptions)
n Acknowledge all purchases
n Consistent Offers
n Faster purchase experience
n Revamped Developer Payload
n Improved error codes for easier debugging
n Predictable Releases & Support
主な変更点
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
https://www.youtube.com/watch?v=N4004Set4F8
ProfilePending Transactions
n クレジットカード決済のよ
うな即時取引完了となるフ
ローとは異なる
n いくつかのステップを踏む
遅延取引を実現
n 現⾦⽀払い(店舗⽀払)や
銀⾏振り込み
n ⽇本とメキシコから開始
(っぽい) https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfilePending Transactions
n 購⼊ボタンの代わりに⽀払
いコードが与えられる
n 購⼊が承認されると、サー
ビス側でアイテムの付与な
どを⾏う
https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfilePending Transactions
実装ステップ
1.アプリ起動時に
PendingTransaction
を有効化
var playStoreBillingClient =
BillingClient
.newBuilder(application.applicationContext)
.enablePendingPurchases()
.setListener(this).build()
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfilePending Transactions
実装ステップ
2.購⼊状態の変化を
PurchasesUpdatedListenerの
onPurchasesUpdatedで観測
override fun onPurchasesUpdated(
responseCode: Int,
purchasesList: List<Purchase>?) {
when (responseCode) {
BillingClient.BillingResponse.OK -> {
if (purchasesList == null) {
// 購⼊情報なし
} else {
// PurchasesStateを確認
}
}
・・・
}
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfilePending Transactions
実装ステップ
3.PurchaseResultから
Purchaseのインスタンスの
PurchaseStateを確認
purchasesResult.forEach { purchase ->
if (purchase.purchaseState
== Purchase.PurchaseState.PURCHASED) {
// 購⼊内容の確認 -> 購⼊商品の付与
} else if (purchase.purchaseState
== Purchase.PurchaseState.PENDING) {
// 遅延⽀払いが未完了
}
}
https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileNew purcase surfaces
n インストールとサブスクリ
プションを同時に⾏う
n つまりアプリ外でサブスク
リプションを⾏う
https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileAcknowledge all purchases
n すべての購⼊でアイテムが正しくユーザに
届けられたかをGoogle Playに知らせるた
め、購⼊承認処理が必要になった
n 購⼊が成功してから3⽇以内に知らせない
場合は購⼊が取り消しとなり、ユーザに返
⾦される
n Pending TransactionによるPENDING
状態の⽀払い状態のうちは3⽇間ルールは
適⽤されない
n 消費アイテムについては消費
(consumeAsync())時に⾃動的に
処理される(ので考慮不要)
TrivialDriveKotlin:BillingRepository.kt
private fun acknowledgeNonConsumablePurchasesAsync(
nonConsumables: List<Purchase>) {
nonConsumables.forEach { purchase ->
val params =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
playStoreBillingClient.acknowledgePurchase(params)
{ billingResult ->
when (billingResult.responseCode) {
BillingClient.BillingResponseCode.OK ->
{
disburseNonConsumableEntitlement(purchase)
}
else ->
Log.d(LOG_TAG,
"acknowledgeNonConsumablePurchasesAsync
response is ${billingResult.debugMessage}")
}
}
}
}
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileConsistent Offers
n 元の価格と割引前の価格を
得ることができ、ユーザに
割引を受けていることを提
⽰できる
n SkuDetailsに価格に関する
2つのメソッドが追加
• getOriginalPriceAmountMicros()
元の価格(フォーマット前)
• getOriginalPrice()
特定の通貨でフォーマットされた元の価格
https://www.youtube.com/watch?v=N4004Set4F8
現在テスト中
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileFaster purchase experience
n 購⼊画⾯のレンダリングを
最適化し、購⼊画⾯の表⽰
速度が向上
https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileRevamped Developer Payload
n Billing Libraryで
deprecatedだった
Developer Payloadが刷新
n アプリ外購⼊を含めたすべて
の購⼊に対応
n A/Bテスト識別⼦や購⼊検証
のための識別⼦を⼊れたりす
るのが想定される
https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileRevamped Developer Payload
n 今までのAIDLの購⼊フロー開
始時に指定する形とは異なる
n 消費/承認時に指定する
https://developer.android.com/google/play/billing/billing_library_overview
// 消費
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(/* token */)
.setDeveloperPayload(/* payload */)
.build()
client.consumeAsync(consumeParams, listener)
// 承認(Acknowledge)
val acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(/* token */)
.setDeveloperPayload(/* payload */)
.build()
client.acknowledgePurchase(
acknowledgePurchaseParams, listener)
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfileImproved error codes
for easier debugging
n エラーコードとエラーメッ
セージを詳細化
https://www.youtube.com/watch?v=N4004Set4F8
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
ProfilePredictable Release
& Support
n Major Releaseを毎年の
Google I/Oで公開
https://www.youtube.com/watch?v=N4004Set4F8
n Major Release毎に
2年間のサポート期間
n AIDL / BL1.x
deprecated
Predictable Release & Support
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
https://www.youtube.com/watch?v=N4004Set4F8
Kotlin版はもうすぐ
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
https://www.youtube.com/watch?v=N4004Set4F8
n 購⼊フローの中にPENDING状態を作ることで
アプリ外での課⾦⼿段を実現した
n 課⾦完了まで、より⾮同期的になるため、サービス内で課⾦完了
承認(Acknowledge)する仕組みが必須化
n 様々な課⾦⼿段/タイミングができることでのトラブル防⽌の
ために払い戻しの仕組みも⽤意
まとめ、というか所感
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
n Google Play Billing Library release notes
https://developer.android.com/google/play/billing/billing_library_releases_notes
n Use the Google Play Billing Library
https://developer.android.com/google/play/billing/billing_library_overview
n GitHub(android-play-billing)
https://github.com/googlesamples/android-play-billing
n Whatʻs New with Google Play Billing (Google I/Oʼ19) Youtube
https://www.youtube.com/watch?v=N4004Set4F8
参考資料
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
Thanks︕

Contenu connexe

Plus de Namito Satoyama

Plus de Namito Satoyama (13)

誰でもできるGoogleアシスタント開発
誰でもできるGoogleアシスタント開発誰でもできるGoogleアシスタント開発
誰でもできるGoogleアシスタント開発
 
Google Assistant Apps
Google Assistant AppsGoogle Assistant Apps
Google Assistant Apps
 
What's new with Android TV
What's new with Android TVWhat's new with Android TV
What's new with Android TV
 
App bundle
App bundleApp bundle
App bundle
 
SSMLでできること
SSMLでできることSSMLでできること
SSMLでできること
 
中国のスマホ市場
中国のスマホ市場中国のスマホ市場
中国のスマホ市場
 
Play Billing Library
Play Billing LibraryPlay Billing Library
Play Billing Library
 
はじめてのActions ongoogle
はじめてのActions ongoogleはじめてのActions ongoogle
はじめてのActions ongoogle
 
Actions on Google #Umeda.apk
Actions on Google #Umeda.apkActions on Google #Umeda.apk
Actions on Google #Umeda.apk
 
Firebase update from io'17
Firebase update from io'17Firebase update from io'17
Firebase update from io'17
 
App shortcuts
App shortcutsApp shortcuts
App shortcuts
 
Introduction of Eddystone
Introduction of EddystoneIntroduction of Eddystone
Introduction of Eddystone
 
Potatotips_7
Potatotips_7Potatotips_7
Potatotips_7
 

Billing Library 2.0 Overview

  • 1. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ Billing Library 2.0 Overview 2019/05/17 Shibuya.apk #34 Namito Satoyama
  • 2. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ Community Video Market Corporation 執⾏役員 VP of Engineering /ProductManager Twitter: @ns_twt Writing Namito Satoyama Profile ⿊帯エンジニアが教えるプロの技術 Android開発の教科書 (共著︓SB Creative) ステップバイステップで⼒がつく Googleアシスタント アプリ開発⼊⾨ (共著︓ソシム) Speaker Developers Summit 2017/2019 Interop Tokyo Conference 2018 Android Bazaar and Conference 2018a / 2017a / 2018s GDG DevFest Tokyo 2016
  • 3. 7⽉にFlutterアプリ(iOS版)を出します Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
  • 4. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ Billing Library 2.0
  • 5. n Pending Transactions n New Surface Interface(out-of-app subscriptions) n Acknowledge all purchases n Consistent Offers n Faster purchase experience n Revamped Developer Payload n Improved error codes for easier debugging n Predictable Releases & Support 主な変更点 Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
  • 6. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ https://www.youtube.com/watch?v=N4004Set4F8 ProfilePending Transactions n クレジットカード決済のよ うな即時取引完了となるフ ローとは異なる n いくつかのステップを踏む 遅延取引を実現 n 現⾦⽀払い(店舗⽀払)や 銀⾏振り込み n ⽇本とメキシコから開始 (っぽい) https://www.youtube.com/watch?v=N4004Set4F8
  • 7. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfilePending Transactions n 購⼊ボタンの代わりに⽀払 いコードが与えられる n 購⼊が承認されると、サー ビス側でアイテムの付与な どを⾏う https://www.youtube.com/watch?v=N4004Set4F8
  • 8. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfilePending Transactions 実装ステップ 1.アプリ起動時に PendingTransaction を有効化 var playStoreBillingClient = BillingClient .newBuilder(application.applicationContext) .enablePendingPurchases() .setListener(this).build()
  • 9. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfilePending Transactions 実装ステップ 2.購⼊状態の変化を PurchasesUpdatedListenerの onPurchasesUpdatedで観測 override fun onPurchasesUpdated( responseCode: Int, purchasesList: List<Purchase>?) { when (responseCode) { BillingClient.BillingResponse.OK -> { if (purchasesList == null) { // 購⼊情報なし } else { // PurchasesStateを確認 } } ・・・ }
  • 10. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfilePending Transactions 実装ステップ 3.PurchaseResultから Purchaseのインスタンスの PurchaseStateを確認 purchasesResult.forEach { purchase -> if (purchase.purchaseState == Purchase.PurchaseState.PURCHASED) { // 購⼊内容の確認 -> 購⼊商品の付与 } else if (purchase.purchaseState == Purchase.PurchaseState.PENDING) { // 遅延⽀払いが未完了 } }
  • 11. https://www.youtube.com/watch?v=N4004Set4F8 Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileNew purcase surfaces n インストールとサブスクリ プションを同時に⾏う n つまりアプリ外でサブスク リプションを⾏う https://www.youtube.com/watch?v=N4004Set4F8
  • 12. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileAcknowledge all purchases n すべての購⼊でアイテムが正しくユーザに 届けられたかをGoogle Playに知らせるた め、購⼊承認処理が必要になった n 購⼊が成功してから3⽇以内に知らせない 場合は購⼊が取り消しとなり、ユーザに返 ⾦される n Pending TransactionによるPENDING 状態の⽀払い状態のうちは3⽇間ルールは 適⽤されない n 消費アイテムについては消費 (consumeAsync())時に⾃動的に 処理される(ので考慮不要) TrivialDriveKotlin:BillingRepository.kt private fun acknowledgeNonConsumablePurchasesAsync( nonConsumables: List<Purchase>) { nonConsumables.forEach { purchase -> val params = AcknowledgePurchaseParams.newBuilder() .setPurchaseToken(purchase.purchaseToken) .build() playStoreBillingClient.acknowledgePurchase(params) { billingResult -> when (billingResult.responseCode) { BillingClient.BillingResponseCode.OK -> { disburseNonConsumableEntitlement(purchase) } else -> Log.d(LOG_TAG, "acknowledgeNonConsumablePurchasesAsync response is ${billingResult.debugMessage}") } } } }
  • 13. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileConsistent Offers n 元の価格と割引前の価格を 得ることができ、ユーザに 割引を受けていることを提 ⽰できる n SkuDetailsに価格に関する 2つのメソッドが追加 • getOriginalPriceAmountMicros() 元の価格(フォーマット前) • getOriginalPrice() 特定の通貨でフォーマットされた元の価格 https://www.youtube.com/watch?v=N4004Set4F8 現在テスト中
  • 14. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileFaster purchase experience n 購⼊画⾯のレンダリングを 最適化し、購⼊画⾯の表⽰ 速度が向上 https://www.youtube.com/watch?v=N4004Set4F8
  • 15. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileRevamped Developer Payload n Billing Libraryで deprecatedだった Developer Payloadが刷新 n アプリ外購⼊を含めたすべて の購⼊に対応 n A/Bテスト識別⼦や購⼊検証 のための識別⼦を⼊れたりす るのが想定される https://www.youtube.com/watch?v=N4004Set4F8
  • 16. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileRevamped Developer Payload n 今までのAIDLの購⼊フロー開 始時に指定する形とは異なる n 消費/承認時に指定する https://developer.android.com/google/play/billing/billing_library_overview // 消費 val consumeParams = ConsumeParams.newBuilder() .setPurchaseToken(/* token */) .setDeveloperPayload(/* payload */) .build() client.consumeAsync(consumeParams, listener) // 承認(Acknowledge) val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder() .setPurchaseToken(/* token */) .setDeveloperPayload(/* payload */) .build() client.acknowledgePurchase( acknowledgePurchaseParams, listener)
  • 17. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfileImproved error codes for easier debugging n エラーコードとエラーメッ セージを詳細化 https://www.youtube.com/watch?v=N4004Set4F8
  • 18. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ ProfilePredictable Release & Support n Major Releaseを毎年の Google I/Oで公開 https://www.youtube.com/watch?v=N4004Set4F8 n Major Release毎に 2年間のサポート期間 n AIDL / BL1.x deprecated
  • 19. Predictable Release & Support Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ https://www.youtube.com/watch?v=N4004Set4F8
  • 20. Kotlin版はもうすぐ Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ https://www.youtube.com/watch?v=N4004Set4F8
  • 21. n 購⼊フローの中にPENDING状態を作ることで アプリ外での課⾦⼿段を実現した n 課⾦完了まで、より⾮同期的になるため、サービス内で課⾦完了 承認(Acknowledge)する仕組みが必須化 n 様々な課⾦⼿段/タイミングができることでのトラブル防⽌の ために払い戻しの仕組みも⽤意 まとめ、というか所感 Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
  • 22. n Google Play Billing Library release notes https://developer.android.com/google/play/billing/billing_library_releases_notes n Use the Google Play Billing Library https://developer.android.com/google/play/billing/billing_library_overview n GitHub(android-play-billing) https://github.com/googlesamples/android-play-billing n Whatʻs New with Google Play Billing (Google I/Oʼ19) Youtube https://www.youtube.com/watch?v=N4004Set4F8 参考資料 Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌
  • 23. Copyright (C) 2019 Namito.Satoyama. All Rights Reserved. 無断引⽤・転載禁⽌ Thanks︕