Reputation: 102
It is the first time that I use react-native-iap in my project. I installed the library without any problems. I have a few questions.
import * as RNIap from 'react-native-iap';
const itemSkus = Platform.select({
ios: ['stackoverflow_ex'],
android: ['stackoverflow_ex']
});
export default class Buy extends Component {
state= {
products:[],
count:0
}
async componentDidMount() {
try {
const products: Product[] = await RNIap.getProducts(itemSkus);
this.setState({ products });
} catch(err) {
console.warn(err); // standardized err.code and err.message available
}
}
requestPurchase = async (sku: string) => {
try {
await RNIap.requestPurchase(sku, false);
this.setState({ count:this.state.count+1 });
} catch (err) {
console.warn(err.code, err.message);
}
}
click = () => {
this.requestPurchase('stackoverflow_ex')
}
render() {
const {item} = this.props;
return (
<TouchableOpacity onPress={() => this.click()} />
);
}
}
Upvotes: 2
Views: 3073
Reputation: 300
From the first glance, I would say that at least initConnection
is missing.
The best way to make sure the code is done correctly check out example in the github: https://github.com/dooboolab/react-native-iap/blob/master/IapExample/App.js
Upvotes: 0
Reputation: 1914
For android
you need to upload your apk
in Google play. if not then you cannot test Google play billing in your application. What you can do is upload the apk
and do a release under Internal test track
. It will take 2-3 days for the review process. After that you can do the testing.
For more read please check this link
Upvotes: 1