react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

Not able to pay with any other payment method

Open AkshayManiar opened this issue 1 year ago • 1 comments

Description

When you have enough money in your Apple Wallet, you can make payments directly. However, if your Apple Wallet doesn’t have enough funds, it prompts you to use other payment methods like UPI or a credit card.

In the development environment, where everything is simulated (or "sandboxed"), payments are processed directly without issue. But in the production environment, when you choose UPI as the payment method, a request is sent to your UPI ID. However, the payment process is encountering an error and showing a “received error” status.

So, the main issues are:

  1. Payments work fine in the development environment but not in production.
  2. In production, UPI requests are failing with an error message.

Expected Behavior We need to get a payment status update and a transaction ID so that we can check and verify the payment status later.

Environment:

  • react-native-iap: 12.10.5
  • react-native: ^0.68.5
  • Platforms: IOS

Code

RNIap.requestPurchase({ sku: purchaseID, }) .then(async (res) => { console.log(res); }) .catch((err) => { console.log(err); });

AkshayManiar avatar Aug 13 '24 14:08 AkshayManiar

i faced the same issue.

after showing "payment in Progress" click on ok showing " Purchase Error" with payment was deferred. code==>

import * as RNIap from 'react-native-iap';
import { Alert } from 'react-native';
import { getUserDetails } from '../../utils/userDetails';

let resolvePaymentOverlay = null;
let purchaseUpdateSubscription = null;
let purchaseErrorSubscription = null;

export const waitForPurchaseToComplete = () => {
  return new Promise((resolve) => {
    resolvePaymentOverlay = resolve;
  });
};

const removeIapListeners = () => {
  purchaseUpdateSubscription?.remove();
  purchaseErrorSubscription?.remove();
  purchaseUpdateSubscription = null;
  purchaseErrorSubscription = null;
};

export const buyProductApple = async (productId) => {
  const userDetails = await getUserDetails();
  const userId = userDetails?.uid;

  try {
    await RNIap.initConnection();

    // Register listeners locally
    purchaseUpdateSubscription = RNIap.purchaseUpdatedListener(async (purchase) => {
      try {
        const receipt = purchase.transactionReceipt;
        if (receipt) {
          await RNIap.finishTransaction({ purchase, isConsumable: true });
          resolvePaymentOverlay?.(true);
          removeIapListeners(); // clean up
        }
      } catch (err) {
        console.warn('❌ Finish transaction error', err);
        resolvePaymentOverlay?.(false);
        removeIapListeners();
      }
    });

    purchaseErrorSubscription = RNIap.purchaseErrorListener((error) => {
      console.warn('❌ Purchase error:', error);
      if (error.code === 'E_USER_CANCELLED') {
        Alert.alert('Purchase Cancelled', 'You cancelled the payment.');
      } else {
        Alert.alert('Purchase Error', error.message || 'Something went wrong.');
      }
      resolvePaymentOverlay?.(false);
      removeIapListeners();
    });

    const availableProducts = await RNIap.getProducts({ skus: [productId] });

    if (!availableProducts || availableProducts.length === 0) {
      Alert.alert('Error', 'Product not found.');
      resolvePaymentOverlay?.(false);
      removeIapListeners();
      return false;
    }

    await RNIap.requestPurchase({
      sku: productId,
      andDangerouslyFinishTransactionAutomatically: false,
      appAccountToken: userId,
    });

    return true;
  } catch (error) {
    console.log('❌ Purchase error code:', error.code);
    if (error.code === 'E_USER_CANCELLED') {
      Alert.alert('Purchase Cancelled', 'You cancelled the payment.');
    }
    resolvePaymentOverlay?.(false);
    removeIapListeners();
    return false;
  } finally {
    setTimeout(() => {
      RNIap.endConnection();
    }, 3000);
  }
};

if you find any solution please help it would be very helpful. Thanks you can connect me on LinkedIn- [(https://www.linkedin.com/in/sandipanbera/)]

Image Image

sandipanflutrr avatar May 16 '25 06:05 sandipanflutrr

I’m closing all issues reported in versions below 14, as the library now supports the new architecture with NitroModules and has been completely revamped.

hyochan avatar Sep 30 '25 18:09 hyochan