Search Unity

How to track if the product purchased successfully or not using UNITY IAP

Discussion in 'Unity IAP' started by Deleted User, Sep 28, 2018.

  1. Deleted User

    Deleted User

    Guest

    Working on Unity IAP and implement the subscription
    Here is the code :

    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2.     {
    3.         // Or ... a subscription product has been purchased by this user.
    4.        if (String.Equals(args.purchasedProduct.definition.id, kProductIDSubscription, StringComparison.Ordinal))
    5.         {
    6.             StartCoroutine ("processingUserMembershipStatus");
    7.         }
    8.         // Or ... an unknown product has been purchased by this user. Fill in additional products here....
    9.    
    10.         return PurchaseProcessingResult.Complete;
    11.     }

    Everything works fine. But when I use Coroutine in "IF " condition in the above code error comes up.
    Any help would be much appreciated. Thanks in anticipation.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What is the exact syntax of the error that you are receiving?
     
  3. Deleted User

    Deleted User

    Guest

    Hi This is the error I'm getting
    MissingReferenceException: The object of type 'IAPManager' has been destroyed but you are still trying to access it.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you are likely trying to call into IAPManager on a different thread context. If you need a specific variable value, perhaps you could pass it as a parameter to processingUserMembershipStatus or similar? This is not specific to IAP, but looks to be in code that you have written. Without seeing your full code, it would be difficult to troubleshoot.
     
  5. Deleted User

    Deleted User

    Guest

    In coroutine I'm using simple code.
    Let me share my whole code.
    Code (CSharp):
    1.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2.     {
    3.      
    4.         if (String.Equals(args.purchasedProduct.definition.id, kProductIDSubscription, StringComparison.Ordinal))
    5.         {
    6.             StartCoroutine(testing());
    7.         }
    8.         return PurchaseProcessingResult.Complete;
    9.     }
    10.  
    11. IEnumerator testing() {
    12.         yield return new WaitForSeconds (1.0f);
    13.         Debug.Log ("Hello after 1s");
    14.         yield return new WaitForSeconds (1.0f);
    15.         Debug.Log ("Hello after 2nd");
    16.     }
    17.  
    18.  
     
  6. Deleted User

    Deleted User

    Guest

    Like
    "OnPurchaseFailed"

    Code (CSharp):
    1. public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    2.     {
    3.         // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing
    4.         // this reason with the user to guide their troubleshooting actions.
    5.         Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    6.     }
    is there any "OnPurchaseSuccess" callback or method
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  8. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi,
    Is your IAP class called 'IAPManager'?
    If you're attaching it to a GameObject, please make sure that you have called 'DontDestroyOnLoad(gameObject)'. Otherwise, the instance of 'IAPManager' would be destroyed after loading another scene.
     
  9. Deleted User

    Deleted User

    Guest

  10. Deleted User

    Deleted User

    Guest

    But in the code snippet that I have shared. I haven't load any other scene,
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So a Debug.Log statement just prior to the coroutine execution logs the message, but one immediately after does not? Where do you instantiate and persist IAPManager? I will test here with a simple coroutine such as yours also. The caller for "yield return.." might be out of scope or similar.
     
  12. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Could you please send us a reproducible project?
    Thank you.