How to Verify iTunes, Android and Amazon Subscription Status from Backend Server?
How to Verify iTunes, Android and Amazon Subscription Status from Backend Server?
10 September 2020
Introduction
When your application has in-app purchase subscription, either auto-renewal or not, you might need to check the subscription status whether still active or it has expired. To check if the user still has a valid subscription when their subscription period is about to end, you will need to do re-validation on the purchase token.
Detect iTunes Subscription Status
The endpoint for the sandbox environment is https://sandbox.itunes.apple.com/verifyReceipt and for production it’s https://buy.itunes.apple.com/verifyReceipt
You need to send a JSON payload on iTunes endpoint:
- receipt-data – The base64 encoded receipt data. This will get from the app on subscription and store it on your backend database.
- Password – it will be your app’s shared secret
- exclude-old-transactions – It is only used for iOS7 style apps. If the value is true, then the response includes only the latest renewal transaction.
Use cURL to call the App Store endpoint. Here’s a rough example, you’ll need to modify it for your particular environment and to fill in the required variables.
Here is an example how to get the subscription status in php:
In the response, it will return the subscription detail having expiry date and time.
For more information about error codes and response parameter see on official site
Detect Google Android Subscription Status
You can check the subscription status by sending a request with the purchase token from your server to the play store API. You can check the expiry/renewal field in the server response and see if the purchase has expired or not.
Here is an example how to get the subscription status in php:
Where:
- $appId – your app package name, like com.yourapp.messenger
- $refreshToken, $clientID, $clientSecret – Your account details for oauth2. Follow the step to generate it from the official site
Detect Amazon Receipt Verification for IAP Apps
The Receipt Verification Service (RVS) allows validation of purchases made by your app’s users through RVS endpoint.
Here is an example how to get the subscription status in php:
Here:
- Shared_secret: Shared secret used to identify the developer. Your shared secret can get on the Shared Key page of your developer account with the Amazon Appstore.
- More information about error and response see on official site
Conclusion
Finally, you are able to validate all three store purchase receipts with simple cURL implementation to call the server and response having receipt valid period.