Search Unity

[Closed] How do I track auto-renewing subscriptions?

Discussion in 'Unity IAP' started by Deleted User, Jun 12, 2017.

Thread Status:
Not open for further replies.
  1. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Hello, I will post may answer for Android :
    The autoRenewing field seems to be a good marker to be sure that the subscription is ok or over. However you need to exit/launch the app in order to show the right result :)

    Code (CSharp):
    1.         foreach (Product p in m_StoreController.products.all) {
    2.             GooglePurchaseData data = new GooglePurchaseData(p.receipt);
    3.             if (p.hasReceipt)
    4.             {
    5.                 Debug.Log(data.json.autoRenewing);
    6.             }
    7.         }
     
  2. MorenoBralts

    MorenoBralts

    Joined:
    May 23, 2017
    Posts:
    19
    That wouldn't solve the issue where @anuragclancy was talking about. By checking the
    autoRenewing
    value you are just checking if the subscription will get renewed after a certain amount of time. What we want to check is whether the subscription period is still active or not, regardless if the user has
    autoRenwing
    .
    I'm facing exact the same issue he has and I can't really find a viable solution. If I may find one I will post it here.
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are working to improve subscription support, and you should see these improvements in a soon upcoming release! You'll see a boolean IsSubScriptionActive flag for this purpose.
     
    rattlesnake and Nananaaa like this.
  4. MorenoBralts

    MorenoBralts

    Joined:
    May 23, 2017
    Posts:
    19
    Thanks for the quick update! Very good news to hear, is there an ETA scheduled for this release?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No ETA at this time, but the coding is complete and is currently going through the QA and release process.
     
    Nananaaa and MorenoBralts like this.
  6. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    I've tried following the writings in this post, thank you for those. I'm implementing only iOS, an auto-renewing subscription. My problem is that to my understanding the system doesn't go through ProcessPurchase when the game start on iOS, so where would I get the receipt to check the expirationDate from? Thanks.
     
  7. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    Actually I do have more questions. I slightly modified the receipt validation, but ultimately this should do the same. However I don't understand how the m_receipt.expirationDate refers to the specific subscription in my game? I only have one subscription in the game, sure, but what if I had two? And in general, am I approaching the problem correctly at all? Thanks.

    Code (CSharp):
    1. private AppleReceipt m_receipt;
    2.  
    3.     private void ProcessSubscriptionPurchase()
    4.     {
    5.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    6.         // Get a reference to IAppleConfiguration during IAP initialization.
    7.         var appleConfig = builder.Configure<IAppleConfiguration>();
    8.         var receiptData = System.Convert.FromBase64String(appleConfig.appReceipt);
    9.  
    10.         m_receipt = new AppleValidator(AppleTangle.Data()).Validate(receiptData);      
    11.     }
    12.  
    13.     public static bool IsSubscriptionActive()
    14.     {
    15.         bool active = Instance.m_receipt.expirationDate > DateTime.Now.ToUniversalTime();
    16.         Debug.Log("Subscription state is " + active);
    17.  
    18.         return active;
    19.     }
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @Erikoinen I will try to get an update from the IAP team today with regard to improved subscription support. Since your game only has one subscription, your method should work for now.
     
  9. MorenoBralts

    MorenoBralts

    Joined:
    May 23, 2017
    Posts:
    19
    Any update on this?
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The hope is that subscription support will go into the next release or possibly the next, depending on the results of QA testing.
     
    VoodooAssets likes this.
  11. hm_assets

    hm_assets

    Joined:
    Sep 30, 2016
    Posts:
    6
    Any news about the support?
    Will it be in the 1.19 of Unity IAP, or in the new Unity update?
     
  12. kabur

    kabur

    Joined:
    Jan 23, 2016
    Posts:
    12
    I am testing subscription with latest plugin version 1.19. The restore purchase function freezes the app for 3 to 4 minutes in sandbox mode in the latest version. Is anyone else facing similar issue here.
     
    Last edited: May 28, 2018
  13. Denvery

    Denvery

    Joined:
    Mar 26, 2014
    Posts:
    17
    Hello, JeffDUnity3D!
    Please tell me what do you mean "product is dropped" in Google Play?
    I try to test subscription (with test purchases). I buy my test subscription (1 month = 5 min in test period), then I cancel my subscription. Unity gives me receipt with purchaseState = 0 and autorenewing = false for several hours after expiring. I wanna know that my product was expired, but I can't do it :(

    Thank you very much
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you using IAP 1.19 with Subscription support? Does it work as expected after several hours?
     
    Denvery likes this.
  15. Denvery

    Denvery

    Joined:
    Mar 26, 2014
    Posts:
    17
    Thank you for reply!
    How to get the version index of IAP in my project? :)
    After several hours (2-6 hours after expiring) - yes, it doesn't return receipts for expired subscriptions. But why I get receipts for expired subscriptions during this time after expiring?
     
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    Because Google Play caches product information + receipts as well, so it takes some time (up to one day) for you to actually receive the newest state of your products from their servers.

    Version 1.19 is the latest version. Just open your Services window > Unity IAP and see if it says "Up to date" there, or showing an update button.
     
    Denvery likes this.
  17. Denvery

    Denvery

    Joined:
    Mar 26, 2014
    Posts:
    17
    Thank you very much!
    Baroni, as I understood: Google Play removes info about my subscription from Play Store instantly, but caches our receipts on servers?
    I installed v.1.19 and got the same result.
    So, how can I get actual information about the subscription status in Unity app? only via Google Play Store API?
     
    Last edited: Jun 8, 2018
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Denvery and nicloay like this.
  19. Denvery

    Denvery

    Joined:
    Mar 26, 2014
    Posts:
    17
  20. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Denvery likes this.
Thread Status:
Not open for further replies.