dooboolab-community / react-native-iap

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

Subscription Bottom Sheet Popup Loop on "Subscribe" Button Click in Sandbox Environment #2796

Open Nivashawk opened 4 days ago

Nivashawk commented 4 days ago

Description

When clicking the "Subscribe" button in the sandbox environment, the subscription bottom sheet popup appears in a continuous loop, preventing users from completing the subscription process(tested on simulator).

Steps to Reproduce

  1. Navigate to the subscription page in the sandbox environment.
  2. Click on the "Subscribe" button.
  3. Observe the subscription bottom sheet popup.

Expected Behavior

The subscription bottom sheet should appear once, allowing the user to complete the subscription process.

Actual Behavior

The subscription bottom sheet appears in a continuous loop, preventing the user from proceeding with the subscription.

Screenshots

Simulator Screenshot - iPhone SE (3rd generation) - 2024-07-05 at 10 44 00 Simulator Screenshot - iPhone SE (3rd generation) - 2024-07-05 at 10 44 30 Simulator Screenshot - iPhone SE (3rd generation) - 2024-07-05 at 10 44 50 Simulator Screenshot - iPhone SE (3rd generation) - 2024-07-05 at 10 44 53

How We Are Using Your Library

We are using your library to handle the subscription process as follows:

  1. initiating connection

    const setupInAppPayment = async () => {
    try {
      await initConnection();
      console.log("IAP connection initialized");
    } catch (err) {
      if (err instanceof Error) {
        console.warn(err.message);
      } else {
        console.warn("Unknown error", err);
      }
    }
    };
    
    React.useEffect(() => {
    setupInAppPayment();
    }, []);
  2. Getting subscription list

    const itemSkus = Platform.select({
    ios: ["m30", "q90", "y365"],
    });
    
    const getsubs = async () => {
    const subs = await RNIap.getSubscriptions({ skus: itemSkus });
    console.log("subs", subs);
    if (subs.length !== 0) {
      setSubscriptions(subs);
    }
    };
  3. Initiating request subscription
    const purchaseAppleSubscription = async (productId) => {
    try {
        const requestSubscription = await RNIap.requestSubscription({
          sku: productId,
        });
        console.log("requestSubscription", requestSubscription);
      }
    } catch (err) {
      if (err instanceof Error) {
        console.warn(err.message);
        Alert.alert("Purchase Failed", err.message);
      } else {
        console.warn("Unknown error", err);
        Alert.alert("Purchase Failed", "An unknown error occurred");
      }
    }
    };  
  4. We have a subscription listener

    React.useEffect(() => {
    const purchaseUpdateSubscription = RNIap.purchaseUpdatedListener(
      async (purchase) => {
        console.log("purchase", purchase);
        const receipt = purchase.transactionReceipt;
        console.log("receipt", receipt);
        if (receipt && receipt.length !== 0) {
          await axios.post("/user/not", {
            Receipt: receipt,
            Purchase: purchase
          });
          try {
            Alert.alert(
              "Purchase Successful",
              "Thank you for your subscription!"
            );
            await RNIap.finishTransaction({ purchase: purchase });
          } catch (err) {
            if (err instanceof Error) {
              console.warn(err.message);
            } else {
              console.warn("Unknown error", err);
            }
          }
        }
      }
    );
    const purchaseErrorSubscription = RNIap.purchaseErrorListener((error) => {
      console.warn("purchaseErrorListener", error);
      Alert.alert("Purchase Failed", error.message);
    });
    
    return () => {
      purchaseUpdateSubscription.remove();
      purchaseErrorSubscription.remove();
      // RNIap.endConnection();
    };
    }, []);

Environment:

Additional Information

The issue does not occur in the xcode environment.

sharukhrahman97 commented 4 days ago

Also, the server notifications webhook doesnt get hit, but it is working with request a test notification and get test notification status.