Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved not all code paths return a value in IAPManager.ProcessPurchase(PurchaseEventArgs)':

Discussion in 'Scripting' started by pKallv, Sep 18, 2020.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,177
    I just can't figure out where the problem is. I have two versions of the function "PurchaseProcessingResult" (IAP) and one works and the other one (newer) report the following error:

    on the following line:
    ...on the "ProcessPurchase" keyword in the title.

    To try to isolate the problem I did replaced one function at the time until I got the error when I replaced this function.

    The code(s) is a bit messy as I am in test mode.

    New code that report error: "not all code path returns a value":
    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    2.     {
    3.         MyDebug("PurchaseProcessingResult");
    4.  
    5.         bool validPurchase = true; // Presume valid for platforms with no R.V.
    6.  
    7.         // Unity IAP's validation logic is only included on these platforms.
    8. #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
    9.         // Prepare the validator with the secrets we prepared in the Editor
    10.         // obfuscation window.
    11.         var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    12.             AppleTangle.Data(), Application.identifier);
    13.  
    14.         try
    15.         {
    16.             // On Google Play, result has a single product ID.
    17.             // On Apple stores, receipts contain multiple products.
    18.             var result = validator.Validate(e.purchasedProduct.receipt);
    19.  
    20.         }
    21.         catch (IAPSecurityException)
    22.         {
    23.             MyDebug(">> Invalid receipt, not unlocking content");
    24.             _lang.InfoPanel(10);
    25.  
    26.             validPurchase = false;
    27.         }
    28. #endif
    29.  
    30.         if (validPurchase)
    31.         {
    32.             MyDebug(">> validPurchase");
    33.  
    34.             if (purchaseBtn)    // Purchase button is pressed when process this = not restore @ init
    35.             {
    36.                 MyDebug("Valid Purchase done");
    37.                 PlayerPrefs.SetString("SkipAd", "TRUE");
    38.                 _but.ManagePurchaseButton(false);
    39.                 _but.ManageRestoreButton(false);
    40.             }
    41.  
    42.  
    43.             //#if UNITY_EDITOR
    44.             //            PlayerPrefs.SetString("SkipAd", "TRUE");
    45.             //            Invoke("DoTheGobackEqTrue", 1f);
    46.             //#else
    47.             Invoke("DoTheGobackEqTrue", 0f);
    48.             //#endif
    49.  
    50.             return PurchaseProcessingResult.Complete;
    51.         }
    52.     }
    The version that works:
    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    2.     {
    3.         MyDebug("PurchaseProcessingResult");
    4.  
    5.         bool validPurchase = true; // Presume valid for platforms with no R.V.
    6.  
    7.         // Unity IAP's validation logic is only included on these platforms.
    8. #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
    9.         // Prepare the validator with the secrets we prepared in the Editor
    10.         // obfuscation window.
    11.         var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    12.             AppleTangle.Data(), Application.identifier);
    13.  
    14.         try
    15.         {
    16.             // On Google Play, result has a single product ID.
    17.             // On Apple stores, receipts contain multiple products.
    18.             var result = validator.Validate(e.purchasedProduct.receipt);
    19.  
    20.         }
    21.         catch (IAPSecurityException)
    22.         {
    23.             MyDebug(">> Invalid receipt, not unlocking content");
    24.             _lang.InfoPanel(10);
    25.  
    26.             validPurchase = false;
    27.         }
    28. #endif
    29.  
    30.         if (validPurchase)
    31.         {
    32.             MyDebug(">> validPurchase");
    33.             // Unlock the appropriate content here.
    34.             if (purchaseBtn)
    35.             {
    36.                 MyDebug("2) Set SkipAdd = TRUE");
    37.                 PlayerPrefs.SetString("SkipAd", "TRUE");
    38.                 _but.ManagePurchaseButton(false);
    39.                 _but.ManageRestoreButton(false);
    40.                 purchaseBtn = false;
    41.             }
    42.             else
    43.             {
    44.                 _but.ManagePurchaseButton(false);
    45.                 _but.ManageRestoreButton(true);
    46.             }
    47.  
    48.         }
    49.         else
    50.         {
    51.             //_lang.InfoPanel(9);
    52.             MyDebug("3) Set SkipAdd = FALSE");
    53.             PlayerPrefs.SetString("SkipAd", "FALSE");
    54.         }
    55.  
    56.         //#if UNITY_EDITOR
    57.         //        PlayerPrefs.SetString("SkipAd", "TRUE");
    58.         //        Invoke("DoTheGobackEqTrue", 1f);
    59.         //#else
    60.         Invoke("DoTheGobackEqTrue", 0f);
    61.         //#endif
    62.  
    63.  
    64.  
    65.         return PurchaseProcessingResult.Complete;
    66.     }
     
  2. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,177
    Solved: I had put
    Code (CSharp):
    1. return PurchaseProcessingResult.Complete;
    inside the
    Code (CSharp):
    1. if (validPurchase)
    This post can be removed.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    Always best to leave it in case someone else can learn from it. Glad to see you're operational again!
     
    pKallv likes this.
  4. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,177
    tx