Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect(() => {
RNIAP.initConnection().then(() =>
RNIAP.getAvailablePurchases()
.then(findCurrentSubInfoFromPurchases)
.then(setCurrentSubscriptionInfo),
)
return () => {
// https://github.com/dooboolab/react-native-iap#end-billing-connection
RNIAP.endConnectionAndroid()
}
}, [])
export const init = async (userId)=>{
if (await RNIap.initConnection() == false)
throw new Error('This device is not allowed to make purchases. Please check restrictions on device')
//Old not finished puchases (restore like)
const purchases = await RNIap.getAvailablePurchases()
for(const purchase of purchases)
try{
await validatePurchase(purchase, userId)
} catch (e) {
console.log(e, purchase)
}
}