I install and linked react native React Native IAP and also upload app in play store after that it create subscription product id But When I am request for get subscription I am getting this error
error
subscription product id
const items = Platform.select({
ios: [
'dev.products.gas',
'dev.products.premium',
'dev.products.gold_monthly',
'dev.products.gold_yearly',
],
android: ['dev.products.gas',
'dev.products.premium',
'dev.products.gold_monthly',
'dev.products.gold_yearly',],
});
import React, { useEffect } from 'react';
import { View, Text, Button, Platform } from 'react-native';
import { requestPurchase, useIAP } from 'react-native-iap';
const ParchesCode = () => {
const {
connected,
products,
promotedProductsIOS,
subscriptions,
purchaseHistories,
availablePurchases,
currentPurchase,
currentPurchaseError,
initConnectionError,
finishTransaction,
getProducts,
getSubscriptions,
getAvailablePurchases,
getPurchaseHistories,
} = useIAP();
const handlePurchase = async (sku) => {
await requestPurchase({ sku });
};
useEffect(() => {
// ... listen to currentPurchaseError, to check if any error happened
}, [currentPurchaseError]);
useEffect(() => {
// ... listen to currentPurchase, to check if the purchase went through
}, [currentPurchase]);
return (
<View style={{ flex: 1, }}>
<Button
title="Get the products"
onPress={() => getSubscriptions(items)}
/>
{subscriptions.map((product) => (
<View key={product.productId}>
<Text>{product.productId}</Text>
<Button
title="Buy"
onPress={() => handlePurchase(product.productId)}
/>
</View>
))}
<Text>{JSON.stringify(connected)}</Text>
<Text>{JSON.stringify(connected)}</Text>
</View>
);
};
export default ParchesCode;
I am not getting subscriptions when I am calling getSubscriptions() function. I need result after calling this but I am getting error like that -> Possible Unhandled Promise Rejection (id: 0): skus is required
Here is with working example. there issue is due to change in code but the documentation is not updated.
Here is the product list. the code only for iOS.
import {requestPurchase, useIAP, withIAPContext} from 'react-native-iap';
const myProducts = [
'product.example.1',
'product.example.2',
];
const InAppPurchaseScreen = ({navigation}) => {
useEffect(() => {
getProductsAndPurchases();
}, []);
const getProductsAndPurchases = async () => {
try {
await getProducts({skus: myProducts});
} catch (error) {
//console.log("Products error: ", error)
}
};
}
export default withIAPContext(InAppPurchaseScreen);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With