How to handle renewal of the auto-renewable subscriptions locally? - ios

I try to add auto-renewable subscriptions in my app, but not sure about the proper way to handle this.
What I'm having right now is
Add SKPaymentQueue.default().add(self) in app delegate.
Once user purchase I save expiration date and set timer to fire on that date.
If I get renew transaction, update expiration date and extended timer.
If user not renew timer will fired and update ui to reflect that change.
My question is if this a right approach? This approach seem to have a gap where a brief moment (when date expired and renew transaction not yet arrived), users are treat as free tier.
What is a better way to do this?

The app receipt contains a record of the user’s purchases, cryptographically signed by Apple. You can validate subscription receipt in two ways:
Locally/Unsafe: Perform receipt validation immediately after your application launched.
Remotely/Safe: Perform receipt validation at server end. Use trusted
server to connect with App Store.
For more information, see Receipt Validation Programming Guide.

Related

iOS auto-renewable subscriptions and restoreCompletedTransactions(): is the transaction removed from the queue after expiration or cancellation?

After a long search for an answer, I want to ask a very simple question here. Are transactions associated with a auto-renewable subscription removed after the expiration date from the list of transactions that can be obtained using the restoreCompletedTransactions() method?
In its simplest implementation, is it possible to manage application content associated with a auto-renewable subscription without using Validating Receipts? And using only the result of the restoreCompletedTransactions() method?
You have two questions here.
1) Are transactions associated with a auto-renewable subscription removed after the expiration date from the list of transactions that can be obtained using the restoreCompletedTransactions() method?
Answer:
No. Those entries will always remain there and when you validate the receipt, you will get it back in response. By Doing the Restore purchase won't delete the existing entries from receipt. When you testing the In app purchase with Sandbox account then you will have 35 mins to use that account within 8 Hours. You can do whatever you want. You can do subscription again(In this case system will say us that your subscription is still running). After 35 mins of first purchased, Plan will be considered as Cancel and you need to do Subscription again(Only in Sandbox mode, Well In production mode May be it will not ask to do subscription again? I am not sure here.)
2) Is it possible to manage application content associated with a auto-renewable subscription without using Validating Receipts
Answer: No. Its good to use the receipt validation for locking/unlocking content of your application.

iOS - how should i make sure the IAP receipt is valid

I want to offer a renewable subscription in my iOS application. The user subscribed and the receipt is stored. Now i wonder how i need to make sure that the receipt is valid and not cancelled:
If the user cancels the subscription and it is not renewed, how would i know it? If the subscription is renewed, when a new receipt will be created?
If the user cancels the subscription through apple support (because, for example, he bought it my mistake), how can i know it? The receipt on the device will be valid. Should i refresh the receipt every time the user logs in?
EDIT:
I forgot to mention it, but the receipt is checked in the client side.
Generally you need to check the expiration date of the subscription. To do that you need to get the receipt list and find the most recent record. It could be done using several ways (iOS Restore in App purchases with receipts)
If user cancels the subscription, I believe it means that receipt list simply will updated and you can find this by reading the 'cancellation date' field. To get track the expiration date I'd recommend to use UILocalNotification. If user continues to use subscription and you doubt whether he prolonged it or not, you should update the receipt list and send request to Apple [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]
If user cancel the subscription through apple support , you can find the corresponding record (aka "Cancellation Date") in the receipt data. Please read (https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html).
I'd recommend to check the receipt from time to time or use a notification mechanism.

How to update auto-renewable subscription receipt

I am trying to implement an auto-renewable subscription in an app, it works like this:
The user buys a subscription.
The app gets the receipt and sends it to my webService.
My webService verifies the receipt, changes the role of the user from Free to VIP and also records the receipt.
Now the question: When the expiration date comes, should I verify the receipt at my webService or in the app?
If it is on the webService, should I attempt to verify the old receipt (stored) and Apple returns to me the latest one if renewed or cancelled?
If it is on the app how should I proceed? Is there some kind of notification from storeKit when the subscription is renewed or cancelled?
If the right approach is the second (App), since my webService controls whether the role of the user is Free or VIP, every time a renewal happens I will have to send the latest receipt to my webService, so, it can manage the user's role properly. That's why I need to know how and when to get the latest receipt to send.
The more useful approach is the first one - through your web Service.
When you will attempt to verify the old receipt (stored) and Apple may respond in one of the following two ways:
If user has not cancelled the subscription, you will get the latest receipt with the expiration date extended.
If user has cancelled the subscription, you will get the receipt with the old expiration date only.
So based on the expiration date you can create your logic to whether extend the VIP membership or not.
Additionally, you can configure your authentication call on app side to re-authenticate user every 12 hours or 24 hours so you will get the updated membership status as well.

How do I verify IOS In-App Purchasing Receipts in Bulk?

I'm working on an iOS app that will use Apple's in-app purchasing framework to let the user create auto-renewing subscriptions.
I want my server to check periodically that none of the subscriptions have expired. Apple's Receipt Validation Programming Guide describes a verifyReceipt web service that appears to validate a single receipt.
However, if I want to bulk-verify my entire database every few days, is there a better way to do that than a storm of individual verifyReceipt calls?
You don't need to need to bulk-verify your entire database. A subscription is valid for a fixed duration. If the user cancels their subscription then this takes effect at the next renewal period, not immediately.
Apple customer service can refund a subscription if a user has a case (wrong product purchase is one example they give) but this would be a pretty low figure - and your app should also check for a valid subscription when it starts.
So you should only need to verify subscriptions that are known to be expiring "today".
To my knowledge there's no way to send multiple receipts in one bulk request to validate them in the iTunes servers... You have to send one by one. (Multiple requests)...
I don't know if how you are planing to solve this is the best approach. Apple has extended documentation on how to handle auto renewal subscriptions, most of the times you check the validity of the subscription in the app itself.
Check the in-app purchase documentation. It's a very good read if you plan to depend on in-app subscriptions for your business model:
https://developer.apple.com/library/ios/technotes/tn2259/_index.html

iOS 6 - How to validate in-app renewable subscriptions?

I am building an app that offers a 30-day subscription to premium services in the app.
I am familiar with in-app purchases (consumables) and have everything setup up for that. However, I haven't found any good tutorial or explanation of what the proper procedure for validating auto-renewable subscriptions.
Can anyone point me in the right direction?
What I would like to do is have the subscription setup like this:
User purchases in-app subscription and is verified
Subscription End-Date (30 days from purchase) is added to network database with user's account info
How to detect when the subscription is renewed so I can update the network database
UPDATE
So I have figured out the original purchasing and receipt verification, so all good on that. Then getting expired date by getting the value of 'expires_date' from the receipt data.
What I need to accomplish now is the best way to check for ALL completed transactions on app load (including any auto-renewed subscriptions) so I can unlock premium services. Using 'restoreCompletedTransactions' allows me to receive old receipt data, but it forces the user to enter a password, and I would like to avoid this. What are the alternatives?
a user purchases a product and you save the receipt. keep track of a timestamp so you know how long the subscription is valid for. on each launch you validate the receipt. you will always get the latest receipt so you know whether the product was renewed. using the timestamp you can make sure the user doesnt get access after their subscription has cancelled.

Resources