Get Started
Getting started
react-native-iap
will help you access the In-App purchases capabilities of your device on iOS
, and Android
(Play Store and Amazon).
This library will provide the basic features to consume In-App purchases on the client-side, however you'll have to implement the server-side to validate your receipts (which is probably the most time consuming part to do it correctly).
Requirements
react
>= 16.13.1react-native
>= 0.65.1
Installation
Start with installing the package:
- npm
- Yarn
- pnpm
npm install react-native-iap
yarn add react-native-iap
pnpm add react-native-iap
iOS
cd ios; pod install; cd -
You can now get started hacking!
Android
With Android Support
Go to android/build.gradle
and modify the following lines:
buildscript {
ext {
...
+ supportLibVersion = "28.0.0"
}
}
With AndroidX
Go to android/build.gradle
and modify the following lines:
buildscript {
ext {
...
+ androidXAnnotation = "1.1.0"
+ androidXBrowser = "1.0.0"
+ minSdkVersion = 24
+ kotlinVersion = "1.8.0"
}
}
dependencies {
...
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
Configure the payment provider
You can support either Play Store
, Amazon
or both.
- To only support
Play Store
, go toandroid/app/build.gradle
:
defaultConfig {
...
+ missingDimensionStrategy "store", "play"
}
- To support both:
android {
...
+ flavorDimensions "appstore"
+
+ productFlavors {
+ googlePlay {
+ dimension "appstore"
+ missingDimensionStrategy "store", "play"
+ }
+
+ amazon {
+ dimension "appstore"
+ missingDimensionStrategy "store", "amazon"
+ }
+ }
}
And your are now good to go!
Manual installation
iOS
- Open up
ios/Podfile
- Add
pod 'RNIap', :path => '../node_modules/react-native-iap'
- Run
pod install
Android
Open up
android/app/src/main/java/[...]/MainApplication.java
Add
import com.dooboolab.rniap.RNIapPackage;
at the top of the file.Add
new RNIapPackage()
to the list returned by thegetPackages()
methodAppend the following lines to
android/settings.gradle
:
+ include ':react-native-iap'
+ project(':react-native-iap').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-iap/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:
+ implementation project(':react-native-iap')
- Finally configure the payment provider described above.