<commit_before>package com.soomla.store;

import android.content.Context;
import android.os.Handler;
import android.util.Log;
import com.soomla.billing.BillingService;
import com.soomla.billing.Consts;
import com.soomla.store.data.StorageManager;
import com.soomla.store.domain.VirtualGood;
import com.soomla.store.exceptions.VirtualItemNotFoundException;


public class SoomlaJS {

    public SoomlaJS(Context mContext, BillingService mBillingService, Handler mHandler, SoomlaStoreActivity mActivity) {
        this.mContext = mContext;
        this.mBillingService = mBillingService;
        this.mHandler = mHandler;
        this.mActivity = mActivity;
    }

    public void wantsToBuyCurrencyPacks(String productId){
        Log.d(TAG, "wantsToBuyCurrencyPacks " + productId);

        mBillingService.requestPurchase("android.test.purchased", Consts.ITEM_TYPE_INAPP, "");

        // TODO: implement according to productId
    }

    public void wantsToBuyVirtualGoods(String itemId) {
        Log.d(TAG, "wantsToBuyVirtualGoods " + itemId);
        try {
            VirtualGood good = StoreInfo.getInstance().getVirtualGoodBySoomlaId(itemId);

            int balance = StorageManager.getInstance().getVirtualGoodsStorage().add(good, 1);
            StorageManager.getInstance().getVirtualCurrencyStorage().remove(good.getmCurrencyValue());

            mActivity.sendSoomlaJS("goodsPurchase", "true," + itemId + "," + balance + ",''");
        } catch (VirtualItemNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void wantsToLeaveStore(){
        Log.d(TAG, "wantsToLeaveStore");
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mActivity.finish();
            }
        });
    }

    public void pageInitialized(){
        Log.d(TAG, "pageInitialized");
        mActivity.storeJSInitialized();
        mActivity.sendSoomlaJS("initialize", StoreInfo.getInstance().getJsonString());
    }

    private static final String TAG = "SOOMLA SoomlaJS";

    private Context mContext;
    private BillingService mBillingService;
    private Handler mHandler;
    private SoomlaStoreActivity mActivity;
}
<commit_msg>checking for insufficient funds to purchase a virtual good<commit_after>package com.soomla.store;

import android.content.Context;
import android.os.Handler;
import android.util.Log;
import com.soomla.billing.BillingService;
import com.soomla.billing.Consts;
import com.soomla.store.data.StorageManager;
import com.soomla.store.domain.VirtualGood;
import com.soomla.store.exceptions.VirtualItemNotFoundException;


public class SoomlaJS {

    public SoomlaJS(Context mContext, BillingService mBillingService, Handler mHandler, SoomlaStoreActivity mActivity) {
        this.mContext = mContext;
        this.mBillingService = mBillingService;
        this.mHandler = mHandler;
        this.mActivity = mActivity;
    }

    public void wantsToBuyCurrencyPacks(String productId){
        Log.d(TAG, "wantsToBuyCurrencyPacks " + productId);

        mBillingService.requestPurchase("android.test.purchased", Consts.ITEM_TYPE_INAPP, "");

        // TODO: implement according to productId
    }

    public void wantsToBuyVirtualGoods(String itemId) {
        Log.d(TAG, "wantsToBuyVirtualGoods " + itemId);
        try {
            VirtualGood good = StoreInfo.getInstance().getVirtualGoodBySoomlaId(itemId);

            if (StorageManager.getInstance().getVirtualCurrencyStorage().getBalance() >= good.getmCurrencyValue()){
                int balance = StorageManager.getInstance().getVirtualGoodsStorage().add(good, 1);
                StorageManager.getInstance().getVirtualCurrencyStorage().remove(good.getmCurrencyValue());

                mActivity.sendSoomlaJS("goodsPurchase", "true," + itemId + "," + balance + ",''");
            }
            else {
                int balance = StorageManager.getInstance().getVirtualGoodsStorage().getBalance(good);
                String failureMsg = "You don\'t have enough " + StoreInfo.getInstance().getVirtualCurrency().getName() + " to buy a " + good.getName() + ".";
                mActivity.sendSoomlaJS("goodsPurchase", "false," + itemId + "," + balance + ",'" + failureMsg + "'");
            }
        } catch (VirtualItemNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void wantsToLeaveStore(){
        Log.d(TAG, "wantsToLeaveStore");
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mActivity.finish();
            }
        });
    }

    public void pageInitialized(){
        Log.d(TAG, "pageInitialized");
        mActivity.storeJSInitialized();
        mActivity.sendSoomlaJS("initialize", StoreInfo.getInstance().getJsonString());
    }

    private static final String TAG = "SOOMLA SoomlaJS";

    private Context mContext;
    private BillingService mBillingService;
    private Handler mHandler;
    private SoomlaStoreActivity mActivity;
}

{'fraction_non_alphanumeric': 0.10748407643312102, 'fraction_numerical': 0.0003980891719745223, 'mean_word_length': 3.0622473726758286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4818796', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1401, 'n_words': 261}