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) {
// 遅延⽀払いが未完了
}
}
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
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︕