Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Codeless IAP not working

Discussion in 'Unity IAP' started by NayDev, Dec 30, 2019.

  1. NayDev

    NayDev

    Joined:
    Dec 2, 2018
    Posts:
    3
    I'm aving a small issue that i cant resolve.

    I first add codeless IAP in the first scene of my game and it was working 100% on my android Phone.

    I decided to move the store in an other scene and everything stop working... cant find what i'm doing wrong.

    Some one have a hint?

    I've tryed to create a Initialisation script that i added to a gameobject in the desired scene (not the first scene of the game)

    ___________________________________________________________

    using UnityEngine;
    using UnityEngine.Purchasing;

    public class MyIAPManager : MonoBehaviour, IStoreListener
    {

    private IStoreController controller;
    private IExtensionProvider extensions;

    void start()
    {
    var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    UnityPurchasing.Initialize(this, builder);
    }

    /// <summary>
    /// Called when Unity IAP is ready to make purchases.
    /// </summary>
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
    this.controller = controller;
    this.extensions = extensions;
    }

    /// <summary>
    /// Called when Unity IAP encounters an unrecoverable initialization error.
    ///
    /// Note that this will not be called if Internet is unavailable; Unity IAP
    /// will attempt initialization until it becomes available.
    /// </summary>
    public void OnInitializeFailed(InitializationFailureReason error)
    {
    }

    /// <summary>
    /// Called when a purchase completes.
    ///
    /// May be called at any time after OnInitialized().
    /// </summary>
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
    return PurchaseProcessingResult.Complete;
    }

    /// <summary>
    /// Called when a purchase fails.
    /// </summary>
    public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
    {
    }
    }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You'll likely need to use an IAP Listener and and make it globally available. And you are not using Codeless, you are using Script IAP as shown in your code. You can't mix the two, make sure you are don't use an IAP Button with the code above. Please see the two sample IAP projects here, the first is scripted and the second is Codeless with a Listener https://forum.unity.com/threads/sample-iap-project.529555/
     
    NayDev likes this.
  3. NayDev

    NayDev

    Joined:
    Dec 2, 2018
    Posts:
    3
    Ok I clean every things.

    When you mentionned "IAP Listener and and make it globally available". what should i do?
    I added it to the first scene.... i tryed to read to do a singleton without success...

    i'm a bit lost... and mixed up with all the documentation.
     
  4. NayDev

    NayDev

    Joined:
    Dec 2, 2018
    Posts:
    3


    I also try DontDestroyOnLoad(this.gameObject) in the MyApiManager script
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446