使用In app billing"付款选项"进行测试

时间:2014-07-26 10:35:44

标签: in-app-purchase in-app-billing in-app

我想在我的Android应用中集成In app billing。我使用的是版本3 apis。因此,我创建了一个托管产品。

我正在关注此tutorial。以下是我的代码。

IabHelper mHelper;
final String BONUS_BUDGET = "bonus_budget";

Button purchaseButton;
String applePrice, skuID;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fantasy_login);

    purchaseButton = (Button) findViewById(R.id.login_button);

    String base64EncodedPublicKey = "MY BASE64 KEY";

    MyLog.e(TAG, "onCreate");

    mHelper = new IabHelper(this, base64EncodedPublicKey);

    final IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result,
                Inventory inventory) {
            if (result.isFailure()) {
                // handle error
                return;
            } else {
                Log.e(TAG,
                        "result : " + result.getResponse()
                                + result.getMessage());
            }

            try {
                if (inventory == null) {
                    Toast.makeText(FC_FantasyCricketLoginActivity.this,
                            "Inventory is null", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(
                            FC_FantasyCricketLoginActivity.this,
                            inventory.getSkuDetails(BONUS_BUDGET)
                                    .getPrice().toString(),
                            Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                Toast.makeText(FC_FantasyCricketLoginActivity.this,
                        "inventory catch block", Toast.LENGTH_LONG).show();
            }

            // Toast.makeText(FC_FantasyCricketLoginActivity.this, "",
            // duration)
            // Log.e(TAG,
            // "Inventory :" + inventory.getSkuDetails(BONUS_BUDGET).);
            //
            // applePrice =
            // inventory.getSkuDetails(BONUS_BUDGET).getPrice();
            // skuID = inventory.getSkuDetails(BONUS_BUDGET).getSku();

            // update the UI
        }
    };

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {

        @Override
        public void onIabSetupFinished(IabResult result) {

            if (result.isSuccess()) {
                Log.e(TAG, "Successfully set up in app billing");

                List<String> additionalSkuList = new ArrayList<String>();
                additionalSkuList.add(BONUS_BUDGET);

                Log.e(TAG, "Size of list"
                        + additionalSkuList.get(0).toString());

                mHelper.queryInventoryAsync(true, additionalSkuList,
                        mQueryFinishedListener);

            } else {
                Log.e(TAG,
                        "Problem in setting of in app billing "
                                + result.toString());
            }

        }
    });

    final IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result,
                Purchase purchase) {
            if (result.isFailure()) {
                Log.d(TAG, "Error purchasing: " + result);
                return;
            } else if (purchase.getSku().equals(skuID)) {

                Log.e(TAG,
                        "Purchase done time:"
                                + String.valueOf(purchase.getPurchaseTime())
                                + "SKU id : " + purchase.getSku());
            }
        }
    };

    purchaseButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            mHelper.launchPurchaseFlow(FC_FantasyCricketLoginActivity.this,
                    skuID, 10001, mPurchaseFinishedListener,
                    "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");

        }
    });

}

显示产品并显示其处于测试模式。但之后显示Payment Options。我是否需要添加我的实际帐户,或者有没有办法在不添加实际帐户的情况下进行测试?

1 个答案:

答案 0 :(得分:0)

您需要一个“真实”帐户才能在Android上的应用结算中进行测试。 此帐户必须与您用于开发人员控制台的帐户不同。 您必须输入有效的信用卡信息。 然后将此帐户添加到具有测试访问权限的帐户(开发者控制台 - &gt;设置 - &gt;帐户详细信息 - &gt;具有测试访问权限的Gmail帐户)

当您使用帐户购买商品时,该帐户将通过Google Checkout结算,您的Google Checkout商家帐户会收到购买款项。因此,您可能希望退还使用该帐户进行的购买(转到您的Google Checkout,选择要退款的订单并点击取消整个订单),否则购买将显示为您的商家帐户的实际付款。

来自Google网站的引用:

  

测试购买是真实订单,Google Play会将其处理   与其他订单相同。购买完成后,Google Play   防止订单进行财务处理,确保这一点   对用户帐户没有实际收费,也是自动收费   14天后取消已完成的订单。

链接:http://developer.android.com/google/play/billing/billing_testing.html