Inapp帐单:错误响应:7:测试事务已拥有项目 [英] Inapp billing: Error response: 7:Item Already Owned Issue With Test Transactions

查看:95
本文介绍了Inapp帐单:错误响应:7:测试事务已拥有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首次实施应用内结算.我能够完成第一笔交易,但是第二次在购买相同商品时,我在 onIabPurchaseFinished 方法上得到了错误响应:7:商品已拥有" ,如何制作可重新购买?任何帮助将不胜感激.

First time implementing in-app billing. i was able to complete first transaction, but second time while purchasing same item i am getting "Error response: 7:Item Already Owned" on onIabPurchaseFinished Method, how to make it re-purchase-able? any help would be appreciated.

代码结构的屏幕截图.

screenshot of code structure is also attached.

Onclick购买,我正在调用以下方法: initilizeInAppPurchasePakages();

Onclick purchase i am calling following method: initilizeInAppPurchasePakages();

 public void initilizeInAppPurchasePakages()
    {
        String base64EncodedPublicKey=getString(R.string.inAppBillingKey);
        mHelper = new IabHelper(getActivity(), base64EncodedPublicKey);
        mPurchaseFinishedListener
                = new IabHelper.OnIabPurchaseFinishedListener() {
            public void onIabPurchaseFinished(IabResult result, Purchase purchase)
            {
                if (result.isFailure()) {
                    Log.d(TAG, "Error purchasing: " + result);
               //     Toast.makeText(getActivity(),"fail to purchase"+result, Toast.LENGTH_SHORT).show();
                    return;
                }
                else if (purchase.getSku().equals(purchaseItemId)) {
                    transactionId=purchase.getOrderId();
                    PackageFragment.isNeedToUpdate = true;
                    // consume the gas and update the UI
                   // Toast.makeText(getActivity(), "purchase successfully", Toast.LENGTH_SHORT).show();
                    mHelper.consumeAsync(purchase,
                            mConsumeFinishedListener);
                }
                else if (purchase.getSku().equals(purchaseItemId)) {
                    // give user access to premium content and update the UI
                   // Toast.makeText(getActivity(), "purchase successfully", Toast.LENGTH_SHORT).show();
                }
            }
        };


        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    // Oh no, there was a problem.
                   // Toast.makeText(getActivity(), "connection Error", Toast.LENGTH_SHORT).show();
                }
                else
                {
                 //   Toast.makeText(getActivity(), "connected successfully", Toast.LENGTH_SHORT).show();
                    Log.d(TAG, "Problem setting up In-app Billing: " + result);
                    mHelper.launchPurchaseFlow(getActivity(), purchaseItemId, 10001,
                            mPurchaseFinishedListener, "testing");

                }
                // Hooray, IAB is fully set up!
            }
        });
         mConsumeFinishedListener =
                new IabHelper.OnConsumeFinishedListener() {
                    public void onConsumeFinished(Purchase purchase, IabResult result) {
                        if (result.isSuccess()) {
                            serverUtilities.savePayment(pakageId,pakagePrice,transactionId);
                          //  Toast.makeText(getActivity(), "consumed", Toast.LENGTH_SHORT).show();
                            // provision the in-app purchase to the user
                            // (for example, credit 50 gold coins to player's character)
                        }
                        else {

                            // handle error
                        }
                    }
                };
    }

推荐答案

好的,

花时间阅读了Google在应用结算方面的文档后,我发现我需要通过测试对应用结算进行测试,所以我做了

After spending time on reading documentation of google in app billing i found that i need to test in app billing through testing so what i did

测试帐单:

mHelper.launchPurchaseFlow(getActivity(), purchaseItemIdSKU, 10001,
                            mPurchaseFinishedListener, "testing");

仅第一次调用以删除我上面使用的测试帐单行上方的已购买条目记录: ArrayList skusToBeListed = null;

Calling only first time to remove that already purchased entry record above the test billing line that i used above: ArrayList skusToBeListed = null;

                skusToBeListed = new ArrayList<String> ();
                skusToBeListed.add (SKU_PREMIUM);
                skusToBeListed.add (SKU_PREMIUM_ELITE);
                skusToBeListed.add (SKU_PREMIUM_PLUS);

mHelper.queryInventoryAsync(true,skusToBeListed,mGotInventoryListener);

mHelper.queryInventoryAsync(true, skusToBeListed, mGotInventoryListener);

完成后,您可以毫无困难地进行许多测试预订.

and once its done you can do many test bookings without any headache.

 mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
            @Override
            public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
                if (result.isFailure()) {
                    //complain("Failed to query inventory: " + result);
                    return;
                }

                Purchase currentPurchase = inventory.getPurchase(purchaseItemIdSKU);
                if(currentPurchase != null)
                {
                    //Boolean  mIsPremium = (currentPurchase != null && verifyDeveloperPayload(currentPurchase));
                                       mHelper.consumeAsync(currentPurchase,mConsumeFinishedListener);

                }





        }
    } ;

注意: 如果不会返回测试帐单交易ID,请确保如何处理,我确实通过将其硬编码为以下格式对应用程序帐单进行了测试:"GPA.1234-5678-9012-34567"

Note: In case of test billing transaction id will not be returned so make sure how to handle that, i did tested my in app billing by hard coding it to following format: "GPA.1234-5678-9012-34567"

简而言之,如果我将我的代码用于生产模式,上面的代码很好,但是在测试模式下,它给了我我解释的错误并给出了解决方案.

In short above code of mine was fine if i would i have used it on production mode, but in case of testing mode it was giving me errors that i explained and given solution how i solved it.

这篇关于Inapp帐单:错误响应:7:测试事务已拥有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆