问题
I've finished setting up my IAP system but I can't figure out how to check if the user actually owns/have purchased a certain product. Using Google IAP Billing for android I simply did:
Purchase ITEM_1 = inventory.getPurchase(ITEM_1);
if(ITEM_1 != null && verifyDeveloperPayload(ITEM_1)){
//Give user the product
ITEM_1_BOUGHT = true;
}
I can't find an equivalent method for this in Gdx-Pay.
回答1:
The PurchaseObserver
has a method called: handleRestore(Transaction[] transactions)
You can iterate through transactions:
@Override
public void handleRestore(Transaction[] transactions) {
for (int i = 0; i < transactions.length; i++) {
// do something with all bought products.
if (transactions[i].getIdentifier().equals("YOUR_PRODUCT_IDENTIFIER")) {
// do something with a certain product
}
}
}
回答2:
There's a parent method getInformation() which is not showcased in any of the examples. You need to override it in the abstract PlatformResolver like
public Information getInformation(String identifier){
return mgr.getInformation(identifier);
}
then in your game class you need check whether the purchase exists like:
Information info = getPlatformResolver().getInformation(productId);
String getName = info.getLocalName();
if(getName == null)
getPlatformResolver().requestPurchase(productId);
来源:https://stackoverflow.com/questions/32374839/gdx-pay-check-for-purchases