Android Google Play计费库3.0+;-恢复购买

Android Google Play计费库3.0+;-恢复购买,android,in-app-purchase,android-inapp-purchase,Android,In App Purchase,Android Inapp Purchase,使用Google Play Billing Library v3.0+我们有了一个新的购买流程,所有内容都在这里得到了完美的解释: 在旧版本的库中,我们将恢复如下内容: bp = new BillingProcessor(this, MERCHANT_ID, new BillingProcessor.IBillingHandler() { @Override public void onProductPurchased(@NonNull String produ

使用Google Play Billing Library v3.0+我们有了一个新的购买流程,所有内容都在这里得到了完美的解释:

在旧版本的库中,我们将恢复如下内容:

bp = new BillingProcessor(this, MERCHANT_ID, new BillingProcessor.IBillingHandler() {
        @Override
        public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {
            String orderId = details.purchaseInfo.purchaseData.productId;
  // we then compare the orderID with the SKU and see if the user purchased the item,
  // however in the new version of the library there is nothing about restore
但是,文档中没有关于恢复购买的内容


例如,我们有一个用例,您有一个有效的订阅和一个您购买的IAP产品。您可以删除应用程序并重新安装。如何恢复订阅和IAP产品?

BillingProcessor和onProductPurchased似乎不是Play Billing Library(或AIDL)的一部分,它更像是anjlab()实现的包装类
为了满足您的需求,我认为并可以提供帮助。

基本上queryPurchaseHistoryAsync完成了这项工作,只需小心传递SKU类型(inapp或SUB)

我的实施:

fun restorePurchaseInApp() {
    bp.queryPurchaseHistoryAsync("inapp", this)
}

fun restorePurchaseInSubs() {
    bp.queryPurchaseHistoryAsync("subs", this)
}

// bp is BillingClient
// the class should implement PurchaseHistoryResponseListener

override fun onPurchaseHistoryResponse(
    p0: BillingResult,
    p1: MutableList<PurchaseHistoryRecord>?
) {
    if (p1 != null) {
        Log.d("TMS", "onPurchaseHistoryResponse: " + p1.size)
    }

    if (p1 != null) {
        for (item in p1) {
            Log.d("TMS", "onPurchaseHistoryResponse sku: " + item.sku)
            Log.d("TMS", "onPurchaseHistoryResponse signature: " + item.signature)
            Log.d("TMS", "onPurchaseHistoryResponse purchaseToken: " + item.purchaseToken)
            Log.d("TMS", "onPurchaseHistoryResponse purchaseTime: " + item.purchaseTime)
        }
    }
}
fun restorePurchaseInApp(){
bp.queryPurchaseHistoryAsync(“inapp”,本)
}
有趣的恢复性购买{
bp.queryPurchaseHistoryAsync(“subs”,this)
}
//英国石油公司正在向客户付费
//该类应实现PurchaseHistoryResponseListener
覆盖onPurchaseHistoryResponse(
p0:BillingResult,
p1:可变列表?
) {
如果(p1!=null){
Log.d(“TMS”,“onPurchaseHistoryResponse:”+p1.size)
}
如果(p1!=null){
用于(p1中的项目){
Log.d(“TMS”、“onPurchaseHistoryResponse sku:+item.sku”)
Log.d(“TMS”,“onPurchaseHistoryResponse签名:”+项签名)
Log.d(“TMS”、“onPurchaseHistoryResponse purchaseToken:”+item.purchaseToken)
Log.d(“TMS”,“onPurchaseHistoryResponse purchaseTime:”+item.purchaseTime)
}
}
}
在这里,您可以看到购买的物品,仅此而已:)。我希望这会有所帮助,因为我花了很多时间来搞清楚一些如此简单的事情,而文档实现却没有提到这一点