Форум для тех, кто программирует под Android
Anonymous
Ошибка React Native при покупке приложения (Android)
Сообщение
Anonymous » 16 июл 2024, 13:13
Функция работает нормально для iOS, но для Android выдает ошибку на моем физическом устройстве. Скриншот прилагается. Кто-нибудь сталкивается с такой же проблемой? (
https://i.sstatic.net/TMQN8BpJ.jpg )
Код: Выделить всё
const handleBuySubscription = async (productId, planType) => {
setIsRequestInProgress(true);
try {
const offer = subscriptionOffers[productId]?.[planType];
console.log("Selected Product ID:", productId);
console.log("Selected Plan Type:", planType);
console.log("Offer:", offer);
if (Platform.OS === 'android' && offer && offer.basePlanId && offer.offerId) {
try {
await requestSubscription({
sku: productId,
subscriptionOffers: [{ basePlanId: offer.basePlanId, offerId: offer.offerId }],
});
} catch (error) {
console.error("Error during requestSubscription:", error);
}
} else if (Platform.OS === 'ios') {
await requestSubscription({ sku: productId });
} else {
throw new Error("Invalid subscription offer details.");
}
setLoading(false);
setIsRequestInProgress(false);
} catch (error) {
setLoading(false);
setIsRequestInProgress(false);
if (error instanceof PurchaseError) {
console.error(`[${error.code}]: ${error.message}`, error);
} else {
console.error("handleBuySubscription", error);
}
}
};
Попробовал другой метод запроса покупки, но он не сработал.
Подробнее здесь:
https://stackoverflow.com/questions/787 ... roid-error
1721124834
Anonymous
Функция работает нормально для iOS, но для Android выдает ошибку на моем физическом устройстве. Скриншот прилагается. Кто-нибудь сталкивается с такой же проблемой? (https://i.sstatic.net/TMQN8BpJ.jpg) [code]const handleBuySubscription = async (productId, planType) => { setIsRequestInProgress(true); try { const offer = subscriptionOffers[productId]?.[planType]; console.log("Selected Product ID:", productId); console.log("Selected Plan Type:", planType); console.log("Offer:", offer); if (Platform.OS === 'android' && offer && offer.basePlanId && offer.offerId) { try { await requestSubscription({ sku: productId, subscriptionOffers: [{ basePlanId: offer.basePlanId, offerId: offer.offerId }], }); } catch (error) { console.error("Error during requestSubscription:", error); } } else if (Platform.OS === 'ios') { await requestSubscription({ sku: productId }); } else { throw new Error("Invalid subscription offer details."); } setLoading(false); setIsRequestInProgress(false); } catch (error) { setLoading(false); setIsRequestInProgress(false); if (error instanceof PurchaseError) { console.error(`[${error.code}]: ${error.message}`, error); } else { console.error("handleBuySubscription", error); } } }; [/code] Попробовал другой метод запроса покупки, но он не сработал. Подробнее здесь: [url]https://stackoverflow.com/questions/78753915/react-native-in-app-purchaseandroid-error[/url]