In app purchases working, but method not executing?
Asked Answered
H

1

1

I have successfully added in app purchases to my app, and it goes through fine:

enter image description here

but the if (purchase.getSku().equals("android.test.purchased")) doesn't go through, and so I can't update my UI with the premium version!

    public void buy(View v) {

        mHelper.launchPurchaseFlow(this, "android.test.purchased", 10001,
                mPurchaseFinishedListener, "developerPayLoadString");

    }

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
            = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if (result.isFailure()) {

                Toast.makeText(MainActivity.this, "Unable to make purchase.", Toast.LENGTH_SHORT).show();
                return;
            } else if (purchase.getSku().equals("android.test.purchased")) {
                Toast.makeText(MainActivity.this, "Successfully bought product!", Toast.LENGTH_SHORT).show();
            }
};

Why isn't the if (purchase.getSku().equals("android.test.purchased")) going through even though the payment is successful?

Thanks,

Ruchir

Heiskell answered 30/3, 2016 at 2:0 Comment(0)
H
0

In Security.java, method verifyPurchase(), add this:

 if (BuildConfig.DEBUG) {
            Log.v("myActivity", "Debug :)");
            return true;
        }

So, the total method should look like this:

  public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {

        if (BuildConfig.DEBUG) {
            Log.v("myActivity", "Debug :)");
            return true;
        }

        if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
                TextUtils.isEmpty(signature)) {
            Log.e(TAG, "Purchase verification failed: missing data.");
            return false;
        }



        PublicKey key = Security.generatePublicKey(base64PublicKey);
        return Security.verify(key, signedData, signature);
    }
Heiskell answered 1/4, 2016 at 3:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.