Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 getLatestSubscription(callback) {
try {
await RNIap.prepare();
const subscriptionList = await RNIap.getAvailablePurchases();
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);
async fetchData() {
this.loading = true;
try {
const status = await RNIap.prepare();
this.products = await RNIap.getProducts(SKUs);
} catch (err) {
Sentry.captureException(err);
}
this.loading = false;
}
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();
}
}