Search Unity

IAP Receipts Caching issue?

Discussion in 'Unity IAP' started by SevenAdmin, Jan 29, 2019.

  1. SevenAdmin

    SevenAdmin

    Joined:
    Jul 7, 2014
    Posts:
    7
    Howdy! I was wondering about a specific functionality of the unity/iOS subscription system;

    I'm parsing receipts in order to figure out if the user is supposed to still be subscribed and that works well, I take the latest subscriptionExpirationDate in the receipt and compare it to today's date.

    My issue is that if you leave the app opened while the date goes over that latest date. It seems like no matter what the user does, the receipt will never be refreshed and they wont be seen as subscribed to our app;

    For instance, if my auto-renewal date is the 23rd of each month and that I launch the game on the 20th and then leave it running until the 28th, when I come back to the app it won't see me as subscribed in-game. If I try to subscribe again, the apple popup will tell me that i'm already subscribed, but even Restore Purchase won't set me as 'subscribed', console outputs from the device shows that the latest expiration date is still on the 23rd of January, while it's really the 23rd of February now.

    Does this mean that once the IAP initialization is done, it won't fetch fresh IAP info from apple ever again? Would there be a way to force that refresh? Would calling RefreshAppReceipt() be enough to fix this issue?

    Thanks!
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I would never use date math to determine if a subscription is still valid. It's not common for a user to leave the app open that long, I would not engineer a solution around it!
     
  3. SevenAdmin

    SevenAdmin

    Joined:
    Jul 7, 2014
    Posts:
    7
    Do you mean that you would never use it at all?

    I thought that checking the dates like so

    Code (CSharp):
    1. DateTime expirationDate = apple.subscriptionExpirationDate;
    2.             DateTime now = DateTime.Now;
    3.             if(DateTime.Compare(now, expirationDate) < 0)
    4.             {
    5.                 isActive = true;
    6.             }
    Was somewhat the right way to do it. We've been doing it this way for a year+ now; If there's a better way I'm all ears.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Correct, I would not use date math (prone to errors, extra work, etc), but use the exposed properties in the SubscriptionManager class. But if it's working for you, then great!
     
  5. SevenAdmin

    SevenAdmin

    Joined:
    Jul 7, 2014
    Posts:
    7
    I guess to try and figure out my issue better; Even if you used another system (like the subscriptionmanager class) to verify if a user is subscribed, when do you call it? I do it once when the app launches, but then I'm not sure if I should ever check again at runtime.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    When the app launches. So if the subscription expires in the middle of game play, do you plan to yank the product from them at that time? Not very user friendly. How about let them finish their session, and check the next time they launch the game!