libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
225 stars 83 forks source link

Error Help: Payment system must be installed to perform this action #168

Closed manutyagi01 closed 6 years ago

manutyagi01 commented 6 years ago

Hi I am trying to get gdx-pay integrated into my project but am running into a strange error I cant seem to understand the cause of.

I setup the pay library as outlined in the wiki and sample project page, I am only trying to use test ids (android.test.purchased) on android phone which is on version 7.1.1, but keep getting the following error?

public final static String productID_fullVersion = "android.test.purchased";
06-02 16:42:56.783 31061-31085/com.mygdx.enso.android I/GdxPay/IAP: IAP: gdx-pay successfully instantiated.
06-02 16:42:56.783 31061-31085/com.mygdx.enso.android E/myPurchaseSystem:: com.badlogic.gdx.pay.android.googleplay.AndroidGooglePlayPurchaseManager@fcaa47f
    Canceltestpurchases supported!
06-02 16:42:56.813 31061-31085/com.mygdx.enso.android E/AndroidRuntime: FATAL EXCEPTION: GLThread 3933
    Process: com.mygdx.enso.android, PID: 31061
    com.badlogic.gdx.pay.android.googleplay.GdxPayException: Payment system must be installed to perform this action.
        at com.badlogic.gdx.pay.android.googleplay.AndroidGooglePlayPurchaseManager.assertInstalled(AndroidGooglePlayPurchaseManager.java:312)
        at com.badlogic.gdx.pay.android.googleplay.AndroidGooglePlayPurchaseManager.purchase(AndroidGooglePlayPurchaseManager.java:192)
        at com.badlogic.gdx.pay.PurchaseSystem.purchase(PurchaseSystem.java:148)
        at com.mygdx.enso.PlatformResolver.requestPurchase(PlatformResolver.java:47)
        at com.mygdx.enso.screens.ScreenLeaderboards$11.clicked(ScreenLeaderboards.java:330)
        at com.badlogic.gdx.scenes.scene2d.utils.ClickListener.touchUp(ClickListener.java:89)
        at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:59)
        at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:351)
        at com.badlogic.gdx.InputMultiplexer.touchUp(InputMultiplexer.java:96)
        at com.badlogic.gdx.backends.android.AndroidInput.processEvents(AndroidInput.java:383)
        at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:493)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1548)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1259)

I am calling these methods on button click when the error occurs when calling requestPurchase():

if (PurchaseSystem.hasManager())
Gdx.app.error("myPurchaseSystem:", PurchaseSystem.getManager().toString());

PurchaseManager manager = PurchaseSystem.getManager();
if (manager instanceof PurchaseManagerTestSupport) {
//((PurchaseManagerTestSupport) manager).cancelTestPurchases();
Gdx.app.error("myPurchaseSystem:", "Canceltestpurchases supported!");
}

topControlRef.getPlatformResolver().requestPurchase(topControlRef.productID_fullVersion);

I also called AndroidGooglePlayPurchaseManager.isRunningViaGooglePlay() which returned true and the error seems to be related to this following method in AndroidGooglePlayPurchaseManager :

 private void assertInstalled() {
        if (!installed()) {
            throw new GdxPayException("Payment system must be installed to perform this action.");
        }
    }

   @Override
    public boolean installed() {
        return googleInAppBillingService.isListeningForConnections();
    }

Also noticed the following message in logcat:

06-02 18:16:29.273 1554-1554/com.mygdx.enso.android D/GdxPay/V3GoogleIABS: start onServiceConnected(), isConnected() is: false

any help would be greatly appreciated.....

manutyagi01 commented 6 years ago

Fixed: calling PurchaseSystem.onAppRestarted(); at the incorrect location in code seems to have been the cause of the problem. :)