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

Bug with subscription in IAP version 2.2.5

Discussion in 'Unity IAP' started by OneGame-Studio, Jan 14, 2021.

  1. OneGame-Studio

    OneGame-Studio

    Joined:
    Dec 5, 2016
    Posts:
    13
    Google Play/Android does not recognize an active subscription when the app is relaunched. This means that users are not getting the features they are paying for. Very critical. Seem to when relaunch app after buy subscription , unity read receipt and return error : "The product receipt does not contain enough information, the 'developerPayload' field is missing". I used license test account to make test order.
    My code is work normally for other game that use version 1.23. This game use version 2.2.5 and get this bug :( .

    Currently using version 2.2.5.
     

    Attached Files:

    ex-nihilio likes this.
  2. OneGame-Studio

    OneGame-Studio

    Joined:
    Dec 5, 2016
    Posts:
    13
    I solved this problem. I don't use the private variable bool checkIfProductIsAvailableForSubscriptionManager anymore. But the feeling that it is still not really good. It's just that everything is working properly.
     
  3. ex-nihilio

    ex-nihilio

    Joined:
    Jan 23, 2015
    Posts:
    12
    Same problem with me.

    Are you using "developerPayload" string in the InitiatePurchase function?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    developerPayload is no longer supported by the stores. We will need to check if SubscriptionManager is still using/expecting this field. You can certainly parse the receipt yourself in the meantime.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I'm not seeing this behavior, the SubscriptionManager is working for me as expected when using IAP 2.2.5. I first purchase a subscription, then restart the app. During IAP initialize, I'm checking the product receipts with SubscriptionManager, and don't see any exception. I'm using the Sample IAP Project here https://forum.unity.com/threads/sample-iap-project.529555/ As the message states, it only works for those subscriptions purchased via IAP 1.19+
     
  6. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    78
    We are having this issue too.
    I tried importing the plugin into a fresh project, and this code exists in IAPDemo.cs:

    Code (CSharp):
    1. var original_json_payload_wrapper = (Dictionary<string, object>)MiniJson.JsonDecode((string)payload_wrapper["json"]);
    2.                     if (original_json_payload_wrapper == null || !original_json_payload_wrapper.ContainsKey("developerPayload")) {
    3.                         Debug.Log("The product receipt does not contain enough information, the 'developerPayload' field is missing");
    4.                         return false;
    5.                     }
    If developerPayload is no longer supported, it should be removed from the demo code.
    I'm going to remove this from our code.

    And maybe you didn't get an error, because your code doesn't depend on correct behaviour of
    checkIfProductIsAvailableForSubscriptionManager()
    ?
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, it appears that we need to update IAPDemo. Please share the code that is causing your error.
     
  8. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    82
    The current IAP demo still has the 'developer payload'. Will this be updated?
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The IAP demo will be removed in the next release. You will want to use the included Samples now, or the Sample IAP Project here on the IAP forum
     
  10. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    82
    Thank you!
     
  11. chenjiechao666

    chenjiechao666

    Joined:
    Jun 12, 2023
    Posts:
    4
    Yes I also encountered the same problem, display "The product receipt does not contain enough information, the 'developerPayload' field is missing"
     
  12. chenjiechao666

    chenjiechao666

    Joined:
    Jun 12, 2023
    Posts:
    4
    I found the answer in the case of IAP

    Code (CSharp):
    1.    
    2. using System;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.Purchasing;
    6. using UnityEngine.UI;
    7.  
    8. public class BuyingSubscription : MonoBehaviour, IStoreListener
    9.     {
    10.         IStoreController m_StoreController;
    11.  
    12.         // Your subscription ID. It should match the id of your subscription in your store.
    13.         public string subscriptionProductId = "com.mycompany.mygame.my_vip_pass_subscription";
    14.  
    15.         public Text isSubscribedText;
    16.  
    17.         void Start( )
    18.         {
    19.             InitializePurchasing( );
    20.         }
    21.  
    22.         void InitializePurchasing( )
    23.         {
    24.             var builder = ConfigurationBuilder.Instance( StandardPurchasingModule.Instance( ) );
    25.  
    26.             // Add our purchasable product and indicate its type.
    27.             builder.AddProduct( subscriptionProductId, ProductType.Subscription );
    28.  
    29.             UnityPurchasing.Initialize( this, builder );
    30.         }
    31.  
    32.         public void BuySubscription( )
    33.         {
    34.             m_StoreController.InitiatePurchase( subscriptionProductId );
    35.         }
    36.  
    37.         public void OnInitialized( IStoreController controller, IExtensionProvider extensions )
    38.         {
    39.             Debug.Log( "In-App Purchasing successfully initialized" );
    40.             m_StoreController = controller;
    41.  
    42.             UpdateUI( );
    43.         }
    44.  
    45.         public void OnInitializeFailed( InitializationFailureReason error )
    46.         {
    47.             Debug.Log( $"In-App Purchasing initialize failed: {error}" );
    48.         }
    49.  
    50.         public PurchaseProcessingResult ProcessPurchase( PurchaseEventArgs args )
    51.         {
    52.             // Retrieve the purchased product
    53.             var product = args.purchasedProduct;
    54.  
    55.             Debug.Log( $"Purchase Complete - Product: {product.definition.id}" );
    56.  
    57.             UpdateUI( );
    58.  
    59.             // We return Complete, informing IAP that the processing on our side is done and the transaction can be closed.
    60.             return PurchaseProcessingResult.Complete;
    61.         }
    62.  
    63.         public void OnPurchaseFailed( Product product, PurchaseFailureReason failureReason )
    64.         {
    65.             Debug.Log( $"Purchase failed - Product: '{product.definition.id}', PurchaseFailureReason: {failureReason}" );
    66.         }
    67.  
    68.         bool IsSubscribedTo( Product subscription )
    69.         {
    70.             // If the product doesn't have a receipt, then it wasn't purchased and the user is therefore not subscribed.
    71.             if ( subscription.receipt == null )
    72.             {
    73.                 return false;
    74.             }
    75.  
    76.             //The intro_json parameter is optional and is only used for the App Store to get introductory information.
    77.             var subscriptionManager = new SubscriptionManager( subscription, null );
    78.  
    79.             // The SubscriptionInfo contains all of the information about the subscription.
    80.             // Find out more: https://docs.unity3d.com/Packages/com.unity.purchasing@3.1/manual/UnityIAPSubscriptionProducts.html
    81.             var info = subscriptionManager.getSubscriptionInfo( );
    82.  
    83.             return info.isSubscribed( ) == Result.True;
    84.         }
    85.  
    86.         void UpdateUI( )
    87.         {
    88.             var subscriptionProduct = m_StoreController.products.WithID( subscriptionProductId );
    89.  
    90.             try
    91.             {
    92.                 var isSubscribed = IsSubscribedTo( subscriptionProduct );
    93.                 isSubscribedText.text = isSubscribed ? "You are subscribed" : "You are not subscribed";
    94.             }
    95.             catch ( StoreSubscriptionInfoNotSupportedException )
    96.             {
    97.                 var receipt = ( Dictionary<string, object> ) MiniJson.JsonDecode( subscriptionProduct.receipt );
    98.                 var store = receipt[ "Store" ];
    99.                 isSubscribedText.text =
    100.                     "Couldn't retrieve subscription information because your current store is not supported.\n" +
    101.                     $"Your store: \"{store}\"\n\n" +
    102.                     "You must use the App Store, Google Play Store or Amazon Store to be able to retrieve subscription information.\n\n" +
    103.                     "For more information, see README.md";
    104.             }
    105.             catch ( Exception e )
    106.             {
    107.                 Debug.LogWarning( e );
    108.             }
    109.         }
    110.     }