Gdx-Pay check for purchases

前提是你 提交于 2019-12-11 03:49:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!