-2

I added In-app billing v3 in my app and when I try to buy an item, the transfer is successful and money is taken from credit card, but the item doesn't add in app. What could be wrong?

//EDIT

public class GetcoinsActivity extends MainActivity {
SharedPreferences prefs_coins;  
static final String ITEM_SKU_1 = "coins_1"; 
static final int RC_REQUEST = 10001;
    private static final String TAG = "com.chess.black";

IabHelper mHelper;
Button btn1;

int score_get = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_getcoins);

prefs_coins = PreferenceManager.getDefaultSharedPreferences(GetcoinsActivity.this);
if (prefs_coins.contains(activity_play_normal.APP_PREFERENCES_score)) 
{
score_get = prefs_coins.getInt(activity_play_normal.APP_PREFERENCES_score, 0);      
}
btn1 = (Button) findViewById(R.id.buttonBuy30);

 String base64EncodedPublicKey = "here's my key";
                    mHelper = new IabHelper(this, base64EncodedPublicKey);

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

    }

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
    = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, 
                    Purchase purchase) 
    {
       if (result.isFailure()) {
          // Handle error
          return;
     }      
     else if (purchase.getSku().equals(ITEM_SKU_1)) {
         consumeItem();
    }

   }
};

public void consumeItem() {
    mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener 
   = new IabHelper.QueryInventoryFinishedListener() {
       public void onQueryInventoryFinished(IabResult result,
          Inventory inventory) 
       {           
          if (result.isFailure()) {
          // Handle failure
          } else {
                 mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU_1), 
            mConsumeFinishedListener);
          }
    }
};

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

if (result.isSuccess()) {               
     score_get = score_get + 500;
     Editor editor = prefs_coins.edit();        
     editor.putInt(activity_play_normal.APP_PREFERENCES_score, score_get);
     editor.commit();
} else {
       // handle error
}
}
};

    public void OnClickBuy30(View v)
    {
        mHelper.launchPurchaseFlow(GetcoinsActivity.this, ITEM_SKU_1, RC_REQUEST,   
               mPurchaseFinishedListener);
    }

    protected void OnDestroy()
    {
        super.onDestroy();
        if (mHelper != null) mHelper.dispose();
        mHelper = null;
    }

    protected void OnActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (!mHelper.handleActivityResult(requestCode, 
                  resultCode, data)) {     
            super.onActivityResult(requestCode, resultCode, data);
          }
    }
}
Alexander Sidikov Pfeif
  • 2,418
  • 1
  • 20
  • 35
Denis Lolik
  • 299
  • 1
  • 4
  • 11

1 Answers1

0

ok first please put Logs in your code ... (Log.d(..))

maybe your score will be not written in the preferences because the billing process is in another process .. try this

SharedPreferences yourPrefs= ctx.getSharedPreferences(ctx.PREFS_NAME,ctx.MODE_MULTI_PROCESS);
Alexander Sidikov Pfeif
  • 2,418
  • 1
  • 20
  • 35
  • And what if I will replace "... editor.putInt(...) ..." to method "OnCkickBuy30" after "mHelper.launchPurchaseFlow" and here "if (result.isSuccess()) { score_get = score_get + 500;} will be like this. Or it won't work too? – Denis Lolik Feb 15 '14 at 19:36