Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

How to handle auto-renewable iOS subscriptions

Discussion in 'Unity IAP' started by GeorgeCH, Jan 7, 2019.

  1. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    201
    Hi there -

    I'm a bit confused about how to handle auto-renewable weekly subscriptions on iOS devices.

    Specifically, I've figured out how to detect the first instance of the subscription purchase; what I don't understand is what data I need to retain and how to subsequently capture auto-renewals.

    For example, let's day on Day 1 user successfully purchases a weekly subscription and receive their receipt. Do I then somehow need to reference that previous receipt on Day 8 to check whether the subscription associated with this receipt is still active? If yes, which part of the receipt (from the list below) needs to be referenced?

    Code (CSharp):
    1.     public class AppleInAppPurchaseReceipt : IPurchaseReceipt
    2.     {
    3.         public AppleInAppPurchaseReceipt();
    4.  
    5.         public int quantity { get; }
    6.         public string productID { get; }
    7.         public string transactionID { get; }
    8.         public string originalTransactionIdentifier { get; }
    9.         public DateTime purchaseDate { get; }
    10.         public DateTime originalPurchaseDate { get; }
    11.         public DateTime subscriptionExpirationDate { get; }
    12.         public DateTime cancellationDate { get; }
    13.         public int isFreeTrial { get; }
    14.         public int productType { get; }
    15.         public int isIntroductoryPricePeriod { get; }
    16.     }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,452
  3. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    201
    Hi Jeff -

    Thank you for replying, but let me try to better understand the specifics, as I have not seen them explained anywhere else, either in documentation or in other developers' examples.

    Exactly what happens if the subscription has expired and been auto-renewed? Assuming that I store the Day 1 receipt of the subscription somewhere and use it to validate the status of the subscription on Day 8, how can Unity tell whether it has been auto-renewed? Does it "phone home" to the appropriate app store (Apple or Google), get an updated receipt, update the local record accordingly, and, using the SubscriptionManager class, tells me whether it's been renewed (automatically or otherwise) or cancelled?

    Or does it treat any subscription that was marked as auto-renewing as, well, auto-renewed, irrespective of what the user actually did?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,452
    Expired and auto-renewed are mutually exclusive. A subscription cannot be both renewed (currently valid, paid for and available) and expired (product is not longer available). But your assumptions are basically correct. However I'm not clear on your last question. What behavior are you seeing in your testing?
     
  5. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    201
    Hi Jeff -

    I was assuming that, in determining the status of the subscription, Unity was relying solely on locally stored data and did not attempt to get the latest status of the subscription from the respective store - hence my hypothesizing on its treatment of auto-renewing subscriptions in the last paragraph.

    However, if I understood you correctly, the workflow is something like this:
    1. Unity IAP is initialized
    2. Unity loops through the list of stored receipts - it is the responsibility of the developer to ensure that these receipts are stored correctly
    3. If one of these receipts refers to a subscription, make use of the SubscriptionManager class which will always get the current status of the subscription from the respective app store.
    4. Apply whatever logic necessary based on the status of the subscription
    Does this sound about right? If so, what happens if there is no Internet connectivity?

    I have not started doing any testing quite yet (actually, I've been wondering what the best way of testing behaviors of expired/auto-renewed subscriptions would be, given that Apple has a minimum subscription duration of one week).
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,452
  7. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    201
    Thanks a lot, Jeff! I think I’m over-complicating things. So, I basically just need to initialise Unity IAP and the magic will happen, so to speak?

    Sounds awesome - and a lot easier than I thought.