In App Purchase is a great tool for sales setup if you offer additional functionality or features to your iPhone application. But it’s not that easy to get the job done…
Here are some key tips for working with In App Purchase that will help you to add your products to the AppSore.

In App Purchase Process

The connection with the AppStore is carried out through StoreKit.framework that is delivered with SDK starting from the 3.0 version. The core steps of the process are the following:

• the developer using itunesconnect.apple.com creates some virtual product with a name, description and price
• the application connects to the AppStore and purchases the virtual product
• the application makes required changes or/and does certain actions (unlocks particular levels, makes a sound, enables monthly subscription for access to the information storage, magazine archive, etc. )

Purchased Product Types in the In App Purchase

There are three types of the products you can create:

• Consumable
• Non-Consumable
• Subscription

Consumable. According to the type name the product can be purchased several times. For example, arrows or bullets for a game. Non-Consumable. Purchase can be done only once. This type of the purchase is used to unlock new themes, additional levels and so on. Subscription. Subscription to any kind of service. This type can be used for a web service app to purchase monthly premium account. Product of this type must be supported by different devices (iPhones/ iPads) and user can make entry using one account.

Note! StoreKit.framework offers tools to get transactions history, but the history will contain only the Non-consumable products transactions. For other types of products you should create or use other server to store this information.

Model of Server – Application Interaction in In App Purchase

A model of the server interaction can be described in the next 8 main steps:

• The application requests the list of the products from your server
• The app displays the list of the new products to the user
• The user either purchases the product or doesn’t buy it
• The app requests the purchase from the Apple’s server using StoreKit
• StoreKit sends the answer as a transaction
• iPhone application sends to its server a so-called receipt
• Application’s server validates the receipt on the Apple’s server
• The iPhone app downloads the product from its server

Pitfalls in Choosing Purchase Types in the In App Purchase

Apple is rather strict about the purchase type you’re using for the application.

If the developer has an intention to create monthly subscription for current updates (let’s say to get new jokes from the web), but has no desire to implement the support for the range of devices, then he can’t use this purchase type. The Subscription type forces you to implement the support of many devices though Apple doesn’t provide any tools to facilitate this part of development.

The Consumable type seems to be a simple decision to make in such a situation: it doesn’t require devices support and it’s easy to use. BUT: when trying to get project approval from Apple you’ll face the rejection as Purchase doesn’t corresponds application’s logic and confuses the user. Thus, if there is any hint on Subscription logic (or Apple can see it) the developer is forced to implement all the necessary features (Aha!).
The uncertain regulation provided by Apple is the pitfall for the developers who are trying to estimate the application with In App Purchase, but have never had a deal with it before.

The best way out is to follow the implementation model provided by Apple. If it’s said in Apple’s docs “We recommend you to …” you should read “Implement the application this way only… or else…”

In App Purchase Sample Code and Implementation

Here is an example of the In App Purchase implementation structure for a simple case

Pic. 1. Architecture of the Update Unit

Here we have an application that has one product of the subscription type that gives you the opportunity to update twice a month. The application is free but has no trial period. Instead of the trial period the app has some firmware that let you use the app without purchasing the updates subscription.

Updater is a class which task is to download and setup updates for the application. Before each update it checks for the updates permission. To perform this the Updater refers to the Local Storage.

Local Storage is an abstract and optional unit that stores information about subscription starting and expiry dates (preferably codified) on a local basis. Local Storage is made to save some traffic and secure the situation when the billing server is unavailable.

If the Local Storage has no information the Updater decides the app can be reinstalled and refers to AccountManager. AccountManager returns all the required information or starts the registration or log in process.

When the date information is obtained the confirmation is carried on. If the subscription isn’t expired the update is performed otherwise the request to InAppPurchaseManager takes place. The update purchase is offered to user. Then using storeKit.framework tools the InAppPurchaseManager carries on the transaction and returns the result to Updater. The Updater sends the receipt to BillingServer to validate it. After successful validation Updater gets a new subscription date, saves it to Local Storage and updates the information.

We can’t put here all the listings of the LocalStorage and AccountManager as the their code will require dozens of pages. But we give you In App Purchase sample code from the real project where it was called InAppPurchaseController.

Before the payment transaction is added to the queue it’s necessary to check whether it can be done at the moment. Which is implemented by the call of the canMakePayments method from the class SKPaymentQueue.

Creating the Purchase Product and Test User in iTunes Connect

You should enter ‘Manage Your In App Purchases->Create New’ in iTunes Connect then choose the required application.

Choose Bundle ID and fill in the information about the Purchase (type, name, price, etc.). You should define ‘Product ID’ that can be of any kind but we advise you to use Reverse DNS. The best name for Product ID is the combination of the Bundle ID of your app and the feature’s name.

To test the In-App Purchases you should have at least one Test User. Go to ‘Manage Users->In App Purchase Test User’ and choose ‘Add New User’. Fill in the information about the user. Test User e-mail doesn’t have to be real.

That’s all. Wish you successful testing!

Hope this information was useful for you. If you’ve got any questions about In App Purchase or about Objective C programming leave it as a reply and we’ll answer it as soon as possible.

Hi,
Glad you liked the post. I checked the code for copy/pasting and found out there was a problem with one peace of code (inAppPurchaseController interface). I’ve fixed it and now it’s pasting correctly.

Hi, Vimlesh.
You may use the product type “non consumable” for a single time purchase. You may develop your In App Purchase functionality without server-side because you can restore the transaction history for this product type.

your tutorial was very useful to me and understand more about IAP implementation. Can you tell me how to integrate our own server for product purchase. Because i need to fetch the books from my own server and shown to user. Can you please tell me the idea behind it.? then one more question is that transaction receipt and acknowledgement for payment is handled by storekit app delegate or we need to write code for server side maintaining this history? am going to implement non-consumable type only..

Here I’m stuck with the problem whether I should chooses subscription as the product type or consumable. I implemented everything so that a consumable is treated as if it was a subscription… But I’m afraid Apple won’t like that…

My question is, does apple handle anything related to the time of a subsciption ? If I present an user the buy dialog a second time, lets say 30 days later, the purchase framework says that the product was already purchased before…. In that case I have no clue if the user was billed or not. He should have been since I want the subscription to expire after 30 days… But how can I be sure ?

Hi Alexander.
We don’t recommend you to choose product type “consumable” to use it as “subscription”. You are quite right that Apple will reject your application in this case.

Unfortunately using purchase product type “subscription” obliges developer to implement some features (for example, provide a subscription support from a few user’s devices). Plus Apple does’t store the transaction history for this type of product, so you need to implement a server side where subscription parameters will be stored (that would be additional work for you).

Hi, I have my 9 comic book binaries uploaded to Apple Store already but they require me (last night) to consolidate them all into a single In-Apps Application then ready for Sale.
Do you have services to help create an In-App application for comic book purchases? It will simply be similar to all other comic book reader out there. Purchase and download a copy.

You don’t need to use any special services. We think you should write a single app, that may read any comic book (in your
own format), and the books’ sales will be made via in app purchase. It’s the implementation task for developer but not the task for services.

In other words, can I release an app (free or paid) that has the ability to upgrade its features for free within the in-app store. This would allow be to release the app in a minimal, small size state and then let the users pull down the large data as they want it without paying for it.

Hi, Zack!
In the In App Purchase you can’t have the price which value is “free” because it is the billing system only.
The In App Purchase product is virtual thing that doesn’t allow to store some application data inside it. It only allows to keep the data about the payments, dates of transaction and other required details.

Your application makes payment transaction via In-App-Purchase. When transaction is finished successfully application obtains transaction receipt. Then application sends that receipt to its server side and server validates the transaction. If the validation is successfull server returns this information to application and enables it to download some song or image.

Actually App store was rejected my Application , now that application is not there in App store , But i want to download that rejected Application… It is Possible through In-App purchase??? Possible means how??? I don’t want to download full application, i just want to download contents(Songs , Images ) of the rejected Application!!!!

Hi,Suresh.
As was described above In App Purchase product is virtual thing that must provide one thing – fact of a payment. All logic that provides downloading content or other behavior is implemented by the developer only. So you can’t buy rejected application or any part of it through In App purchase because you can’t implement this by programming.
Moreover you can’t implement it in any way. If you want to download rejected application contact Apple and ask them to send binary to your email.

thanks for the tutorial and code samples. I’m just getting started with in-app purchase (non-consumable, no server) and was wondering if you had some examples (code) on how to use this class. For example, would you just set the product id from the calling class? Do you need to run anything in the background?

I have been wondering: Can I sell the same product in 2 different apps? Like if I have an iPad version and an iPhone version, which are different applications in the store, can I sell the same product in both, so that users need to pay only once?

Hello, Christina
You can’t sell the same product in two different apps as there would be only one product. But you may handle this case in your applications server side and users will pay only once. Let’s say server will check if the user has purchased the product for one app and if the it’s positive then it will provide free access to the product for another app.

I am using subscription modal for IAP, I am stuck at the the following point:

“Subscriptions must be provided on all devices associated with a user. In App Purchase expects subscriptions to be delivered through an external server that you provide. You must provide the infrastructure to deliver subscriptions to multiple devices.”

Well, the server side structure depends on concrete application’s specification. Its behavour is not sctictly determined and might be of any kind depending on the app’s purposes and developer’s approach.
So it’s up to you how you will implement the server side support of different devices but you must provide it for the Subscription Purchase to get approval from Apple.

But Question is here, How we can identify which Devices are attached with same iTunes User ?

We are using “restoreCompletedTransactions” method listed in SKPaymentQueue for Restore process on user interaction. But Apple rejected app with saying “Subscriptions must be provided on all devices associated with a user”.

Now I see your point.
The deal is that “restoreCompletedTransactions” isn’t supported by Apple for product type “subscription”. Thus subscriptions are not to be provided on all devices.
In such a case in your server-side you associate user with his own login and password, not with the iTunes account of the user.

Yes, you are right.
That’s what Apple says about this: “In App Purchase expects subscriptions to be delivered through an external server that you provide. You must provide the infrastructure to deliver subscriptions to multiple devices.”

Thanks for the fast reply. Let me make clear the first question and also one more.

First Question:

Suppose I have to write a subscription logic (an in-app to be subscribed for a year or month so..) on my server side. Then I should have any of the user information such as user email id, user device id or any information related to the user.

Now I would like to know which such information of the user would be appropriate.

If I take the UDID, the subscription would be restricted to only one device. But as the subscription type of product for in-App purchase says to be supported for 5 devices (as per DRM).

If I ask the user email id and store it in the user defaults , I just doubt whether its a correct way to implement the in-App purchase.

Second Question:
Can we make the Consumable app (which are required to be purchased on every click of the feature to be used), as subscription for a particular limit of time. For eg. if I create a consumable app(in iTunes connect) say video feature(as NDTV app have) and by taking the user email id as a base(user info) and write the logic on the server, such that it can be used only for a year or so..limited time.

You may use any information such as e-mail or login-password to identify user in your database. It must be the information that user can input by himself. You may use UUID as additional information in your database (if you want to prohibit user to register multiple times from one device for example).

To the second question:

If Apple will suggest that your product looks like subscription but application uses consumable product your application will be rejected. Apple will suggest it if there is any hint of the Subscription type and we believe the time limit is one of them.

I have one question. I have a free app which includes an iAd banner and I want to use the in app purchase to allow the user to remove this banner. Everything is OK when the user pays for the in app purchase the first time. I save this information with NSUserDefaults to know if I hide or not the iAd banner. But if the app is removed from the phone, I don’t get it which functions to call to know if the product has already been purchased or not. I hope I was clear, thanks for your help.

Hi All,
I need a help here, i am done with the all the steps above now i am not able to understand how and from where do i need to upload the binary.. is it from “Manage Your Applications” ? or from anywhere else.. I have uploaded 1 lite version of my app now i am not at all clear about from where do i ned to submit the pro version binary.. Kindly give me CLEAR STEP BY STEP INSTRUCTIONS TO FOLLOW.

Hello Parijat,
We told about the binary file to Suresh because it might have helped him in his certain case. Unfortunately we can’t help you with the step-by-step instructions as we can only answer clear and precise question.
But perhaps other visitors can provide you some help.

I want to develop an in-app purchases application (consumable type, one-time services with 2 options: for example $1 and $10 for each option). Each time, when users request to upload 1 image, my app will cost them with different prices. So I must create 2 virtual products with 2 prices, that’s right?

Hi there,
I have two questions:
1) Suppose I have an article as a subscription; I buy it on my first device; If I do the same with a second devices I get the following message: “You’ve already subscribed …” This is true but I CANNOT TRAP THIS ACKNOWLEDGMENT so if I buy the subscription from my second device I WILL NOT EXTEND THE FIRST SUBSCRIPTION.
Of course I build a username/password system that let the users to register more than one device (as Apple states), but if the user does not register the second device, he/she will buy the subscription once again.
There is a way to resolve this issue????

2) Ok I build a username/password to restore subscription on different devices. Now can I LIMIT the restore on say no more than 4 devices???
I agree that users have to use the subscription on their devices but if I don’t limit the restore, one user can give his/her account away so I have one subscription payed and DOZEN of users.

Hello Oscar,
To the first question:
1) You should check your subscription through application server and shouldn’t initiate buying subscription again.
To the second question:
2) Apple may reject your application if it have any restriction in number of devices.
Hope this will help you in iPhone app development.

Thanks for the answer.
About the first one:
How can I check the subscription?
I cannot know the iTunes connect user that already subscribed. I have only a new UDID and if the user doesn’t confirm the subscription with my user/pass system I cannot link the already payed subscription with the new devices.

We created an app in the developer portal as ‘Main app’ with the product id as com.companyname.mainapp and also two inapp purchase apps as ‘Sub app1′, ‘Sub app2′ with the product identifiers as com.companyname.mainapp.subapp1 and com.companyname.mainapp.subapp2.
We wrote the code to handle the payment and once the transaction state reaches SKPaymentTransactionStatePurchased.
It is the responsibility of the apple to download and install the Sub app1 in the device? or do we need to write a code to install the sub app1 or sub app2 in the device.
Note: We use the in app store inside the main app ie we have sub app1, sub app2 with the buy now button.

Another question : After we purchase the Sub app1. Do we need to show as buy now inside the Main app for Sub app1 or show the status or button as Installed?

Hi Vijay,
All the functionality of the iPhone/iPad applications is implemented only by developer. Apple can’t download and install app unless it is specified in the code of the app so it’s all up to the logic of the app you develop.

Thank you for your reply. In my app, after we click the Buy now for the product in the main app. It goes to the product request, payment process and i receive the alert message as Thank you for purchasing the app. Can you give me a sample of how to download and install the product (eg: sub app1) to the device?

Note: we should see the apps like Main app, sub app1 in the device. The sub app1 will be a separate app installed after purchasing and downloading using Non-Consumable. We have submitted the Main app as well as Sub app1, Sub app2 binary files to the itunes connect.

I don’t mean to download and install an application from app store from another application. I mean how to download and install in app purchase app like how the AppShopper app in the iTunes store. If i install an app from the inapp store (AppShopper) that app is downloaded and installed onto the device along with AppShopper. I don’t have the idea about the code to implement the above process after the inapp purchase payment process.

Thank you for your reply. do i need to submit the binary files for each product and wait for it to be approved by apple before submitting the in app purchase app (bundle)? because my in app purchase was rejected as the products binary was still in the review status.

Dear Concerned,
We created an app, currently we know that there will be two different non-consumable products, so we created two different product id’s & hard coded in our code snippet. But in future there can be more than two products or less than two, so how can we manage the product id’s so that the current code snippet can accommodate the new products too.
Is there a direct way to get the complete list of the products for the specific application without specifying product id by default?
If possible, please explain using source code…
Thanks & Regards,
Zahur

Now, We need to make the NSSet to be dynamic. We mean that we load the product id’s from the server as a Mutable Array, now we need to pass those product id’s in the above request. But we are confuse how to do that…
Please guide us ….
Thanks & Regards,
Zahur

Hi Zahur,
The question you asked has no attitude to the article and we can’t provide you the solution here. But you should see the Apple guidelines and other books and tutorials (related to the topic) that can be easily found in the web. We believe in your case they’ll be more helpful.

I am new in iTunes store. and i have create a iphone application and i want to use apple In-App-Purchase in my application and its my first application. and i want to submit this application to apple store. but it needs minimum one paid application submitted on apple store before use In-App-Purchase. so can any one suggest how i submit my first application on apple store with in-app-purchase.

Hi Mitesh,
You need at least one paid application because you have to implement the logic for the payment transactions, there are should be ids for users to identify them as well as some other points. See the guidelines provided by AppSrore for the paid iPhone applications and carrying out payment transactions. Then it would be easier for you to deal with in-app purchase implementation.

I received a rejection email from Apple for the following reason:
17.2 Apps that require users to share personal information, such as email address and date of birth, in order to function will be rejected

Does this mean I shouldn’t use an e-mail as the username?

I also must include a text as stated in the mail:
It would be appropriate to make it clear to the user that registering will enable them to access the content from any of their iOS devices, and to provide them a way to register later, if they wish to extend membership to additional iOS devices.

Right now the user must register to get the 30 days trial and can then subscribe for more days at any time.
Would it be enough to just include that text or must I enable the 30 days trial before registration per nsuserdefaults, which would allow the user to delete and re-install the app to get another 30-day trial?

i can’t do any in-app purchases, the applications gave me always the same message that I should contact iTunes support to accomplish the transaction i redo and redo the some operation and always the same result, I checked the credit card, my informations….etc aand everything is normal and functional i hope you can help me to fix this problem.

Thank you guys for a great tutorial and codes. I have a question, I heard from somewhere that you can not make your app expired in a year. But MLB (not sure if I got the name correct) took some functionalities off their MLB app and introduced a new one MLB2010 and force buyers to buy that new version.

Would Apple allow that implementation to no longer support an old paid app and having user buy a new one or a new one with a subscription based services?

Now i need same thing, i have one free app in app store, that app can access limited level.
I want make that app in full access level (like open the levels) using in-app purchase(change free app to paid app). How can it’s possible?., u have any same code or any suggestion pls??

Hello I have gone through the steps but I am unable to understand where I have to write which code please guide me or give me step by step solution how start new application for In-App-Purchasing. Thank you.

I will describe my problem in detail…..I am doing a business application…User want to purchase an item more than once at the same time. Now Apple account has only id for 1 item . How can we purchase one item several times using In App Purchase…?

HI Iphone Dept
great resource thanks for sharing, we have our own subscription system working for our kids TV app and now want to transition to the IAP ( before the end of june:-)) We have a 30 day full trail, then you can transition to paid monthly or the free VALUE account. Right now we require email and password to setup account. I have a couple of questions.
1/ We have a number of coupons for extra months free usage out in the world, we are tracking that through our server and I was wondering the best way to have people use those on sign up, (I guess we could track time locally but what about multiple devices?)
2/ Does Apple allow the app to go to a free Value account on in app purchase after 30 days? Our idea is to have the 2 options, stay free but get the value account (less content) or pay subscription for all the content monthly. we want to remind them of this every time they open the app if the choose free. Also when an App is deleted and reinstalled how would we stop them from getting the free full account for a month again?
hope you can give us some feedback
yours
Tim

I wish to implement subscription type in app purchase to my app. I have a iPad Only application, even then I need to support for all the other devices of a user to download my in app purchase product?

We already have an in app purchase (non-consumable type) app version for iPad only and now need to implement subscription model as a new version? Should I do this as a new version or I should do it as a new app altogether.

Hello Sir,
This is the great example to implement the in app purchase in apps, I have some basic questions . I would like to request you please provide me the answer if you have a time for these. I am going to implement the auto renewal subscription.
My question is follow as:
1 We need to upload my application in app store to test the apps,
2 I have created the test account. Is it work for sandbox login.
3 Is there any url need to heat for creating the connection between application to app store server.
4.How i can test my application before going to upload in the app store , is there any way to test in app purchase.
5 If we need to upload the application in app store then it is publicly available so this is not a good way to test the apps.

Please provide me step by step process to implement the Auto renewal subscription and which is the best way to implement.
if you can provide me any sample code then it will be very helpful for me.

Seem this thread is quite old, however I actually face the same questions.
So if anybody have the answers to this please reply:

Can we configure the app without upload it in AppStore in order to test in-app purchase?
And if yes where is the trap? :p (a check button to not check? an information to not add? an action to not perform? )

Otherwise thank to this good tutorial and for the detailled answers!
Hope to received one to my own!

Great Code !
But: I`m a new iPhone developer – please can you post a simple CodeSnipped how I implement this class in my code !? I have a button and this will change the view of IAd with inAppPurchase – how i must call this code ? What must I do ?
Thank you very much ! (Sorry for my bad english – I`m german)
Uwe

We recently shared an open source library for in-app purchase on iOS. You can find it at http://project.soom.la. The library can be used as reference code or as a complete SDK and it implements security and event handling as well.

Hi,
I am doing a modification in an app’s in-app purchase.Currently the app asks for the in-app purchase to be made each time he tries to enter a 2nd event, 3rd event, etc. The in-app purchase should only charge the user to enter the first one then the user can join all events from that point without being charged again.. I created a app -id and product in our apple account.the status of the product is “waiting for review” but when running this application on device it says invalid product id .what is the reason for it?

Hii iphone development.your tutorial is nice…but i have a question …that i want to show products in inapp purchase that is comming from webservice…so how can i do this the app admin can add product any time because he has backend so he can add a product in backend…which is shown in my tableview when i hit the particular webservice….and how the price is decided in in app purchase..is their all the product have same price…..please answer my question………looking for ur response……