Solved

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

  • 19 February 2024
  • 9 replies
  • 64 views

Badge +4


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

icon

Best answer by nat-serrano 28 February 2024, 11:35

View original

This post has been closed for comments

9 replies

Badge +4

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);
}
}
}}

 

Badge +4

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);
}
}}


 

Badge +4

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>

 

Badge +4

@Michael Fogel 

Userlevel 5
Badge +9

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);
}

 

Badge +4

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

 

 

 

Badge +4

 

Badge +4

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.

Badge +4

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

For Expo, we recommend the following: