Skip to main content
Solved

how to find the product I want to buy if not using offering?

  • February 19, 2024
  • 9 replies
  • 135 views

Forum|alt.badge.img+5


how to buy a product?

I’m following this guide but I cannot buy my products
https://www.revenuecat.com/docs/getting-started/displaying-products

I created an offering, which has two packages, the voice has the one time purchase products from apple and google.

how do I find the voice product to buy? with the package identifier?
```

try {

const productToBuy = //how to find the product?;

if (!productToBuy) {

console.error("No product identifier found");

return;

}
```
or should I buy the package?
 

const { customerInfo } = await Purchases.purchasePackage(

offering.all["Voice"].availablePackages

);

I thought revenuecat was supposed to be simple

Best answer by nat-serrano

this info shows how to see the logs if using expo.

For Expo, we recommend the following: 

View original
Did this post help you find an answer to your question?
This post has been closed for comments

Forum|alt.badge.img+5

still I cannot make it buy a simple product
 

<TouchableOpacity
              style={styles.button}
              onPress={async () => {
                // Using Offerings/Packages
                try {
                  const { customerInfo, productIdentifier } =
                    await Purchases.purchasePackage(
                      offering.all["Voice"].availablePackages
                    );
                  // if (
                  //   typeof purchaseResult.customerInfo.entitlements.active[
                  //     "my_entitlement_identifier"
                  //   ] !== "undefined"
                  // ) {
                  //   // Unlock that great "pro" content
                  // }
                } catch (e) {
                  if (!e.userCancelled) {
                    showError(e);
                  }
                }
              }}

 


Forum|alt.badge.img+5

sitll not working not even with the purchasePackage, what am I doing wrong? I don’t even get an error message. a bit disappointed on this revenuecat product that so many devs praised. Note that purchasePackage is not mentioned in the documentation (outdated) and I saw this on youtube, nonetheless  doesn’t work.

 

<TouchableOpacity
              style={styles.button}
              onPress={async () => {
                // Using Offerings/Packages
                try {
                  await Purchases.purchasePackage(
                    packages.offeringIdentifier == "voice"
                  );

                  if (packages.offeringIdentifier === "voice") {
                    alert("succesful purchase!");
                  }
                } catch (e) {
                  console.log(e);
                  alert(e);
                }
              }}


 


Forum|alt.badge.img+5

trying to edit the post but I cannot so I am posting below. this is my logic
 

  useEffect(() => {
    //Purchases.setLogLevel(LOG_LEVEL.VERBOSE);

    if (Platform.OS === "ios") {
      Purchases.configure({ apiKey: process.env.EXPO_PUBLIC_RC_IOS_KEY });
      // Purchases.configure({ apiKey: process.env.EXPO_PUBLIC_RC_IOS_KEY });
    } else if (Platform.OS === "android") {
      Purchases.configure({ apiKey: process.env.EXPO_PUBLIC_RC_ANDROID_KEY });

      // OR: if building for Amazon, be sure to follow the installation instructions then:
      // Purchases.configure({ apiKey: "revenuecat_project_amazon_api_key", useAmazon: true });
    }
  }, []);

then when I reach my day limit in credits then I load the offerings, and set the packages based on the offerings
 

useEffect(() => {
    if (!reachedDayLimit) return; // Only run the effect when the modal is visible

    const loadOfferings = async () => {
      try {
        const offerings = await Purchases.getOfferings();
        if (offerings.current !== null) {
          //console.log("Current Offerings: ", offerings.current);
          //setOfferings(offerings); // Update the state with the fetched offerings
          //console.log("Current Offerings: ", offering.current);
          setPackages(offerings.current.availablePackages);
        } else {
          console.log("No offerings found");
        }
      } catch (e) {
        console.log(JSON.stringify(e));
        console.error("Error fetching offerings: ", e);
      }
    };

    loadOfferings();
  }, [reachedDayLimit]); // Depend on the modal's visibility state

then I have a button to purchase the package but nothing happens, no error, nothing
 

TouchableOpacity
              style={styles.button}
              onPress={async () => {
                // Using Offerings/Packages
                try {
                  await Purchases.purchasePackage(
                    packages.offeringIdentifier == "voice"
                  );

                  console.log("tried to purchase!!!!!!");

                  if (packages.offeringIdentifier === "voice") {
                    alert("succesful purchase!");
                  }
                } catch (e) {
                  console.log(e);
                  alert(e);
                }
              }}
            >
              <Text style={styles.buttonText}>
                Purchase !
              </Text>
            </TouchableOpacity>

 


Forum|alt.badge.img+5

sharif
RevenueCat Staff
Forum|alt.badge.img+9
  • RevenueCat Staff
  • February 22, 2024

Hey @nat-serrano,

You can use code similar to this:

try {
    const offerings = await Purchases.getOfferings();
    const offering = offerings.all["offering without weekly"];
    const packages = offering.availablePackages;
    const package = packages.find(package => package === "Voice");
    const { customerInfo, productIdentifier } = await Purchases.purchasePackage(
        package
    );
    if (
        typeof customerInfo.entitlements.active[
          "<put_your_entitlement_identifier_here>"
        ] !== "undefined"
      ) {
        // Unlock that great "pro" content
      }
} catch (e) {
    console.error(e);
}

 


Forum|alt.badge.img+5

Thanks. My products do not have entitlements because they are consumable products. I just need revenue cat to tell me the purchase of a package with a product was successful. 
 

anyways, I was able to get the modal (trying to pay) but now I am getting an error 

“products cannot be loaded” even though the products are active in the play store and the service account has been added etc

 

 

 


Forum|alt.badge.img+5

 


Forum|alt.badge.img+5

feb-25, 


tried to debug but looks like for expo react native apps the process is different, how can I debug RC in an expo app?

Expo apps for iOS can use Console.app on Mac to view debug logs, while Android projects are still recommended to use Android Studio. For specific help on debugging your React Native Expo project, feel free to reach out to RevenueCat support.


Forum|alt.badge.img+5
  • Author
  • Helper
  • 22 replies
  • Answer
  • February 28, 2024

this info shows how to see the logs if using expo.

For Expo, we recommend the following: 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings