$ yarn add react-native-app-gallery-iap
Make sure to read the AppGallery Documentation. The following steps are the most important ones :
- Configure the app
- Add the configuration file in
android/app/agconnect-services.json
- Add the huawei maven repo to your project level
build.gradle
file :
allprojects {
repositories {
maven {
url 'https://developer.huawei.com/repo/'
}
}
}
- Add the huawei maven repo to your project level
build.gradle
file (buildscript) :
buildscript {
repositories {
maven {
url 'https://developer.huawei.com/repo/'
}
}
}
- Add the huawei classpath to the project level
build.gradle
file :
buildscript {
dependencies {
classpath('com.huawei.agconnect:agcp:1.3.1.300')
}
}
- Add the following into your app level
build.gradle
implementations :
implementation 'com.huawei.hms:iap:4.0.4.300'
- Apply the plugin at the bottom of your app level
build.gradle
file :
apply plugin: 'com.huawei.agconnect'
import AppGalleryIap, { PriceType } from "react-native-app-gallery-iap";
try {
await AppGalleryIap.initialize(); // Initializes, if throws error AppGallery IAP is probably not supported
await AppGalleryIap.fetchProducts(PriceType.CONSUMABLE, ["product_id_1"])); // Returns Promise<Product[]>
await AppGalleryIap.fetchOwnedPurchases(PriceType.CONSUMABLE); // Returns Promise<any>
} catch (e) {
throw e;
}
See index.d.ts
for detailed method documentation with types.