Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isAcknowledgedAndroid is always false for consumable product #2918

Open
thechaudharysab opened this issue Jan 23, 2025 · 2 comments
Open

isAcknowledgedAndroid is always false for consumable product #2918

thechaudharysab opened this issue Jan 23, 2025 · 2 comments

Comments

@thechaudharysab
Copy link

Description

My first time implementing in-app purchase so I might have a bit less knowledge about the whole lifecycle of the IAP. I only have in-app products to buy virtual coins that the user can buy as many times as they like hence isConsumable will be true for my case.

My implementation if IAP can be summed up to three changes:

  1. App.tsx the entry point of the app which has my navigator etc I did initConnection
  2. In the Home.tsx which is the first screen that the App.tsx loads in any case i.e. auth or non-auth users is where I added purchaseUpdatedListener and this is also where finishTransaction happens.
  3. The BuyCoins.tsx screen is where I getProducts as well as requestPurchase when a buy button is pressed.

For all the three points above here is the code:

App.tsx

  useEffect(() => {
    const initIAP = async () => {
      try {
        await initConnection();
        if (Platform.OS == 'android') {
          await flushFailedPurchasesCachedAsPendingAndroid();
        } else {
          // TODO: Add code to handle iOS purchases
          // await clearTransactionIOS();
        }
      } catch (error) {
        console.log('Error initializing IAP: ', error);
      }
    };

    initIAP();

    return () => {
      endConnection();
    };
  }, []);

Home.tsx

  const {
    currentPurchase,
    finishTransaction,
    getProducts,
  } = useIAP();

  useEffect(() => {
    const subscriptionListener = purchaseUpdatedListener(
      async (_purchase: Purchase) => {

        if (currentPurchase) {
          //TODO: Send the receipt to the server
          await finishTransaction({
            purchase: currentPurchase,
            isConsumable: true,
          });
          console.log(
            'currentPurchase @ subscriptionListener: ',
            currentPurchase.transactionReceipt,
          );
        }
      },
    );

    return () => {
      subscriptionListener.remove();
    };
  }, []);

BuyCoins.tsx

  const handleGetProducts = async () => {
    try {
      if (constants.productSkus) {
        await getProducts({ skus: constants.productSkus });
      }
    } catch (error) {
      errorLog({ message: 'handleGetProducts', error });
    }
  };

  const handleProductPurchase = async (sku: Sku) => {
    try {
      let purchaseParams: RequestPurchase = {
        sku,
        andDangerouslyFinishTransactionAutomaticallyIOS: false,
      };

      if (Platform.OS === 'android') {
        purchaseParams = { skus: [sku] };
      }

      await requestPurchase(purchaseParams);
    } catch (error) {
      console.log('err: ', error);
      setIsLoading(false);
    }
  };

Expected Behavior

When I purchase it goes through successfully but in finish payment if I try to print the transactionReceipt I get:

{"orderId":"ABC123","packageName":"com.MYAPP.TEST","productId":"passtest","purchaseTime":1234,"purchaseState":0,"purchaseToken":"safkhbvkhvbkfhbvfehbv","quantity":1,"acknowledged":false}

The "acknowledged":false should be true as it's a consumable product and as soon as user buys any product it should return true because i did call it after await finishTransaction...

Screenshots

N/A

Environment:

  • react-native-iap: 12.16.0
  • react-native: 0.75.4
  • Platforms (iOS, Android, emulator, simulator, device): Android Emulator and Physical Device

[Optional] Additional Context

I sometimes get error in finishTransaction [Error: Purchase failed with code: 8]

@kukadiyaAni
Copy link

I sometimes get an error in finishTransaction [Error: Purchase failed with code: 8]

same for me, any update?

@xinkuiwu
Copy link

xinkuiwu commented Feb 11, 2025

same problem in android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants