我一直在测试新的Google计费库版本。发布说明中指出:“购买必须在三天内得到确认”。
在测试过程中,我注意到如果我不确认购买,则几分钟后购买会自动退款。
是这样的情况吗,Google将测试订单与正式订单区别对待,并仅允许在几分钟内确认订单而非3天,还是我遗漏了什么?
以下是我用来确认购买的代码。Purchase Holder是一个类,它保存了购买和SKU以及来自我的后端服务器的响应代码。
for (IABManager.PurchaseHolder pm : purchaseHolders){
if(pm.getSku().equals(SKU)) {//found matching SKU
if (pm.getActionResult() == IABManager.BillingActionResult.VALID_PURCHASE) {//valid purchase made
if(!pm.getPurchase().isAcknowledged()) {//purchase not yet acknowledged
iabManager.acknowledgePurchases(pm.getPurchase(), (billingResult) -> {
Log.d(TAG, "AcknowledgedPurchaseResponse received from Google");
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
unlockFeatures();
}
});
}else{
unlockFeatures();
}
} else if (pm.getActionResult() == IABManager.BillingActionResult.NON_VALID_PURCHASE){
lockFeatures();
}else{
Log.d(TAG, "BILLING_ACTION_RESULT = " + pm.getActionResult() + " doing nothing");
}
}
}
...以及 acknowledgePurchases 方法
public void acknowledgePurchases(Purchase purchase, AcknowledgePurchaseResponseListener listener){
AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.getPurchaseToken()).build();
billingClient.acknowledgePurchase(params, listener);
}