Search code examples
androidlibgdxin-app-purchaseamazon-appstore

Amazon says PurchasingService.getPurchaseUpdates() not being called from libgdx project


I'm attempting to use the class PurchaseManagerAndroidAmazon to handle purchases for my libdx project. The following are within the interface to access the android methods from within the core project:

public void createPurchaseSystem();
public void getPurchaseUpdates();
public void getUserInformation(); 
public void purchaseItem(String id);

These are the actual methods within the AndroidApplication:

PurchaseManagerAndroidAmazon pm;

@Override
protected void onResume() {
    Log.d(TAG, "onResume");

    if(pm != null) {
        getUserInformation();
        getPurchaseUpdates();
    }

    super.onResume();
}

@Override
public void purchaseItem(String id) {
    Log.d(TAG, "purchaseItem");

    pm.purchase(id);
}

@Override
public void getUserInformation() {
    Log.d(TAG, "getUserInformation");

    if(pm == null)
        createPurchaseSystem();

    PurchasingService.getUserData();
}

@Override
public void getPurchaseUpdates() {
    Log.d(TAG, "getPurchaseUpdates");

    if(pm == null)
        createPurchaseSystem();

    PurchasingService.getPurchaseUpdates(true);
}

@Override
public void createPurchaseSystem() {
    Log.d(TAG, "createPurchaseSystem");

    if(pm == null)
        pm = new PurchaseManagerAndroidAmazon(this, 0);

    PurchaseManagerConfig config = new PurchaseManagerConfig();
    config.addOffer(new Offer().setType(OfferType.CONSUMABLE).setIdentifier(getString(R.string.min_id)));
    config.addOffer(new Offer().setType(OfferType.CONSUMABLE).setIdentifier(getString(R.string.med_id)));
    config.addOffer(new Offer().setType(OfferType.CONSUMABLE).setIdentifier(getString(R.string.max_id)));

    pm.install(new PurchaseObserver() {
        @Override
        public void handleInstall() {
            Log.d(TAG, "PurchaseSystem installed");
            PurchaseSystem.purchaseRestore();
        }

        @Override
        public void handleInstallError(Throwable err) {
            Log.e(TAG, "ERROR PurchaseObserver: handleInstallError!: " + err.getMessage());
            throw new GdxRuntimeException(err);
        }

        @Override
        public void handlePurchase(Transaction transaction) {
            Log.d(TAG, "PurchaseSystem handlePurchase: " + transaction.toString());

            pm.purchaseRestore();
        }

        @Override
        public void handlePurchaseCanceled() {
            Log.d(TAG, "PurchaseSystem handlePurchaseCanceled");
        }

        @Override
        public void handlePurchaseError(Throwable err) {
            Log.d(TAG, "ERROR PurchaseObserver: handlePurchaseError!: " + err.getMessage());
            throw new GdxRuntimeException(err);
        }

        @Override
        public void handleRestore(Transaction[] transactions) {
            Log.d(TAG, "PurchaseSystem handleRestore: " + transactions.toString());
        }

        @Override
        public void handleRestoreError(Throwable err) {
            Log.d(TAG, "ERROR PurchaseObserver: handleRestoreError!: " + err.getMessage());
            throw new GdxRuntimeException(err);
        }
    }, config, true);
}

And this is within the core project:

HighPoint highPoint; // this class extends Game of libgdx

public void createDonationScreen() {

    if(!purchaseSytemCreated)
        createPurchaseSystem();

    TextButton minDonButton = new TextButton(....);
    medDonButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            highPoint.hpaInterface.getPurchaseUpdates();
            highPoint.hpaInterface.purchaseItem(MIN_ID);
        }
    });

Using the Amazon App Tester gives me the error

failed to call PurchasingService.getPurchaseUpdates()

but as you can tell its being called mulitple times. I feel I've put in too many times actually. The Amazon dialog pops up asking me to confirm the purchase when I click the button so it seems like it should work either way.

Any ideas would be greatly appreciated.


Solution

  • Adding call to PurchasingService.getPurchaseUpdates(false) in activity onResume callback solved the notification issue in my case.