In App Purchase - iOS Integration
Last updated
Last updated
If you have not done setup for In App Purchase in your apple account click here to know how to setup IAP in iOS.
To initiate In app purchase in your app call following method from javascript
Note: If the run was unsuccessful and you didn’t see any products, then there are a number of things to check.
Does the project’s Bundle ID match the App ID from the iOS Development Center?
Is the full product ID being used when calling purchase method.
Is the Paid Applications Contract in effect on iTunes Connect? It can take hours to days for them to go from pending to accepted from them moment you submit them.
Have you waited several hours since adding your product to App Store Connect? Product additions may be active immediately or may take some time.
Check Apple Developer System Status. Alternatively, try this link. If it doesn’t respond with a status value, then the iTunes sandbox may be down. The status codes are explained in Apple’s Validating Receipts With the App Store documentation.
Have IAPs been enabled for the App ID? (Did you select Cleared for Sale earlier?)
Have you tried deleting the app from your device and reinstalling it?
Still stuck? Contact Us
There are two methods available to fulfill your user’s purchases: server-side, and on-device. Server-side verification is generally recommended if purchases are to be associated with a user account, as it is more secure. When an in-app purchase is made, the purchase data will be sent to your web server, which will credit or fulfill the purchased item after it has verified the purchase with Apple. During this process, you should associate the purchase with the logged-in user in your system.
For example, your website may have user logins with a free membership tier, and a premium membership tier. In this case, you should only display the purchase page within the logged-in section of your website. When the purchase is made, callback function will be called with receiptData
Your web server needs to create a post to https://buy.itunes.apple.com/verifyReceipt with the contents:
If exclude-old-transactions
is set to true
, Apple will only return the latest transaction for auto-renewing subscriptions. Otherwise, you will get back the entire history of subscriptions.
Apple's server should return HTTP status 200 with a JSON object (see example below). If the JSON object is {"status":21007}
, the receipt was generated from the sandbox/test environment. In that case, re-do the POST to the following url: https://sandbox.itunes.apple.com/verifyReceipt.
Assuming the response from Apple’s server has status 0, verify the receipt's bundle_id matches your app, and what products have been purchased. Additionally, save the receipt-data in your database so that you can verify successful auto-renews. The receipt-data serves as a “token” you can use to get updated subscription information. At this point, your server should provide whatever it is the user has purchased (premium content, virtual currency, etc.)
If the status in the JSON is any value other than 0, or Apple’s endpoint does not return an HTTP status 200, or the request to Apple fails, do not fulfill the purchase. See https://developer.apple.com/documentation/appstorereceipts/status for other possible JSON status values. Your web server should respond with a JSON object with success
set to false
. We recommend logging the response from Apple for troubleshooting purchases, especially the status
field.
An example response from App Store Connect will look as follows:
Apple will automatically bill users who have purchased auto-renewable subscriptions. To check on the status of a user’s subscription, POST the receipt again to Apple’s endpoint and check the latest_receipt_info
field. You may wish to set up a regular job to go through all active subscriptions.
Apple can also notify you of subscription status changes by posting to an endpoint you have set up to handle the change events. Go to App Store Connect -> Your App -> App Information and enter the URL. See the “Status Update Notifications” section in the In-App Purchase Programming guide.