
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
react-native-iap
Advanced tools
This a react-native link library project for in-app-purchase for both android and ios project. The goal for this project is to have similar experience between the two platforms for in-app-purchase. Basically android platform has more functions for in-app-
This a react-native link library project for in-app-purchase for both android and ios project. The goal for this project is to have similar experience between the two platforms for in-app-purchase. Basically android platform has more functions for in-app-purchase and is not our specific interests for this project. However if you look inside the index.js file, you will have some more hidden android functions which won't be supported in the readme. You can look inside if you want something more in android though. Android iap is implemented with iap version 3 which is currently recent.
https://github.com/dooboolab/react-native-iap
$ npm install react-native-iap --save
$ react-native link react-native-iap
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-iap
and add RNIap.xcodeproj
libRNIap.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainActivity.java
import com.reactlibrary.RNIapPackage;
to the imports at the top of the filenew RNIapPackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':react-native-iap'
project(':react-native-iap').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-iap/android')
android/app/build.gradle
:
compile project(':react-native-iap')
You can look in the RNIapExample folder to try the example. Below is basic implementation which is also provided in RNIapExample project.
First thing you should do is to define your items for iOS and android separately like defined below.
import RNIap from 'react-native-iap';
const itemSkus = {
ios: [
'com.cooni.point1000',
'com.cooni.point5000',
],
android: [
'point_1000',
'5000_point',
],
};
If you are also developing android, you should do prepareAndroid() in componentDidMount in necessary component. Then call getItems() usually.
async componentDidMount() {
if (Platform.OS === 'android') {
try {
const msg = await RNIap.prepareAndroid();
console.log('msg: ' + msg);
} catch (err) {
console.log('err: ' + err);
}
}
const items = await RNIap.getItems(itemSkus);
this.setState({ items, });
/*
Each item will have JSON object.
currently both platform have price, productId attributes.
iOS will support currency_type after v0.1.4
you need productId attribute on both android and iOS to buy item.
*/
}
Finally when you getItems with RNIap module, you can buyItem using it's api.
const receipt = await RNIap.buyItem('com.cooni.point1000');
// above will return receipt string which can be used to validate on your server.
In RNIapExample, at receiving receipt string, main page will navigate to Second.js.
buySubscribeItem = async(sku) => {
try {
console.log('buyItem: ' + sku);
const receipt = await RNIap.buyItem(sku);
// ios case parsing 리턴값이 어레이가 아님... 0, 1 를 키로 갖는 객체임..
console.log(receipt);
this.setState({ receipt }, () => this.goToNext());
} catch (err) {
console.log(`${err}`);
Alert.alert(`${err}`);
}
}
Subscribable products can be included in item object and purchased just like consumable product. You can cancel subscription on iOS system setting.
iOS : restore non-consumable products via restoreCompletedTransactions()
Thanks.
by JJMoon and dooboolab.
FAQs
React Native In App Purchase Module.
The npm package react-native-iap receives a total of 49,811 weekly downloads. As such, react-native-iap popularity was classified as popular.
We found that react-native-iap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.