hi this is my first post, i have written below code for billing, when i was testing app i purchase all items and now i am getting this error “7 unable to buy item (response: 7:item already owned)” i am using android native plugin for this
right now my app is live please help me asap, it is some urgent help required i try to search on google alot but i could not figure this out… please help me asap.
using UnityEngine;
using UnityEngine.UI;
using UnionAssets.FLE;
using System.Collections.Generic;
using System.Collections;
public class BillingWork : MonoBehaviour {
public const string Two_Life_PurChase = "2life";
public const string Six_Life_PurChase = "6life";
public const string Twelve_Life_PurChase = "12life";
public const string Thirty_Life_PurChase = "30life";
public const string Three_Energy_PurChase = "3energy";
public const string Eight_Energy_PurChase = "8energy";
public const string Eighteen_Energy_PurChase = "18energy";
public const string Fourty_Energy_PurChase = "40energy";
/// <summary>
/// Consumeable
/// </summary>
public const string UnLockStageTwo = "cookingshow";
public const string UnLockStageThree = "masterchef";
private bool ListnersAdded = false;
void Awake()
{
int billingintif = PlayerPrefs.GetInt("billingint");
if (billingintif == 1) {
Debug.LogWarning("billingifopen");
if (ListnersAdded) {
return;
}
AndroidInAppPurchaseManager.instance.addProduct (Two_Life_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Six_Life_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Twelve_Life_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Thirty_Life_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Three_Energy_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Eight_Energy_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Eighteen_Energy_PurChase);
AndroidInAppPurchaseManager.instance.addProduct (Fourty_Energy_PurChase);
AndroidInAppPurchaseManager.instance.addEventListener (AndroidInAppPurchaseManager.ON_PRODUCT_PURCHASED,
OnProductPurchased);
AndroidInAppPurchaseManager.instance.addEventListener (AndroidInAppPurchaseManager.ON_PRODUCT_CONSUMED,
OnProductConsumed);
AndroidInAppPurchaseManager.instance.addEventListener (AndroidInAppPurchaseManager.ON_BILLING_SETUP_FINISHED,
OnBillingConnected);
AndroidInAppPurchaseManager.instance.loadStore ();
ListnersAdded = true;
}
PlayerPrefs.SetInt("billingint", 2);
}
private void OnProductPurchased(CEvent e) {
BillingResult result = e.data as BillingResult;
if(result.isSuccess) {
OnProcessingPurchasedProduct (result.purchase);
} else {
AndroidMessage.Create("Product Purchase Failed", result.response.ToString() + " " + result.message);
}
}
private void OnProductConsumed(CEvent e) {
BillingResult result = e.data as BillingResult;
if(result.isSuccess) {
OnProcessingConsumeProduct (result.purchase);
} else {
//AndroidMessage.Create("Product Cousume Failed", result.response.ToString() + " " + result.message);
}
}
private void OnProcessingConsumeProduct(GooglePurchaseTemplate purchase) {
switch(purchase.SKU) {
}
}
private void OnBillingConnected(CEvent e) {
BillingResult result = e.data as BillingResult;
AndroidInAppPurchaseManager.instance.removeEventListener (AndroidInAppPurchaseManager.ON_BILLING_SETUP_FINISHED, OnBillingConnected);
if(result.isSuccess) {
//Store connection is Successful. Next we loading product and customer purchasing details
AndroidInAppPurchaseManager.instance.addEventListener (AndroidInAppPurchaseManager.ON_RETRIEVE_PRODUC_FINISHED, OnRetrieveProductsFinised);
AndroidInAppPurchaseManager.instance.retrieveProducDetails();
}
}
private void AddLifesToGame(int AmountToAdd)
{
int val = PlayerPrefs.GetInt("Life",0);
AndroidToast.ShowToastNotification ("Life: " + val);
int finallife = val + AmountToAdd;
PlayerPrefs.SetInt("Life",finallife);
AndroidToast.ShowToastNotification("Final Life: " + finallife);
}
private void AddEnergyToGame(int AmountToAdd)
{
float val = PlayerPrefs.GetFloat("startenergyleft");
float finalenergy = val + AmountToAdd;
PlayerPrefs.SetFloat("startenergyleft",finalenergy);
}
private void OnProcessingPurchasedProduct(GooglePurchaseTemplate purchase) {
//some stuff for processing product purchse. Add coins, unlock track, etc
switch(purchase.SKU) {
case Two_Life_PurChase:
AddLifesToGame(2);
break;
case Six_Life_PurChase:
AddLifesToGame(6);
break;
case Twelve_Life_PurChase:
AddLifesToGame(12);
break;
case Thirty_Life_PurChase:
AddLifesToGame(30);
break;
case Three_Energy_PurChase:
AddEnergyToGame(3);
break;
case Eight_Energy_PurChase:
AddEnergyToGame(8);
break;
case Eighteen_Energy_PurChase:
AddEnergyToGame(18);
break;
case Fourty_Energy_PurChase:
AddEnergyToGame(40);
break;
case UnLockStageTwo:
PlayerPrefs.SetInt ("stackpayoff", 2);
break;
case UnLockStageThree:
PlayerPrefs.SetInt ("stackpayoff", 3);
break;
}
}
private void OnRetrieveProductsFinised(CEvent e) {
BillingResult result = e.data as BillingResult;
AndroidInAppPurchaseManager.instance.removeEventListener (AndroidInAppPurchaseManager.ON_RETRIEVE_PRODUC_FINISHED, OnRetrieveProductsFinised);
if(result.isSuccess) {
UpdateStoreData();
} else {
//AndroidMessage.Create("Connection Responce", result.response.ToString() + " " + result.message);
}
}
public void scorescene()
{
Application.LoadLevel ("score");
}
public void TwoLife()
{
AndroidToast.ShowToastNotification("Purchasing Two Life");
purchase (Two_Life_PurChase);
}
public void SixLife()
{
purchase (Six_Life_PurChase);
}
public void TwelveLife()
{
purchase (Twelve_Life_PurChase);
}
public void ThirtyLife()
{
purchase (Thirty_Life_PurChase);
}
public void ThreeEnergyPurChase()
{
purchase (Three_Energy_PurChase);
}
public void EightEnergyPurChase()
{
purchase (Eight_Energy_PurChase);
}
public void EighteenEnergyPurChase()
{
purchase (Eighteen_Energy_PurChase);
}
public void FourtyEnergyPurChase()
{
purchase (Fourty_Energy_PurChase);
}
public void UnLockLevel()
{
int stageVal = PlayerPrefs.GetInt ("stackpayoff", 1);
if(stageVal == 1)
{
purchase(UnLockStageTwo);
}
else if(stageVal == 2)
{
purchase(UnLockStageThree);
}
}
private void purchase(string SKU) {
Debug.LogWarning (SKU);
AndroidInAppPurchaseManager.instance.purchase (SKU);
}
private void consume(string SKU) {
AndroidInAppPurchaseManager.instance.consume (SKU);
}
private void UpdateStoreData() {
foreach(GoogleProductTemplate p in AndroidInAppPurchaseManager.instance.inventory.products) {
Debug.Log("Loaded product: " + p.title);
}
//chisking if we already own some consuamble product but forget to consume those
if(AndroidInAppPurchaseManager.instance.inventory.IsProductPurchased(UnLockStageTwo)) {
consume(UnLockStageTwo);
PlayerPrefs.SetInt("stackpayoff",2);
}
else if(AndroidInAppPurchaseManager.instance.inventory.IsProductPurchased(UnLockStageThree)) {
consume(UnLockStageThree);
PlayerPrefs.SetInt("stackpayoff",3);
}
//Check if non-consumable rpduct was purchased, but we do not have local data for it.
//It can heppens if game was reinstalled or download on oher device
//This is replacment for restore purchase fnunctionality on IOS
}
}