iOS In-App purchasing and subscriptions : Testing - ios

A college of mine has implemented iOS in-app purchasing on a auto-renewing monthly basis. I am taking over the code base and want to test it is working. I know the purchasing is wokring but the auto-renewing is what I am worried about.
I have set up a test user and read the Apple documentation that says in sandbox mode, a month is 5 minutes in the sandbox.
However I am not getting any post back from Apple after 5 minutes? should I?
In the AppDelegate I have
inAppPurchase = [TFInAppPurchase new];
[[SKPaymentQueue defaultQueue] addTransactionObserver:inAppPurchase];
[inAppPurchase updateAvailableProductsCache];
I am expecting after 5 minutes, it to fire of a notification or something?

In the iTunes development guide, there's list of how long auto-renew subscriptions last in sandbox mode:
Sandbox Testing Your In-App Purchases
You are required to test your in-app purchases in a sandbox environment before you submit them for
review by Apple. You must first sign out of your iTunes Store account
from your test device Settings before attempting to use the sandbox
environment. If you mistakenly use your test-user-account credentials
to log in to a production environment on your test device (instead of
in to your test environment), your account credentials become invalid
and cannot be used as a test account again. For more details on how to
avoid mistakes during test account use, see “Using Test User
Accounts.”
When testing auto-renewable in-app purchase subscriptions in the
sandbox environment, the duration times will be compressed to allow
for more streamlined testing. Additionally, a sandbox subscription
will only auto-renew a maximum of 6 times. After the subscription has
auto-renewed 6 times, it will no longer renew in the sandbox. The
compressed duration times are as follows:
Actual duration Sandbox duration
1 week 3 minutes
1 month 5 minutes
2 months 10 minutes
3 months 15 minutes
6 months 30 minutes
1 year 1 hour

There is no notification. You keep track of it yourself (the duration). You get a receipt with the original transaction that you save. Use this to verify (perhaps on launch each time) that the user's subscription is still active.

No notification will be generated by apple.
You have to save the recipes on server or device by using nsuserdefaults or keychain.
you have to track the duration by yourself.By caluclating
Compare the product identifier in question to the product identifier of each in-app purchase receipt.
If there is a receipt that matches, validation succeeds. Otherwise, validation fails.
When validation succeeds, your application enables the purchased functionality—for example, by downloading content or adding features. When validation fails, your application simply does not enable the functionality.

Related

iOS Subscription: How to handle INTERACTIVE_RENEWAL notification 10 minutes after INITIAL_BUY?

My server received a INTERACTIVE_RENEWAL notification for a (unsupported) 6 month subscription from the iOS App Store just 10 minutes after it received INITIAL_BUY notification for a 3 months subscription.
How should I handle this?
The long story:
A month ago I have released a new version of my app introducing auto renewing subscriptions. I have created different subscription products, e.g.
com.my.app.subscripton.3months
com.my.app.subscripton.6months
com.my.app.subscripton.12months
The final version of the app which was released to the store only offers the 3 months and 12 months subscriptions. The 6 months subscription ID still exists in code but there is no UI element to purchases this subscription (double checked!)
My server now received the following App Store Update Notification messages within 10 minutes:
02:00 - INITIAL_BUY of product com.my.app.subscripton.3months. Expires on 2020-01-28 02:00:00
02:10 - INTERACTIVE_RENEWAL of product com.my.app.subscripton.6months. Expires on 2020-04-28 02:10:00
How should I handle this? Obviously it makes no sense, that a 3 month subscription is renewed after 10 Minutes...
According to the docs an INTERACTIVE_RENEWAL means:
Indicates the customer renewed a subscription interactively, either by using your app’s interface, or on the App Store in account settings. Make service available immediately.
Since the apps UI does not provide an option to purchase the 6 months subscription this has to be done by the account settings. But where do I find a purchase feature in the account settings?
Even if such a feature exists somewhere in the settings, how can a 3 month subscription renew with 6 months just after 10 minutes?
EDIT: The information from the notification is correct. I re-validated the receipt and the store replied with the latest receipt information which includes to IAP items (3 and 6 months subscriptions) purchased within 10 minutes.
So the information is correct but makes obviously no sense...
In the App Store subscription management page users will be able to see all of the product options for the Subscription Group that they're subscribed to (see image).
It's not uncommon for more savy iOS users to navigate to this page shortly after purchasing a subscription to see if there is a lower priced option available.
As far as handling these events, what you you trying to do exactly? All you really need to determine if someone is subscribed is the product_id and expiration_date. If possible you can log the entire event body somewhere (in case you need it later) then update your user record with whatever values you need from the event. These may be:
Access level (most apps have one access level e.g. "premium")
Product Id
Expiration date
Auto-renew status
With this setup the actual event type becomes irrelevant, you're just updating the fields you need with the values from the latest event.
It's Apphud again. We are using Apple Notifications just to trigger additional receipt validation.
How to handle in your case? Make receipt validation and check whether subscription is active.
These notifications only tell you that something has changed in user's receipt. You have to check manually what has changed and update user subscription status after receipt validation complete.
Here is more info about notifications: https://blog.apphud.com/subscriptions-notifications/

iOS Manage my Subscription with Sandbox Account

Background
I have an application that supports in-app purchase with Apple subscription (in particular auto-renewable plans).
Using the WWDC 2016 slides material, in the Manage Subscription page, (inside iTunes & App Store -> View my Apple ID), we have this:
in which the user is allowed to change the current subscription plan (and also to cancel it). So far, so good.
Case scenario
I would like to simulate the scenario of a user changing account (or cancelling the current subscription) from the Manage Subscriptions page.
My issue (and possible solutions)
Thus, I am now facing the issue of testing the reported scenario.
It seems to conflict with Sandbox Account for testing purposes. In particular: if I try to login with the sandbox Apple ID into the iTunes Store & App Store page, I of course receive the message: iTunes Account creation not allowed (as reported in this question).
The most straight-forward solution seems the one reported in this thread (shortly: let the subscription plan auto-renew for 5 times with 5 minutes period, after which we should receive the 21006 error). Anyway, I am not sure that it could be applied to this case, since it seems only including the cancel my subscription case.
Another thread comes directly from the apple forum (this thread) but: (1) something is strange, i.e. the iTunes account creation not allowed error seems not to appear when logging into iTunes with sandbox accounts - while it happens to me systematically) and (2) even after logging in, the subscriptions are reported not to be shown.
I expect that everything works using a real Apple ID, but this is something I don't really want to do.
Conclusion (?) and question
So, finally :), my question. Is there a way to test the reported case scenario (or an equivalent one) without using a real apple ID, thus without triggering a real transaction? I don't really want to believe that the current sandbox testing mechanism does not include it.
Thanks in avance to all!
An iTunesConnect Sandbox test user account can test auto-renewing subscriptions but that account cannot login to iTunes and utilize the Manage Subscriptions.
Only Option
The only option I have seen being utilized is to essentially get your app fully approved for the app store (do not auto-release). Once approved, use a promo code to download and live test the Manage Subscription scenarios. If it all checks out, release the app. (I cant seem to find the link for this but will add it here if I come across it.)
Other Notes Testing Auto-Renewing Subscriptions
Duration times are shortened when test your auto-renewable subscriptions. Additionally, test subscriptions only auto-renew a maximum of six times.
Reference Link
~Emphasis is mine
1 week = 3 minutes
1 month = 5 minutes
2 months = 10 minutes
3 months = 15 minutes
6 months = 30 minutes
1 year = 1 hour
This thread has a response posted from an Apple Developer in regards to this situation. Link

Auto-renewing subscription doesn't renew

When purchasing auto-renewable subscriptions in the AppStore sandbox, the subscriptions don't automatically renew and terminate after the first period.
I don't know why, but this was working before. What I do is run a cron every few minutes that revalidates the stored receipt and fetches the latest_receipt_info.expires_date_ms with the biggest timestamp value.
According to Apple's documentation 1 month subscriptions should renew 5 times every 5 minutes.
Is the sandbox just flaky or is this expected behavior?
Update
I created a new sandbox user and now it renews again correctly. What did I miss?
You can not reuse the same sandbox user after the ends of the 5 renewals periods, you will need to create a new one to test again. They can only used for one test cycle.

iOS Auto-Renewable Subscriptions with sandbox test account

I have changed my client's current non renewable subscription in app purchase to an auto-renewable one, and when I test it on my iPhone with a test sandbox account it shows the "" message and goes through successfully. I receive all the content I would normally get, but I noticed the amount of days that gets returned from the "daysRemainingOnSubscriptionForProductWithIdentifier: productIdentifier" increases by ~1400 every time i try to purchase it again. Also, it doesn't seem to show if it auto renews or not (6 months -> 30 minutes)... The subscriptions remain paid even when I close the app out and delete it. Is this all part of the sandbox testing and how it functions? Because the in app purchase is/was working fine, I just created a new auto-renewable in app purchase product in itunes connect and replaced the productID of the non renewing subscription with the new auto-renewable one in the .plist file. Does anyone have any experience with this?

IOS subscription end notification

I am looking to build a ios application that will use an auto-renewable subscription on a monthly biases. We will be using some VOIP features that we will be charged monthly for. My question is, how can we be notified when a user cancels a subscription in IOS, so that we can cancel the users VOIP telephone number with our provider.
You will need to verify the receipt the same way you do for regular In App Purchases, but obviously you will do this every time the subscription period expires. Check out the documentation on this, Verifying an Auto-renewable Subscription Receipt
So based on this, it appears you will need to setup your server to check for a valid subscription every month (cron job?). This will allow you to cancel the VOIP number in your system if the subscription is no longer valid. Your app would be responsible for verifying a subscription is still valid when it is opened or the user attempts to access features that require a subscription.
Updated For Comment
The sandbox is supposed to return expiration dates in the following scheme.
This is from page 164 of the iTunes Connect Developer Guide
If it is not working this way you may want to file a bug report.
Also, please not the following from Apples IAP doc:
Additionally, a sandbox subscription will only autorenew a maximum of 6 times. After the subscription has auto-renewed 6 times, it will no longer renew in the sandbox.

Resources