I’m new to react native, recently coding about in app purchase.
below is my code for handle purchase
const handlePurchase = async (productId) => {
try {
setPressedItemId(productId);
const items = Platform.select({
ios: [productId],
android: [productId],
});
const { responseCode, results } = await InAppPurchases.getProductsAsync(items);
console.log('Get products response:', responseCode);
console.log('Products:', results[0].productId);
if (responseCode === InAppPurchases.IAPResponseCode.OK) {
const { productId } = results[0];
const purchase = await InAppPurchases.purchaseItemAsync(productId, null, null, true);
console.log('Purchase successful');
console.log('Purchase:', purchase);
} else {
console.log('Failed to get product information:', responseCode);
Alert.alert('错误', '无法购买商品', [{ text: '确定' }]);
// 处理购买失败后的逻辑
}
} catch (error) {
console.log('Failed to purchase:', error);
Alert.alert('错误', '无法购买商品', [{ text: '确定' }]);
// 处理购买失败后的逻辑
} finally {
setPressedItemId('');
}
};
however
console.log('Purchase successful');
console.log('Purchase:', purchase);
was not activate after successful purchase.
where am I doing wrong?
I tried looking for different iap option, I still prefer expo in app purchase as it is most simple.