Search code examples
iosin-app-purchasesubscriptionauto-renewable

Autorenewable subscription IAP renewing after expiry date in sandbox


According to Apple's documentation...

During the 24-hour period before the subscription expires, the App Store starts trying to automatically renew it. The App Store makes several attempts to automatically renew the subscription over a period of time but eventually stops if there are too many failed attempts.

I run a script that determines if a subscription has expired by sending the receipt to apple and then checking the response to see if it has renewed. If it has not and the current subscription expiry date is before the time I'm running the script I take it as an expired subscription as I am assuming it would have been updated in the previous 24 hours (or the equivalent of shortly before in sandbox environment).

On the sandbox I'm seeing behaviour where the subscription can be renewed after the expiry date - I mark it as expired and then in a future run there is a renewal in the response.

E.g. A subscription has an expiration date of "2017-02-08T15:32:41Z" so I would expect apple to show a renewal before this time. However it doesn't so I mark as expired. On the next run of the script a renewal appears with an expiration date of "2017-02-08T15:39:55Z" which is over 7 minutes after the previous expiration date, which shows that the renewal occurred 2 minutes after the previous expiration date (accounting for the 5 minute subscription length in sandbox). There's many examples of this happening.

My question is how should I account for this behaviour in production? Does it happen? Should I be acting as though the subscription has expired, seeing as the expiration date has passed? Or should I allow more time as the sandbox behaviour contradicts the documentation.


Solution

  • Answering my own question. From the documentation...

    Renewal happens at an accelerated rate, and auto-renewable subscriptions renew a maximum of six times per day. This lets you test how your app handles a subscription renewal, a subscription lapse, and a subscription history that includes gaps.

    Because of the accelerated expiration and renewal rate, the subscription can expire before the system starts trying to renew the subscription, leaving a small lapse in the subscription period. Such lapses are also possible in production for a variety of reasons—make sure your app handles them correctly.