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
Expo
This package cannot be used in the "Expo Go" app because it requires custom native code.
After installing this npm package, add the config plugin to the plugins
array of your app.json
or app.config.js
.
{
"expo": {
"plugins": ["react-native-iap"]
}
}
Config plugins options
Note: every time you change the plugins or options you'll need to rebuild (and
prebuild
) the native app as described in the "Adding custom native code" guide.
You can optionally provide the following config plugin options. If no config plugin options are included, the default values from the options will be added.
Android payment provider
You can support Play Store
, Amazon AppStore
or both
:
paymentProvider
(string): payment provider to configure:Play Store
(default),Amazon AppStore
,both
{
"expo": {
"plugins": [
[
"react-native-iap",
{
"paymentProvider": "both"
}
]
]
}
}
iOS
cd ios; pod install; cd -
Note: For iOS 12.x, set project in Xcode as below: Build Phases -> Link Binary With Libraries -> +(Add) -> SwiftUI.framework, Optional
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 you 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.