close

上篇已提到怎麼從 Google Play Billing Library 接取商品列表

Android Kotlin APP 應用程式內購買 In-App Billing with Google Play Billing Library 實作教學、範例 example ( similar iOS In App Purchase ) ( 一 ) 』Willy's Fish教學筆記

但這時候會有一個問題

取回來是空的

截圖 2020-07-21 下午4.16.45

 

為什麼會這樣呢?

由於我們是在開發階段

所以 Google 並沒有加入我們設定的商品

一直到我們發佈任一版本 ( 包括正式到內測 )

才能憑簽證取到值,所以開發階段是無法取得的

 

那我們又該如何開發呢?

我們可以用以下四個 product ID

這是 Google 的保留 ID 專用來給開發者使用的

enum class SKU(val id: String) {
    Test001("test_001"),
    Test002("test_002"),
    AndroidTestPurchased("android.test.purchased"),
    AndroidTestCanceled("android.test.canceled"),
    AndroidTestRefunded("android.test.refunded"),
    AndroidTestItemUnavailable("android.test.item_unavailable")
}

 

取回來的值是固定的

目的是讓我們了解有哪些欄位

截圖 2020-07-22 上午10.21.00

 

然後就可以實際上買買看 purchased 商品

但買過之後,需要再取消才能買

可以下指令清除購買的 history

adb shell pm clear com.android.vending

 

或是用 code 來表達

https://stackoverflow.com/questions/13896666/in-app-billing-test-android-test-purchased-already-owned

 

最後我們若是要測整個到購買成功的流程

可以利用發佈內部測試來完成

請參考:

https://developer.android.com/google/play/billing/test#billing-testing-real

 

好的,那麼就趕緊來試試吧!

 

 

 

 

資料來源:

https://stackoverflow.com/questions/61154786/retrieve-in-app-purchases-with-android-billingclient-2-1-returns-empty-list

 

 

 

arrow
arrow

    顏澤偉 發表在 痞客邦 留言(0) 人氣()