Validating receipts
Since react-native-iap@0.3.16, we support receipt validation.
With IAPHUB#
IAPHUB is a service that takes care of the ios/android receipt validation for you, you can set up webhooks in order to get notifications delivered automatically to your server on events such as a purchase, a subscription renewal...
You can use it by calling the API manually to process your receipt or use the react-native-iaphub module that is just a wrapper of react-native-iap with IAPHUB built-in.
With Google Play#
For Android, you need separate json file from the service account to get the
access_token from google-apis, therefore it is impossible to implement serverless.
You should have your own backend and get access_token.
With access_token you can simply call validateReceiptAndroid() we implemented.
Further reading is here or refer to example repo.
With App Store#
Currently, serverless receipt validation is possible using validateReceiptIos().
- The first parameter, you should pass
transactionReceiptwhich returns afterbuyProduct(). - The second parameter, you should pass whether this is
testenvironment. Iftrue, it will request tosandboxandfalseit will request toproduction.
For further information, please refer to guide.
Sometimes you will need to get the receipt at times other than after purchase.
For example, when a user needs to ask for permission to buy a product (Ask to buy
flow) or unstable internet connections.
For these cases we have a convenience method getReceiptIOS() which gets
the latest receipt for the app at any given time. The response is base64 encoded.
iOS Purchasing process right way.#
Issue regarding valid products
In iOS, generally you are fetching valid products at App launching process.
If you fetch again, or fetch valid subscription, the products are added to the array object in iOS side (Objective-C
NSMutableArray).This makes unexpected behavior when you fetch with a part of product lists.
For example, if you have products of
[A, B, C], and you call fetch function with only[A], this module returns[A, B, C]).This is weird, but it works.
But, weird result is weird, so we made a new method which remove all valid products.
If you need to clear all products, subscriptions in that array, just call
clearProductsIOS(), and do the fetching job again, and you will receive what you expected.
Example backend (Node.js)#
Here you can find an example backend for idempotent validating of receipts on both iOS/Android and storing and serving subscription state to the client.
Supporting react-native-iap#
react-native is an open source project with MIT license. We are willing to
maintain this repository to support devs to monetize around the world.
Since IAP itself is not perfect on each platform, we desperately need
this project to be maintained. If you'd like to help us, please consider being
with us in Open Collective.