Код: Выделить всё
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