跳到主要內容

發表文章

目前顯示的是 3月, 2016的文章

整合 Google Play Billing Library 的流程

提醒,您必須擁有 Google Play 開發者帳戶並開啟 Google Payments 商家帳戶。 流程: 1. 於 build.gradle 中引入 Google Play Billing Library,程式內其他 Billing 相關的部分可暫時先不實作。 implementation 'com.android.billingclient:billing:*.*.*' 2. 將應用程式 Sign 好,上傳到 Developer Console 的任一測試階段。(需要一段時間生效) 3. 開始在 Developer Console 中建立應用程式內商品,並記得啟用。 4. 參考 範例 開始實作應用程式內購買。 5. 若有使用 ProGuard 也請記得加上 -keep class com.android.vending.billing.** 6. 於裝置上測試購買。 7. 購買成功後在 Developer Console 的訂單管理中可以看到該筆交易。(會標示為測試訂單) 8. 若有需要,可於訂單管理中進行退款(撤銷購買項目)的測試。 注意事項: 若您沒有自己的 Server 處理交易紀錄,而是靠 Play Store 來記錄的話。因為他有 Local Caching 的機制,有時不會立即反映交易狀態的改變。比如說您從訂單管理中取消了交易,但 App 透過 Google Play Billing Library 去查詢卻還是"已購買"的狀態。此時可以試著重啟裝置讓 Play Store 去同步交易狀態。 參考資料: https://developer.android.com/google/play/billing