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. Dismiss Notice

Public Exceptions from UnityEngine.Purchasing.Security compile error

Discussion in 'Unity IAP' started by MonkeyDevD, Mar 15, 2021.

  1. MonkeyDevD

    MonkeyDevD

    Joined:
    Feb 28, 2018
    Posts:
    13
    We created an internal package that references the purchasing assemblies, to predefine code for our teams to use.

    We used to be able to access all the public exceptions and handle those in various ways.
    But the new 3.0 assemblies have moved the exceptions to a asmdef that does not compile for editor, removing these exceptions are causing compiler issues.
    This makes coding very cumbersome, as api changes will not be noticed until device builds are made.

    Referencing UnityEngine.Purchasing.SecurityStub results in the definitions still not being present.

    My workaround is adding this file to my code, so that I can just see and reference these exceptions.
    If we do update and encounter a build-issue later on, it's easy enough to update.
    But ideally this file will be obsolete in a future version.

    Code (CSharp):
    1. using UnityEngine.Purchasing.Security;
    2.  
    3. // In Unity Purchasing 3.0.1 these are not available in editor, so we use this as a workaround
    4. // below sourcecode is from com.unity.purchasing@3.0.1/Runtime/Security/CrossPlatformValidator.cs
    5. namespace UnityEngine.Purchasing.Security
    6. {
    7. #if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
    8.  
    9.     public class StoreNotSupportedException : IAPSecurityException
    10.     {
    11.         public StoreNotSupportedException(string message) : base(message)
    12.         {
    13.         }
    14.     }
    15.  
    16.     public class InvalidBundleIdException : IAPSecurityException
    17.     {
    18.     }
    19.  
    20.     public class InvalidReceiptDataException : IAPSecurityException
    21.     {
    22.     }
    23.  
    24.     public class MissingStoreSecretException : IAPSecurityException
    25.     {
    26.         public MissingStoreSecretException(string message) : base(message)
    27.         {
    28.         }
    29.     }
    30.  
    31.     public class InvalidPublicKeyException : IAPSecurityException
    32.     {
    33.         public InvalidPublicKeyException(string message) : base(message)
    34.         {
    35.         }
    36.     }
    37.  
    38.     public class GenericValidationException : IAPSecurityException
    39.     {
    40.         public GenericValidationException(string message) : base(message)
    41.         {
    42.         }
    43.     }
    44. #endif
    45. }
     
  2. MonkeyDevD

    MonkeyDevD

    Joined:
    Feb 28, 2018
    Posts:
    13
    How we use the exceptions:

    Code (CSharp):
    1.  
    2. try
    3. {
    4.    var validator = new CrossPlatformValidator(null, AppleTangle.Data(), Application.identifier);
    5.     var result = validator.Validate(product.receipt);
    6.     // do stuff with the result, additional check
    7.  
    8. }
    9. catch (InvalidBundleIdException)
    10. {
    11.     // InvalidBundle code
    12. }
    13. catch (MissingStoreSecretException)
    14. {
    15.     // MissingStoreSecret code
    16. }
    17. catch (IAPSecurityException)
    18. {
    19.     // IapSecurityException code
    20. }
     
    _geo__ likes this.
  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    We have heard similar reports. Can you provide a basic project, ideally start with an empty project and add the minimum code? Remove the /Library folder and send it to me directly.