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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Running Codeless IAP buttons on Android restore not working

Discussion in 'Unity IAP' started by BeeSmart, Oct 28, 2019.

  1. BeeSmart

    BeeSmart

    Joined:
    Dec 6, 2013
    Posts:
    22
    Hi,

    Android/Google Play
    Unity 2019.2.10f1
    IAP 1.23

    I have several non-consumable IAPs buttons. These buttons are on a "store" scene within the app. From the main screen, the user would click the store button and the store scene will load.

    There are multiple non-consumable IAP buttons (no-ads, full access, access to different features, etc...). The initial purchase works fine. When I remove and re-install the app, the restore never seems to happen. I have placed a simple Text debug message in the BuyComplete to check this. All of the IAP buttons are active and interactive on load, my thought is maybe timing of the load and the callback to Google for the restore.

    Also, in the IAP Catalog the Automatically initialize UnityPurchasing is checked.

    I have stripped the IAPController down to its barebones to make sure there are no other conflicts.

    I even placed an active & enable IAP button offscreen on the main screen to see if I can get it to fire the BuyComplete function but it still does not.

    Any ideas what might be causing my issue?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Purchasing;
    6.  
    7. public class IAPController : MonoBehaviour
    8. {
    9.     public Text debugTxt;
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.      
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.      
    21.     }
    22.  
    23.     public void BuyComplete(Product product)
    24.     {
    25.         string msg = "Purchase Complete [" + product.definition.id + "]  Store Specific ID [" + product.definition.storeSpecificId + "]";      
    26.         MyDebug(msg);
    27.         //PurchaseActions(product.definition.id);
    28.  
    29.     }
    30.  
    31.  
    32.     public void BuyFailed(Product product, PurchaseFailureReason purchaseFailureReason)
    33.     {
    34.         string msg = product.definition.id + " " + "Purchase failed";    
    35.         MyDebug(msg);
    36.         //tbDebugMg.text = msg;      
    37.     }
    38.  
    39.     public void myListenerSucceed()
    40.     {
    41.         MyDebug("Listener Succeeded.");
    42.     }
    43.  
    44.     public void myListenerFail()
    45.     {
    46.         MyDebug("Listener Failed.");
    47.     }
    48.  
    49.     private void MyDebug(string debug)
    50.     {
    51.         //Debug.Log(debug);
    52.         debugTxt.text = debug;
    53.         DebugController.WriteToDebugFile(debug);
    54.         //tbDebugMg.text += "\r\n" + debug;
    55.  
    56.     }
    57.  
    58.  
    59. }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. BeeSmart

    BeeSmart

    Joined:
    Dec 6, 2013
    Posts:
    22
    Hi Jeff. I am not using a Listener during this test but I did previous and the restore still did not fire as expected. I will attempt the scripted approach. Using this approach how is the restore triggered on android? I assume manually but just asking.

    Regarding the logs, my tests are with built apk files loaded onto the device, so not sure how I would get the logs.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Restore happens automatically on reinstall on Android. You can expect ProcessPurchase to fire for each prior purchase.