成功购买后Android应用内购买失败

问题描述 投票:0回答:1

我正在开发一个具有应用内购买功能的应用。我已将该应用程序在Play商店中进行了封闭测试。在帐户设置中包含测试者电子邮件和添加的测试者电子邮件。我在Play商店有2种被管理产品。我在调试模式下测试了android.test.purchased,它工作正常。但是,当我购买SKU时,从Play商店安装的发布版本成功完成了购买,但是由于某种原因,我收到了失败响应。我正在尝试解决这个问题。此外,我在购买后正在消费这些物品,因此它再次可用。这是我的代码

 mHelper = new IabHelper(this, Constants.BASE64_ENCODED_PUBLIC_KEY);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                Log.d(TAG, "In-app Billing setup failed due to: " +
                        result.getMessage());
            } else {
                //do further steps here.
                Log.d(TAG, "In-app Billing is set up OK");
            }
        }
    });

然后单击按钮

mHelper.launchPurchaseFlow(PurchaseActivity.this, ITEM_SKU, 10001,
                                mPurchaseFinishedListener, "mypurchasetoken");
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if (result.isFailure()) {
                Toast.makeText(PurchaseActivity.this, "mPurchaseFinishedListener: " + result.getMessage(), Toast.LENGTH_SHORT).show();
                if (result.getResponse() == 7) {
                    consumeItem();
                } else {
                    dismissProgressDialog();
                    Log.d(TAG, "onIabPurchaseFinishedWithError: " + result.getMessage());
                    AlertHelper.errorAlert(PurchaseActivity.this,
                            getString(R.string.purchase_unsuccessful_text), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.dismiss();
                                }
                            });

                }
            } else if (purchase.getSku().equals(ITEM_SKU)) {
                Log.d(TAG, "onIabPurchaseFinishedWithSuccess: ");
                consumeItem();
            }

        }
    };

public void consumeItem() {
   /* if (isTest) {
        try {
            int response = mHelper.mService.consumePurchase(3, getPackageName(), "inapp:" + getPackageName() + ":android.test.purchased");
            if (response == 0) {
                //Save purchase status to shared pref.
                updateUserAccount(ITEM_SKU);

                //Sign up user to our server.
                signUpUserToServer("android.test.purchased:9090");
                Log.d(TAG, "onConsumeFinishedSuccessfully");
            } else {
                Log.d(TAG, "onConsumeFinishedWithError: " + response);
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    } else*/
    mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result,
                                         Inventory inventory) {

        if (result.isFailure()) {
            dismissProgressDialog();
            Log.d(TAG, "onQueryInventoryFinishedWithError: " + result.getMessage());
            Toast.makeText(PurchaseActivity.this, "mReceivedInventoryListener: " + result.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        } else {
            Log.d(TAG, "onQueryInventoryFinished. asyncConsume fired. ");
            mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
                    mConsumeFinishedListener);
        }
    }
};

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
    public void onConsumeFinished(Purchase purchase, IabResult result) {

        if (result.isSuccess()) {
            if (isAlreadyOwned) {
                isAlreadyOwned = false;
                processPurchaseClick();
            } else {
                //Save purchase status to shared pref.
                updateUserAccount(ITEM_SKU);

                //Sign up user to our server.
                signUpUserToServer(purchase.getToken());
                Log.d(TAG, "onConsumeFinishedSuccessfully");
            }
        } else {
            Toast.makeText(PurchaseActivity.this, "onConsumeFinishedWithError: " + result.getMessage(), Toast.LENGTH_SHORT)
                    .show();
            Log.d(TAG, "onConsumeFinishedWithError: " + result.getMessage());
        }
    }
};

从测试帐户成功购买后,我在onPurchasefinishedListener中得到失败结果和R.string.purchase_unsuccessful_text。帮助PLZ

android in-app-purchase
1个回答
0
投票

我想出来了,所以我要发布答案,这样可能会对某人有所帮助。我的Base64公钥是另一个应用程序。我把正确的钥匙,它的工作。 This答案帮助了我。

© www.soinside.com 2019 - 2024. All rights reserved.