简体   繁体   English

管理Google Play订阅无效

[英]Managing Google Play subscriptions not working

My app has in-app subscription purchases but I am feeling really confused regarding the whole implementation process. 我的应用有应用内订阅购买,但我对整个实施过程感到非常困惑。

When the app opens I am calling onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) to check if the user has any active purchases. 当应用程序打开时,我正在调用onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases)来检查用户是否有任何有效购买。 If the purchase list is null, the app assumes the user has not purchased anything. 如果购买清单为空,则该应用会假定用户未购买任何东西。

Later when user decides to purchase something app calls: 稍后,当用户决定购买一些应用调用时:

mBillingClient = BillingClient.newBuilder(view.getContext()).setListener(new PurchasesUpdatedListener()

Once the purchase is made again onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) is called, however, once I reopen the app nothing works, its all back to normal (free version) like user purchased nothing. 一旦再次购买,就会onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) ,但是,一旦我重新打开该应用程序,它将无法正常工作,它会像用户未购买任何东西一样恢复到正常(免费版本)。

Also, user purchase data wasn't stored in the cloud (firebase real-time database). 此外,用户购买的数据也没有存储在云(firebase实时数据库)中。 Already three users have made their purchase and it's in Three Day Trial period. 已经有三位用户进行了购买,并且处于三天试用期。

Have you looked at the sample on GitHub ? 您是否在GitHub上查看了示例 When user opens your app you are supposed to call queryPurchases . 当用户打开您的应用程序时,您应该调用queryPurchases Here is an example: 这是一个例子:

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)
    }

And you should make this call as soon as you establish connection with the BillingClient service: 与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)
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM