How to use the react-native-iap.validateReceiptIos 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 Flaque / quirk / src / subscriptions / iosReceipts.ts View on Github external
export async function getAppleExpirationDateFromReceipt(
  receipt: string
): Promise {
  let data = await InAppPurchases.validateReceiptIos(
    {
      "receipt-data": receipt,
      password: APPLE_SHARED_SECRET, // Shared Secret
    },
    !!__DEV__ // Ask for sandbox if we're in dev
  );
  if (!data) {
    return false;
  }

  /**
   * Apple's reviewers test in sandbox mode, so
   * if we find ourselves in a build that SHOULD
   * be production, but Apple's servers are
   * "helpfully" returning a 21007, (thank you apple you're the best and totally not the bane of my entire existance)
   * then we'll just try again in sandbox mode.
github Flaque / quirk / src / subscriptions / iosReceipts.ts View on Github external
);
  if (!data) {
    return false;
  }

  /**
   * Apple's reviewers test in sandbox mode, so
   * if we find ourselves in a build that SHOULD
   * be production, but Apple's servers are
   * "helpfully" returning a 21007, (thank you apple you're the best and totally not the bane of my entire existance)
   * then we'll just try again in sandbox mode.
   *
   * everything is fine. This is fine.
   */
  if (data.status === CODE_PRODUCTION_SANDBOX_MODE) {
    data = await InAppPurchases.validateReceiptIos(
      {
        "receipt-data": receipt,
        password: APPLE_SHARED_SECRET, // Shared Secret
      },
      true
    );
  }
  if (!data) {
    return false;
  }

  /* Looks like:
      [
        Object {
          "expires_date": "2019-06-20 14:59:28 Etc/GMT",
          "expires_date_ms": "1561042768000",
github guardian / editions / projects / Mallard / src / hooks / use-subscribe.ts View on Github external
const findCurrentReceiptFromPurchaseHistoryIOS = async (
    purchases: Purchase[],
) => {
    const purchase = purchases.sort(
        (a, b) => b.transactionDate - a.transactionDate,
    )[0]

    if (!purchase) return false

    const latestReceipt = await RNIAP.validateReceiptIos(
        {
            'receipt-data': purchase.transactionReceipt,
            password: ITUNES_CONNECT_SHARED_SECRET,
        },
        __DEV__,
    )

    if (!latestReceipt) throw new Error('Could not find receipt for purchase')
    const latestReceiptInfo = latestReceipt.latest_receipt_info as ReceiptIOS[]
    if (!latestReceiptInfo)
        throw new Error('Could not find receipt info for receipt')

    return (
        latestReceiptInfo.find(
            receipt => Number(receipt.expires_date_ms) > Date.now(),
        ) || false
github guardian / editions / projects / Mallard / src / authentication / services / iap.ts View on Github external
const fetchDecodeReceipt = (receipt: string) =>
    RNIAP.validateReceiptIos(
        {
            'receipt-data': receipt,
            password: ITUNES_CONNECT_SHARED_SECRET,
        },
        isInBeta() || __DEV__,
    )