Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

IAP Renewal Subscription Help

Discussion in 'Unity IAP' started by tamana, Aug 5, 2019.

  1. tamana

    tamana

    Joined:
    Mar 14, 2017
    Posts:
    1
    Hello, Im trying to implement subscription system on my project.
    Im now facing serious problem with SubscriptionManager

    Code (CSharp):
    1.  
    2.             bool validPurchase = true;
    3. #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
    4.             var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    5.                 AppleTangle.Data(), Application.identifier);
    6.  
    7.             try
    8.             {
    9.                 var result = validator.Validate(e.purchasedProduct.receipt);
    10.                 CheckIfPurchaseIsFirstTimePurchaseAsync(result, e.purchasedProduct);
    11.             }
    12.             catch (IAPSecurityException)
    13.             {
    14.                 Debug.Log("Invalid receipt, not unlocking content");
    15.                 validPurchase = false;
    16.             }
    17. #endif
    18.             if (validPurchase)
    19.             {
    20.                 return ProcessPurchase_WithID(e.purchasedProduct.definition.id);
    21.             }
    22.  
    23.             return PurchaseProcessingResult.Pending;
    the code above is the callback after an item was purchased.

    Code (CSharp):
    1. public GetsugakuInformation GetGetsugakuInformation(string storeID)
    2.         {
    3.             SwiftUtility.debugLog("----------------------------------------------");
    4.             string intro_json = string.Empty;
    5.             try
    6.             {
    7.                 if(m_AppleExtensions == null)
    8.                 {
    9.                     SwiftUtility.debugLog("appleExtension is null");
    10.                 }
    11.                 m_AppleExtensions = Extensions.GetExtension<IAppleExtensions>();
    12.                 Dictionary<string, string> introductory_info_dict = m_AppleExtensions.GetIntroductoryPriceDictionary();
    13.  
    14.                 var getsugaku = Array.Find(Controller.products.all, x => x.definition.type == ProductType.Subscription && x.definition.storeSpecificId == storeID);
    15.                 if (getsugaku == null)
    16.                 {
    17.                     SwiftUtility.debugLog("getsugaku is null");
    18.                 }
    19.  
    20.                 intro_json = (introductory_info_dict == null ||
    21.                     !introductory_info_dict.ContainsKey(getsugaku.definition.storeSpecificId)) ? null : introductory_info_dict[getsugaku.definition.storeSpecificId];
    22.                 SubscriptionManager p = new SubscriptionManager(getsugaku, intro_json);
    23.                 if (p == null)
    24.                 {
    25.                     SwiftUtility.debugLog("p is null");
    26.                 }
    27.                 SubscriptionInfo info = p.getSubscriptionInfo();
    28.  
    29.                 SwiftUtility.debugLog($"info.isSubscribed : {info.isSubscribed()}");
    30.                 SwiftUtility.debugLog($"info.isExpired : {info.isExpired()}");
    31.                 SwiftUtility.debugLog($"info.isCancelled : {info.isCancelled()}");
    32.                 SwiftUtility.debugLog($"info.isAutoRenewing : {info.isAutoRenewing()}");
    33.  
    34.                 var getsugakuInfo = new GetsugakuInformation(info.getProductId(), info.getPurchaseDate(), info.getExpireDate(),
    35.                     info.isSubscribed() == Result.True ? true : false,
    36.                     info.isExpired() == Result.True ? true : false,
    37.                     info.isCancelled() == Result.True ? true : false,
    38.                     info.isAutoRenewing() == Result.True ? true : false,
    39.                     info.getRemainingTime());
    40.  
    41.                 return getsugakuInfo;
    42.             }
    43.             catch (Exception e)
    44.             {
    45.  
    46. #if UNITY_ANDROID
    47.                 Debug.Log($"Exception : {e.Message}");
    48. #elif UNITY_IOS
    49.                 SwiftUtility.debugLog($"intro_json : {intro_json}");
    50.                 SwiftUtility.debugLog($"Exception : {e.Message}");
    51.                 SwiftUtility.debugLog($"StackTrace : {e.StackTrace}");
    52. #endif
    53.             }
    54.  
    55.             return GetsugakuInformation.Empty;
    56.         }
    I used the code above to look information from SubscriptionManager class.
    After 5 minutes passed since last purchased,
    isSubscribed became false from true.
    isAutoReneweing became false from true.
    isExpired became true after false.

    The problem is subscription item became null after 5 minutes passed.
    And SubscriptionManager unable to execute getSubscriptionInfo() method after receipt became null

    Question is why the subscribed item wasn't renewed after 5 minutes passed?
    Shouldn't it get renew up to 6 times according to apple documentation?
    Please help me...
     
    Last edited: Aug 5, 2019
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,855
    Is this an auto-renew subscription? I suspect that auto-renew may not be available in Sandbox. The fast expire times are expected during testing.
     
  3. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    254
    Hi I'm using subscription, how I can detect if the subscription was newly renewed?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,855
    @domdev I believe you'll get a ProcessPurchase callback upon renew. You can also check the receipt fields.
     
  5. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    254
    yes but I wanna get the trigger where user subscription was renewed..
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,855
    Yes, that was my suggestion. You will get the trigger when IAP is initialized, there is no callback during a running game, if that is what you are asking. So if a subscription was renewed at midnight on the Play Store, the next time the user launches your app in the morning, they would receive this.