我的应用有应用内订阅购买,但是我对整个实施过程感到非常困惑。
当应用打开时,我正在致电onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases)
,以检查用户是否有任何有效的购买。如果购买清单为空,则该应用会假定用户未购买任何东西。
稍后用户决定购买一些应用调用时:
mBillingClient = BillingClient.newBuilder(view.getContext()).setListener(new PurchasesUpdatedListener()
再次进行一次购买onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases)
后,将再次调用该应用程序,但是一旦我重新打开该应用程序后,它便无法正常工作,就像用户未购买任何东西一样,它都恢复了正常(免费版本)。
此外,用户购买的数据也没有存储在云(firebase实时数据库)中。已经有三位用户进行了购买,并且处于三天试用期。
答案 0 :(得分:0)
您看过the sample on GitHub吗?当用户打开您的应用程序时,您应该调用queryPurchases
。这是一个示例:
fun queryPurchasesAsync() {
Log.d(LOG_TAG, "queryPurchasesAsync called")
val purchasesResult = HashSet<Purchase>()
var result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.INAPP)
Log.d(LOG_TAG, "queryPurchasesAsync INAPP results: ${result?.purchasesList?.size}")
result?.purchasesList?.apply { purchasesResult.addAll(this) }
if (isSubscriptionSupported()) {
result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.SUBS)
result?.purchasesList?.apply { purchasesResult.addAll(this) }
Log.d(LOG_TAG, "queryPurchasesAsync SUBS results: ${result?.purchasesList?.size}")
}
processPurchases(purchasesResult)
}
您应该在与BillingClient服务建立连接后立即拨打此电话:
/**
* This is the callback for when connection to the Play [BillingClient] has been successfully
* established. It might make sense to get [SkuDetails] and [Purchases][Purchase] at this point.
*/
override fun onBillingSetupFinished(billingResult: BillingResult) {
when (billingResult.responseCode) {
BillingClient.BillingResponseCode.OK -> {
Log.d(LOG_TAG, "onBillingSetupFinished successfully")
querySkuDetailsAsync(BillingClient.SkuType.INAPP, GameSku.INAPP_SKUS)
querySkuDetailsAsync(BillingClient.SkuType.SUBS, GameSku.SUBS_SKUS)
queryPurchasesAsync()
}
BillingClient.BillingResponseCode.BILLING_UNAVAILABLE -> {
//Some apps may choose to make decisions based on this knowledge.
Log.d(LOG_TAG, billingResult.debugMessage)
}
else -> {
//do nothing. Someone else will connect it through retry policy.
//May choose to send to server though
Log.d(LOG_TAG, billingResult.debugMessage)
}
}
}