Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (subscriptionList.length === 0) {
callback(null, null);
} else {
const latestSubscription = [].concat(subscriptionList).sort((first, second) =>
second.transactionDate - first.transactionDate)[0];
callback(null, {
planId: latestSubscription.productId,
receipt: latestSubscription.transactionReceipt,
device: Platform.OS,
});
}
} catch (error) {
console.warn(error);
callback(error, null);
} finally {
await RNIap.endConnection();
}
}
export async function isSubscriptionActive() {
let currentSubscription;
if (Platform.OS === 'android') {
try {
await RNIap.prepare();
const subscriptionList = await RNIap.getAvailablePurchases();
if (subscriptionList.length > 0) {
currentSubscription = subscriptionList[0].productId;
}
} catch (error) {
currentSubscription = 'error';
console.warn(error);
} finally {
await RNIap.endConnection();
}
}
return currentSubscription;
}
export async function showPayment(planId, callback) {
try {
await RNIap.prepare();
await RNIap.getSubscriptions([planId]);
const purchase = await RNIap.buySubscription(planId);
callback(null, purchase);
} catch (err) {
callback(err, null);
} finally {
await RNIap.endConnection();
}
}
componentWillUnmount() {
RNIap.endConnection();
}
componentWillUnmount() {
RNIap.endConnection();
}