How to use the react-native-iap.prepare function in react-native-iap

To help you get started, we’ve selected a few react-native-iap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Skjutsgruppen / skjutsgruppen-reactnative / app / services / support / purchase.js View on Github external
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;
}
github Skjutsgruppen / skjutsgruppen-reactnative / app / services / support / purchase.js View on Github external
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);
github birkir / hekla / src / screens / settings / Donate.tsx View on Github external
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;
  }
github Skjutsgruppen / skjutsgruppen-reactnative / app / services / support / purchase.js View on Github external
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();
  }
}