[Solved] You already own this item...

Hello,
I’m trying to add to my game micropayments using the in-App Purchasing Services.
I implemented the following code:

public class Purchaser : MonoBehaviour, IStoreListener
{
    [Tooltip("Consumable Product")]
    public string[] COIN_PRODUCTS;

    private static IStoreController m_StoreController;          // The Unity Purchasing system.
    private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.
 
    public int currentProductIndex;

    public static event OnSuccessBuyGoldEgg OnPurchaseGoldEgg;
    public delegate void OnSuccessBuyGoldEgg(PurchaseEventArgs args);

    private static string kProductNameGooglePlaySubscription = "com.unity3d.subscription.original";

    void Start()
    {
        if (m_StoreController == null)
        {
            InitializePurchasing();
        }
    }

    public void OnPurchaseComplete(Product produt)
    {
        Debug.Log(produt.metadata);
    }

    public void InitializePurchasing()
    {
        if (IsInitialized())
        {
            return;
        }

        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

        foreach (string s in COIN_PRODUCTS)
            builder.AddProduct(s, ProductType.Consumable);

        UnityPurchasing.Initialize(this, builder);
    }


    private bool IsInitialized()
    {
        return m_StoreController != null && m_StoreExtensionProvider != null;
    }


    public void BuyConsumable(int index)
    {
        currentProductIndex = index;
        BuyProductID(COIN_PRODUCTS[index]);
    }

    void BuyProductID(string productId)
    {
        if (IsInitialized())
        {
            Product product = m_StoreController.products.WithID(productId);

            if (product != null && product.availableToPurchase)
            {
                m_StoreController.InitiatePurchase(product);
            }
            else
            {
                Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        else
        {
            Debug.Log("BuyProductID FAIL. Not initialized.");
        }
    }

    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        Debug.Log("OnInitialized: PASS");
        m_StoreController = controller;
        m_StoreExtensionProvider = extensions;
    }


    public void OnInitializeFailed(InitializationFailureReason error)
    {
        Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
    }


    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        m_StoreController.ConfirmPendingPurchase(args.purchasedProduct);

        if (COIN_PRODUCTS.Length > 0 && String.Equals(args.purchasedProduct.definition.id, COIN_PRODUCTS[currentProductIndex], StringComparison.Ordinal))
        {
            OnSuccessC(args);
        }
        else {
            Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product '{0}'", args.purchasedProduct.definition.id));
        }
        return PurchaseProcessingResult.Complete;
    }

    private void OnSuccessC(PurchaseEventArgs args)
    {
        if (OnPurchaseGoldEgg != null) OnPurchaseGoldEgg(args);
        Debug.Log(COIN_PRODUCTS[currentProductIndex] + " Buyed!");
    }

    public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    {
        Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    }

    public void ExitToMainMenu()
    {
        SceneManager.UnloadScene(3);

        GameObject cameras = GameObject.Find("Main Camera");
        cameras.GetComponent<SaveGameManager>().LoadState(cameras);
        cameras.GetComponent<MainMenu_GUI>().mainMenuShow = true;
    }

and:

    private GameObject gameBaseObject;

    private CoinProduct[] coinProducts = new CoinProduct[]
    {
        new CoinProduct("eggs_pack_20.000", "Egg's Pack 20.000", 20000, "Buyng 20 000 Gold Egg!"),
        new CoinProduct("eggs_pack_50.000", "Egg's Pack 50.000", 50000, "Buyng 50 000 Gold Egg!"),
        new CoinProduct("eggs_pack_100.000", "Egg's Pack 100.000", 100000, "Buyng 100 000 Gold Egg!"),
        new CoinProduct("eggs_pack_500.000", "Egg's Pack 500.000", 500000, "Buyng 500 000 Gold Egg!")
    };

    // Use this for initialization
    void Start () {
        gameBaseObject = GameObject.Find("Main Camera");
        Purchaser.OnPurchaseGoldEgg += Purchaser_OnPurchaseGoldEgg;
    }

    private void Purchaser_OnPurchaseGoldEgg(UnityEngine.Purchasing.PurchaseEventArgs args)
    {
        for (int index = 0; index < coinProducts.Length; index++)
        {
            if (args.purchasedProduct.definition.id == coinProducts[index].ID)
            {
                gameBaseObject.GetComponent<Game>().goldEgg += coinProducts[index].AddingCoin;
                gameBaseObject.GetComponent<SaveGameManager>().SaveState(gameBaseObject);
                Debug.Log(coinProducts[index].DebugLog);
            }
        }
    }

What is wrong? Why are you after purchase does not receive the money? Why google play returns this message: “You already own this item”

@Lukasz-Wardak

In your ProcessPurchase function, you are calling ConfirmPendingPurchase. This is not the intended use of of ConfirmPendingPurchase and will result in unpredictable behavior.

In your example, you could just remove line 94 and your code should still work.

The most common use case for ConfirmPendingPurchase is when you are confirming your transactions on a server. The expected flow would be to return PurchaseProcessingResult.Pending in ProcessPurchase and then after your server confirms your purchase, call ConfirmPendingPurchase to finish that transaction.