dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.78k stars 634 forks source link

getProducts empty data and transactionReceipt empty SK2, verify 21002 #2516

Closed minhthuhai closed 1 year ago

minhthuhai commented 1 year ago

Please use the Discussion board if you want to get some help. Please use issues to report bugs.

`useEffect(() => { let purchaseUpdateProduct; let purchaseErrorProduct;

const setupPurchaseListeners = async () => {
  try {
    setup({storekitMode: 'STOREKIT2_MODE'});
    await initConnection({
      useSandbox: true,
      // publicKey: 'YOUR_PUBLIC_KEY',
    });

    if (Platform.OS === 'android') {
      await flushFailedPurchasesCachedAsPendingAndroid();
    }

    const products = await getProducts({skus: productSKUs});
    console.log('products - 125:', products);

    purchaseUpdateProduct = purchaseUpdatedListener(async purchase => {
      console.log('purchaseUpdatedListener', purchase);
      const receipt =
        Platform.OS === 'ios'
          ? purchase.verificationResultIOS
          : purchase.transactionReceipt;
      if (receipt) {
        try {
          if (isIOS) {
            const receiptBody = {
              'receipt-data': receipt,
              password: APPSTORE_IAP_SECRET,
            };
            const appleReceiptResult = await validateReceiptIos(
              receiptBody,
              true,
            );

            if (appleReceiptResult) {
              const {status} = appleReceiptResult;
              setIsLoading(false);
              if (status === 21007) {
                console.log(getAppleIAPErrorMessage(status) + `${status}`);
                Alert.alert(
                  'Purchased Successful!',
                  getAppleIAPErrorMessage(status) + ` ${status}`,
                );
                await finishTransaction({
                  purchase: purchase,
                  isConsumable: true,
                });
              } else {
                console.log(getAppleIAPErrorMessage(status) + `${status}`);
                console.log('Purchased Failed!');
                Alert.alert(
                  'Purchased Failed!',
                  getAppleIAPErrorMessage(status) + ` ${status}`,
                );

                await finishTransaction({
                  purchase: purchase,
                  isConsumable: true,
                });
                setIsPurchaseFailed(true);
              }
            }
          }
        } catch (error) {
          setIsLoading(false);
          console.error('Error delivering purchase:', error);
        }
      }
    });

    purchaseErrorProduct = purchaseErrorListener(error => {
      console.warn('purchaseErrorListener', error);
    });
  } catch (error) {
    setIsLoading(false);
    console.error('Error setting up purchase listeners:', error);
  }
};

setupPurchaseListeners();

return () => {
  if (purchaseUpdateProduct) {
    purchaseUpdateProduct.remove();
  }

  if (purchaseErrorProduct) {
    purchaseErrorProduct.remove();
  }
};

}, []);`

Description This is my setup. i make sure all product on Appstore connect is Ready to Submit. i cann't get my product, so i setup file .storekit but cann't get. (response: [])

For some reason I had to delete my products and create them again. before i deleted i got my list of products. and i can get my product and i requestPurchases i has response empty transactionReceipt, verificationResultIOS is token JWT. i tried verify with verificationResultIOS so status code == 21002.

I have consulted quite a few issues of [react-native-iap] like setup account sandbox, file .storekit. getProducts before call requestPurchase, ... but i cann't solved.

Please help me, i don't know if apple or device have cache for some time but i think that's not my biggest problem.

Environment:

trien19981 commented 4 months ago

em cũng đang bị như thế này, anh đã xử lý được nó chưa ạ?

Rohit-vinfotech commented 1 month ago

how you resolve this , I also facing this issue can you please guide me

Thank you in advance I hope you reply