Search code examples
in-app-purchasein-app-billingin-app

Testing with In app billing "Payment options"


I want to integrate In app billing in my android app. I am using version 3 apis. So for this I have created one managed product.

I am following this tutorial. Given below is my code.

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");

        }
    });

}

It displays product and it's displaying that it's in test mode. But after that it displays Payment Options. Do I need to add my actual account this or is there a way to test without adding an actual account ?


Solution

  • You need a "real" account to test in app-billing on Android. This account must be different than the account you use for the developer console. You will have to enter valid credit card information. Then add this account to account with testing access. (Developer console -> Settings -> Account Details -> Gmail accounts with testing access)

    When you use a account to purchase items, the account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with that account (go to your Google Checkout, select order you want to refund and click Cancel entire order), otherwise the purchases will show up as actual payouts to your merchant account.

    Quote from Google website:

    Test purchases are real orders and Google Play processes them in the same way as other orders. When purchases are complete, Google Play prevents the orders from going to financial processing, ensuring that there are no actual charges to user accounts, and automatically canceling the completed orders after 14 days.

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