I'm testing autorenewable subscriptions and wanted to understand the logic behind renewals as the sandbox behaviour seems to act differently to the documentation in terms of renewing before the expiration date.
According to the 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 iap receipt to apple and checking the response to see if there is a new iap with an expiry date in the future. If there is not and the current 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 shortly before in sandbox env).
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. 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 an extra day? According to the documentation I should be fine assuming that the subscription renewal happens in the previous 24 hours prior to expiration but the behaviour here says otherwise.