gpt4 book ai didi

android - 使用 Google Play Billing,是否可以等到确认购买后再授予应用内购买的权利?

转载 作者:行者123 更新时间:2023-11-30 04:57:21 27 4
gpt4 key购买 nike

Google Play Billing library关于 acknowledging purchases 的文档指出:

you must acknowledge all purchases that have a SUCCESS state received through the Google Play Billing Library as soon as possible after granting entitlement to the user.

因此,您的应用应首先向用户提供他购买的商品,然后确认购买。这也是他们的示例代码所暗示的:

fun handlePurchase() {
if (purchase.purchaseState === PurchaseState.PURCHASED) {
// Grant entitlement to the user.
...
// Acknowledge the purchase if it hasn't already been acknowledged.
if (!purchase.isAcknowledged) {
val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
client.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener)
}
}
}

我目前正在开发一个 Android 应用程序,我允许用户访问他们购买的内容之后以 OK 状态返回的确认(反之亦然):

private fun acknowledgePurchase(purchase: Purchase) {
val params = AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()

billingClient.acknowledgePurchase(params) { billingResult ->
when (billingResult.responseCode) {
BillingResponseCode.OK -> loadPurchase(purchase.sku)
else -> { ... }
}
}
}

因为文档指出:

... you must acknowledge all purchases within three days. Failure to properly acknowledge purchases results in those purchases being refunded.

如果发生这种情况,并且用户获得退款,则用户对该产品的权利也应该被撤销。但就我而言,进行购买意味着加载数据、将内容存储在数据库中等等,而我没有,也不希望有适当的代码来恢复它。因此,我只在成功确认之后才向用户提供产品。

因此我的问题是:是否可以等到确认购买后再授予应用内购买的权利?还是我在这里遗漏了一些问题?我假设文档指定此顺序是有原因的,但他们没有详细说明。

最佳答案

经过更多研究后,我注意到 Trivial Drive sample app采用与我完全相同的方法。以下是 their code 的 fragment :

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

}
}

如果响应正常,则表明在确认回调函数中授予了权利。与我问题中的代码完全相同。

所以我想问题的答案是:是的,确认成功后授予权利是可以的。

关于android - 使用 Google Play Billing,是否可以等到确认购买后再授予应用内购买的权利?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58894656/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com