Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In app auto-renewable subscriptions

Tags:

Sorry for the millionth question about iTunes subscriptions, but I still have a few doubts.

Basically I'm implementing auto-renewable subscriptions in my app and I want to make sure I got it right. Here's a list of steps to take that I came up with:

  • whenever an user buys a subscription, send the receipt to the server to validate it
    • if the receipt is valid, save it on the database
  • on application load, ask the server if a receipt for this UDID exists (this is to figure out if the user has a valid subscription)
    • if so, check if a new item has been added on the store in a date range from the subscription start date to the expire date
      • if any, notify the user about those items in some way and mark them as freely downloadable

Are these steps correct? And if so, why does the Apple doc say:

In most cases, your iOS client application should not need to change. In fact, your client application is now made simpler, as you can use the same code to recover auto-renewable subscriptions as you do to recover nonconsumable products. This is described in “Restoring Transactions.”Your application receives a separate transaction for each period of time where the subscription was renewed; your application should verify each receipt separately.

To me it looks like this needs some code to handle all the various cases I mentioned, instead. Or I'm totally wrong about it. Am I?

Plus, how do I know about the subscription expiration date? I can't find a way to get this information anywhere. Am I supposed to save this on my own database?

Update:

I've figured out a few things since I posted this question. Feel free to correct me if I'm wrong.

First of all I guess I'm supposed to store the length of the subscription somewhere on my own database, because as stated on Apple's docs, you cannot retrieve it in any way through Apple's web services. In fact, each subscription length has a different product identifier, so you should have a way to convert a product identifier to a subscription length.

Also, Sylvian has posted details about his implementation of auto-renewable subscriptions, so at least I know my thinking wasn't too much flawed.

Now the only problem is this: how do I know that an user has a valid subscription? I could store this information on my server, yeah, but how do I associate an user with a completed transaction? Should I save the device's UDID?

like image 445
ySgPjx Avatar asked Mar 16 '11 17:03

ySgPjx


People also ask

What is auto renewal subscription?

(also known as auto-renewal) Is a billing process where the customer's subscription is set to be renewed automatically at the end of their subscription period – weekly, monthly, annually or any other agreed-upon period of time – without the customer having to take action.

What is renewable subscription?

Subscription renewal is the process each customer goes through when continuing their subscription into the next billing cycle.


2 Answers

Here is how we implemented In App Purchases and specifically the new auto-renewable products at my company.

The application transmits the transaction receipt to our webservice, we return OK to the application if we handled it correctly and Apple could verify it. In that case we updated the user account (i.e. the database) to say "yes he has paid and his subscription is valid till the receipt expiration date".

After the OK for this webservice, the application reloads the account info through another webservice, and see there is a valid subscription. That was it... Until auto-renewable products appeared.

We now had to implement some CRON jobs which runs every day: every day we make a list of passes which are supposed to expire, and we ask Apple if the original receipt is still valid: the magic thing is that in their answer, there is a field latest-receipt which embeds the latest receipt. If it is not the same as the one we have, we understand that the subscription has been renewed automatically, we store the latest receipt for the next cron check, and we update the user account to extend the expiration date.

Hope it helps.

like image 51
Sylvain Avatar answered Sep 21 '22 17:09

Sylvain


I think I found a solution. It doesn't require an additional username/password and it seems to be working.

Note: If you think this is inappropriate, please explain why in the comments. Thanks.

Basically, whenever an user buys a subscription, I validate the receipt against my server and store the receipt data in the user defaults. Then, when the app is opened, or whenever I need to check if the subscription is still valid, I retrieve the previously saved receipt data from the user defaults and validate it against the server.

My webservice just returns whether the subscription is still valid or has expired, plus some other related information such as the subscription length. To do this, it just queries the iTunes server as usual, and checks if the status response is nonzero. 21006 means that the subscription has expired.

like image 31
ySgPjx Avatar answered Sep 23 '22 17:09

ySgPjx