syn*_*ded 0 android google-play in-app-subscription play-billing-library
我正在使用 Google 的计费库在我的应用程序内进行订阅。
~~ 3天后,google play已经退还了我用户的所有订阅,为什么呢?
一些带有活动的代码,用于进行订阅:
private var billingClient: BillingClient? = null
private val purchasesUpdateListener = PurchasesUpdatedListener { billingResult, purchases ->
val isSuccessResult = billingResult.responseCode == BillingClient.BillingResponseCode.OK
val hasPurchases = !purchases.isNullOrEmpty()
if (isSuccessResult && hasPurchases) {
purchases?.forEach(::confirmPurchase)
viewModel.hasSubscription.value = true
}
}
private fun confirmPurchase(purchase: Purchase) {
val consumeParams = ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
billingClient?.consumeAsync(consumeParams) { billingResult, _ ->
if (billingResult.responseCode != BillingClient.BillingResponseCode.OK) {
//all done
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
billingClient = BillingClient.newBuilder(this)
.setListener(purchasesUpdateListener)
.enablePendingPurchases()
.build()
connectToBillingService()
}
private fun connectToBillingService() {
billingClient?.startConnection(this)
}
private fun getPurchases(): List<Purchase> {
val purchasesResult = billingClient?.queryPurchases(BillingClient.SkuType.SUBS)
return purchasesResult?.purchasesList.orEmpty()
}
override fun onBillingSetupFinished(result: BillingResult) {
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
updateSkuMap()
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
因为您使用的是 Play Billing Library 2.0 或更高版本。从 Play Billing Library 2.0 开始,所有购买都必须在三天内得到确认。未能正确确认购买将导致购买被退款。查看Play Billing Library v2.0 发行说明和处理购买以了解更多详细信息。
| 归档时间: |
|
| 查看次数: |
396 次 |
| 最近记录: |