Search Unity

How to validate a purchase receipt on Unity Distribution Portal?

Discussion in 'Unity IAP' started by ZenithGames, Jul 16, 2019.

  1. ZenithGames

    ZenithGames

    Joined:
    Mar 26, 2017
    Posts:
    8
    I have a code which validates purchases on Android & iOS:

    Code (CSharp):
    1.     bool validPurchase = true; // Presume valid
    2.  
    3.         // Unity IAP's validation logic is only included on these platforms.
    4.         #if (UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_OSX) && !UNITY_EDITOR
    5.  
    6.             // Prepare the validator with the secrets we prepared in the Editor
    7.             // obfuscation window.
    8.             var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    9.                 AppleTangle.Data(), Application.identifier);
    10.  
    11.             try {
    12.                 // On Google Play, result has a single product ID.
    13.                 // On Apple stores, receipts contain multiple products.
    14.                 var result = validator.Validate(args.purchasedProduct.receipt);
    15.                 // For informational purposes, we list the receipt(s)
    16.                 Debug.Log("Receipt is valid. Contents:");
    17.                
    18.                 foreach (IPurchaseReceipt productReceipt in result) {
    19.                    
    20.                     Debug.Log(productReceipt.productID);
    21.                     Debug.Log(productReceipt.purchaseDate);
    22.                     Debug.Log(productReceipt.transactionID);
    23.                 }
    24.             } catch (IAPSecurityException ex) {
    25.                 Debug.Log("Invalid receipt, not unlocking content: " + ex.Message);
    26.                 validPurchase = false;
    27.             }
    28.            
    29.         #endif
    But while testing on sandbox user on Distribution Portal, it throws an exception.
    What to do?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,944
    What is the exception?
     
  3. ZenithGames

    ZenithGames

    Joined:
    Mar 26, 2017
    Posts:
    8
    Hello. This is the exception message:

    Code (CSharp):
    1. Invalid receipt, not unlocking content: Store not supported: UDP
    The "Store not supported" is true, because the validator object takes only Google Play and Apple tangle data:

    Code (CSharp):
    1. var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    2.                 AppleTangle.Data(), Application.identifier);
    I was looking for a way to disable the validation on UDP, but I can't find any option to determine, if Target UDP is selected (from code).
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,944
    We are looking into this and will follow up here.