Unity&IAP

Unity&IAP

BY 27 Feb 2016 Native Application Development

Hello,

I’m testing the Unity Tizen IAP plugin, but I’m encountring a problem, after doing any request (GetAvailableItems, GetCountries… )  the app hangs on “Waiting for Plugin Callback” and the callBackHandler never called!

To reproduce the issue, create a new project using the latest Unity version, import the Tizen IAP plugin from Asset Store, open the TizenSampleAppScene in the examples folder , build it and run it in your Tizen device.

There is someone that can help me to make Unity Tizen IAP working?

Thanks

The source code of the scene:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using Tizen.IAP;

public class SampleClass
{
    public int Value { get; set;}

	public SampleClass(int x)
	{
		Value = x;
	}
}

public class TizenSampleApp : MonoBehaviour {

	string userMCC = null;
	string userMNC = null;
	string userGrpId = null;
	string userItemTypeCd = null;
	string userBuyItemName = null;
	public SampleClass userData = null;
	
	//IAP object initialization
	
	StoreProvider storeObj = StoreProvider.Instance;
	IAP_AppRequest appReq = new IAP_AppRequest ();


	void Start () {
		//valid data
		appReq.Mode  = "1";
		appReq.StartNumber = 1;
		appReq.EndNumber = 200;
		appReq.StartDate = "2014-01-01";
		appReq.EndDate = "2020-12-31";
		appReq.ItemId = "000000581522";
		appReq.ItemName = "item1";
		appReq.ItemGroupId = "100000070614";
		appReq.LanguageCd = "ENG";
		appReq.ItemTypeCd = "10";
		appReq.Mcc = "404";
		appReq.Mnc = "01";
		
		//calbackHandler
		appReq.RequestCallbackHandler = callBackHandler;
		userData = new SampleClass (12);
		appReq.RequestCallbackUserData = userData;
	}
	void Update (){
	}

	//for debug
	public void printAllDetails(string a, string b , string c,string d)
	{
		//for Logs only
		Debug.Log ("[UnityAppLOG]" + a);
		Debug.Log ("[UnityAppLOG]" + b);
		Debug.Log ("[UnityAppLOG]" + c);
		Debug.Log ("[UnityAppLOG]" + d);

	}

	//for debug
	void LogCheck(string log){
		Debug.Log(log);
	}

	//CallBackHandler Definition
	public void callBackHandler(IAP_AppResponse response)
	{
		Debug.Log ("[ENTER CALLBACK ...........  UNITY APP");
		if(response.ErrorCode == ErrorType.ERROR_ALL_SUCCESS)
		{
			if (response.RequestCode == RequestType.FUNC_GET_COUNTRY_LIST) {
				List<IAP_Country> countries = response.Countries;
				int i;
				for (i=0; i<countries.Count; i++) {
					Debug.LogError ("[UnityAppLOG]" + countries [i].Name);
					Debug.LogError ("[UnityAppLOG]" + countries [i].Mcc);
				}
			}
	
			if (response.RequestCode == RequestType.FUNC_GET_ITEM_LIST) {	

				List<IAP_Item> AvailableItems = response.AvailableItems;
				int i;
				for(i = 0; i < AvailableItems.Count ; i++){
					Debug.LogError("[UnityAppLOG]" + AvailableItems [i].ItemName);
				}
		}
			if (response.RequestCode == RequestType.FUNC_GET_PURCHASED_ITEM_LIST) {
				List<IAP_Item> PurchasedItems = response.PurchasedItems;
				int i;
				for (i = 0; i < PurchasedItems.Count ; i++){
					Debug.LogError("[UnityAppLOG]" + PurchasedItems [i].ItemName);
				}
			}

			if (response.RequestCode == RequestType.FUNC_PURCHASE) {

				IAP_Purchase PurchaseOrder = response.PurchaseOrder;
				Debug.LogError("[UnityAppLOG]" + "Purchased Item is "+PurchaseOrder.ItemName);
			}

			if (response.RequestCode == RequestType.FUNC_NONE) {

				Debug.LogError("[UnityAppLOG]" + "No Request type came in Callback ");
			}

			SampleClass receivedData = (SampleClass) response.UserData;
			Debug.LogError("User Data Value : " + receivedData.Value);

		}

		else if (response.ErrorCode == ErrorType.ERROR_ALLOC_FAIL){
			Debug.Log("[UnityAppLOG]" + "Alloc Failed \n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_APP_CONTROL_ERROR){
			Debug.Log ("[UnityAppLOG]" + "APP CONTROL ERROR\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_RESULT_FAIL ){
			Debug.Log ("[UnityAppLOG]" + "Result Failed \n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_RESULT_CANCELLED){
			Debug.Log ("[UnityAppLOG]" + " Result cancelled\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_INPUT_FPTR ){
			Debug.Log ("[UnityAppLOG]" + " Invalid Input Fptr\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_INPUT_PARAM){
			Debug.Log ("[UnityAppLOG]" + " Invalid Input Param \n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_ITEM_GRP_ID){
			Debug.Log ("[UnityAppLOG]" + " Invalid Item Group ID\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_ITEM_ID){
			Debug.Log ("[UnityAppLOG]" + " Invalid Item Id \n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_TRANSACTION_ID){
			Debug.Log ("[UnityAppLOG]" + " Invalid Transaction Id\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_ITEM_TYPE_ID){
			Debug.Log ("[UnityAppLOG]" + " Invalid Item Type \n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_PARAM_MCC ){
			Debug.Log ("[UnityAppLOG]" + " Invalid Mcc Param\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_INVALID_PARAM_MNC){
			Debug.Log ("[UnityAppLOG]" + " Invalid Param Mnc\n");
		}

		else if (response.ErrorCode == ErrorType.ERROR_UNKNOWN_ERROR ){
			Debug.Log ("[UnityAppLOG]" + " Unknown Error \n");
		}
	}

	public void reEnableButton(Button button){
		button.interactable = true;
	}
	
	IEnumerator MyMethod(Button button) {
		Debug.Log("[UnityAppLOG]" + "Before Waiting 10 seconds");
		yield return new WaitForSeconds(10);
		Debug.Log("[UnityAppLOG]" + "After Waiting 10 Seconds");
		Debug.Log ("[UnityAppLOG]" + "ReEnabling Button\n");
		reEnableButton (button);
	}



	public void getMcclist(Button button){

		//calling IAP GET Countries API
		storeObj.GetCountries(appReq);

		Debug.Log ("[UnityAppLOG]" + "Disabling button\n");
		button.interactable = false;
		Debug.Log ("[UnityAppLOG]" + "Fetching Mcc list\n");
		StartCoroutine(MyMethod(button));


	}

	public void getMnclist(Button button){
	
		//automatically filled 
		Debug.Log ("[UnityAppLOG]" + "Disabling button\n");
		button.interactable = false;
		Debug.Log ("[UnityAppLOG]" + "Fetching Mnc list\n");
		GameObject.Find ("MNC").GetComponent<InputField> ().placeholder.GetComponent<Text>().text = "01";
		StartCoroutine(MyMethod(button));
	}

	public void userMccInput(Text text){
		Debug.Log ("User Input Data Being Fetched \n");
		userMCC = text.text;
		if(!string.IsNullOrEmpty(userMCC)){
		LogCheck(userMCC);
		}
	}

	public void userMncInput(Text text){
		Debug.Log ("User Input Data Being Fetched \n");
		userMNC = text.text;
		LogCheck(userMNC);
	}

	public void userGrpIdInput(Text text){
		Debug.Log ("User Input Data Being Fetched \n");
		userGrpId = text.text;
		LogCheck(userGrpId);
	
	}

	public void userItemTypeCode(Text text){
		Debug.Log ("User Input Data Being Fetched \n");
		userItemTypeCd = text.text;
		LogCheck(userItemTypeCd);
	}

	public void userBuyItemNameInput(Text text){
		Debug.Log ("User Input Data Being Fetched \n");
		userBuyItemName = text.text;
		LogCheck(userBuyItemName);
	}
	public void getItemList(Button button)
	{
		Debug.Log ("[UnityAppLOG]" + "Get Item List Button Pressed\n");

		Debug.Log ("[UnityAppLOG]" + "Disabling button\n");
		button.interactable = false;
		StartCoroutine(MyMethod(button));
		GameObject.Find ("Buy").GetComponent<Button> ().interactable = true;


		//setting user input values
		if(!string.IsNullOrEmpty(userMCC)){
			appReq.Mcc = userMCC;
		}
		else{
			GameObject.Find ("MCC").GetComponent<InputField> ().placeholder.GetComponent<Text>().text = appReq.Mcc;
		}
		if(!string.IsNullOrEmpty(userMNC)){
			appReq.Mnc = userMNC;
		}
		else{
			GameObject.Find ("MNC").GetComponent<InputField> ().placeholder.GetComponent<Text>().text = appReq.Mnc;
		}
		if(!string.IsNullOrEmpty(userGrpId)){
			appReq.ItemGroupId = userGrpId;
		}
		else{
			GameObject.Find ("GrpIdInput").GetComponent<InputField> ().placeholder.GetComponent<Text>().text = appReq.ItemGroupId;
		}
		if(!string.IsNullOrEmpty(userItemTypeCd)){
			appReq.ItemTypeCd = userItemTypeCd;
		}
		else{
			GameObject.Find ("ItemTypeCode").GetComponent<InputField> ().placeholder.GetComponent<Text>().text = appReq.ItemTypeCd;
		}
		 
		//calling IAP Get Item List API
		storeObj.GetAvailableItems(appReq);
		
		//for debugging
		//printAllDetails (userMCC, userMNC, userGrpId, userItemTypeCd);
		printAllDetails (appReq.Mcc,appReq.Mnc , appReq.ItemGroupId, appReq.ItemTypeCd);



	}
	public void getPurchasedList(Button button){
		
		//Calling IAP Get Purchase List API
		storeObj.GetPurchasedItems(appReq);


		button.interactable = false;
		StartCoroutine(MyMethod(button));
		GameObject.Find ("Buy").GetComponent<Button> ().interactable = true;

	}
	public void doBuying(Button button){

		if(!string.IsNullOrEmpty(userBuyItemName)){
			appReq.ItemName = userBuyItemName;

		}
		else{
			GameObject.Find ("BuyItem").GetComponent<InputField> ().placeholder.GetComponent<Text>().text = appReq.ItemName;
		}

		
		//Calling IAP Purchase API
		storeObj.PurchaseItem (appReq);

		button.interactable = false;
		StartCoroutine(MyMethod(button));

	}
}

 

 

 

 

 

 

 

 

 

 

Written by