package com.sometrik.framework;

import java.util.ArrayList;

import com.android.vending.billing.IInAppBillingService;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;

public class PurchaseHelper {
	
	IInAppBillingService mService;
	private static PurchaseHelper instance = null;
	protected PurchaseHelper() { }
	public static PurchaseHelper getInstance() {
		if (instance == null) {
			instance = new PurchaseHelper();
		}
		return instance;
	}

	ServiceConnection mServiceConn = new ServiceConnection() {
		@Override
		public void onServiceDisconnected(ComponentName name) {
			mService = null;
		}

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			mService = IInAppBillingService.Stub.asInterface(service);
		}
	};

	public Bundle getItemList(ArrayList<String> productIDList, String packageName) {
		//Create a query with Product IDs
		Bundle querySkus = new Bundle();
		querySkus.putStringArrayList("ITEM_ID_LIST", productIDList);
		try {
			//Retrieve details with query. 3 is the in-app Billing version.
			return mService.getSkuDetails(3, packageName, "inapp", querySkus);
		} catch (RemoteException e) {
			System.out.println("Error retrieving product list information");
			//TODO
			e.printStackTrace();
		}
		return null;
	}

	public void disconnect(FrameWork framework) {
		if (mService != null) {
			framework.unbindService(mServiceConn);
		}
	}

	public void createConnection(FrameWork framework) {
		Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
		serviceIntent.setPackage("com.android.vending");
		framework.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
	}

}

@@ -55,24 +55,87 @@
 rayList;%0D%0A%0D%0A
+import org.json.JSONException;%0D%0Aimport org.json.JSONObject;%0D%0A%0D%0A
 import com.a
@@ -1043,22 +1043,33 @@
 %09public 
-Bundle
+ArrayList%3CString%3E
  getItem
@@ -1346,22 +1346,36 @@
 on.%0D%0A%09%09%09
-return
+Bundle skuDetails = 
  mServic
@@ -1428,16 +1428,166 @@
 Skus);%0D%0A
+%09%09%09%0D%0A%09%09%09int response = skuDetails.getInt(%22RESPONSE_CODE%22);%0D%0A%09%09%09if (response == 0) %7B%0D%0A%09%09%09%09return skuDetails.getStringArrayList(%22DETAILS_LIST%22);%0D%0A%09%09%09%7D%0D%0A
 %09%09%7D catc
@@ -1735,32 +1735,785 @@
 rn null;%0D%0A%09%7D%0D%0A%0D%0A
+%09//Meant to be used with responseList returned from getItemList%0D%0A%09public String getProductId(String response) %7B%0D%0A%09%09JSONObject object;%0D%0A%09%09try %7B%0D%0A%09%09%09object = new JSONObject(response);%0D%0A%09%09%09return object.getString(%22productId%22);%0D%0A%09%09%7D catch (JSONException e) %7B%0D%0A%09%09%09System.out.println(%22Error retrieving product ID from response%22);%0D%0A%09%09%09e.printStackTrace();%0D%0A%09%09%7D%0D%0A%09%09return %22%22;%0D%0A%09%7D%0D%0A%09%0D%0A%09//Meant to be used with responseList returned from getItemList%0D%0A%09public String getProductPrice(String response) %7B%0D%0A%09%09JSONObject object;%0D%0A%09%09try %7B%0D%0A%09%09%09object = new JSONObject(response);%0D%0A%09%09%09return object.getString(%22price%22);%0D%0A%09%09%7D catch (JSONException e) %7B%0D%0A%09%09%09System.out.println(%22Error retrieving product ID from response%22);%0D%0A%09%09%09e.printStackTrace();%0D%0A%09%09%7D%0D%0A%09%09return %22%22;%0D%0A%09%7D%0D%0A%09%0D%0A%0D%0A
 %09public void dis

Add getProductId and getProductPrice