-
|
There is no problem on Android, but on iOS, the currentPurchase value may not come in from the useIAP hook after completing the purchase. ex) useEffect(() => { Is there anything I'm missing? Additionally, I found a situation where receipt details were not sent to the callback if user used another payment method instead of paying with a credit card. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Does it behave the same in a none sandbox environment? I found the same issue and had to use the purchaseUpdatedListener to retrieve the purchase details instead of the hooks |
Beta Was this translation helpful? Give feedback.
-
|
This is a known issue in the iOS Sandbox environment. The Sandbox environment can be unreliable and sometimes doesn't return purchase results properly. As mentioned in the comments:
Solutions1. Use v14+ with onPurchaseSuccess callback (Recommended)In v14+, use the import { useIAP } from 'react-native-iap';
const { requestPurchase, finishTransaction } = useIAP({
onPurchaseSuccess: async (purchase) => {
// This is more reliable than watching currentPurchase
console.log('Purchase received:', purchase);
await finishTransaction({ purchase, isConsumable: false });
},
onPurchaseError: (error) => {
console.log('Purchase error:', error);
},
});2. Use purchaseUpdatedListener directlyIf you need more control: import { purchaseUpdatedListener, finishTransaction } from 'react-native-iap';
useEffect(() => {
const subscription = purchaseUpdatedListener(async (purchase) => {
console.log('Purchase received:', purchase);
// Process and finish transaction
});
return () => subscription.remove();
}, []);3. Test in Production/TestFlightSandbox has known issues. Always verify behavior in TestFlight or production before concluding there's a bug. Note on VersionIf you're using v12/v13, please upgrade to v14+ which has improved purchase handling: |
Beta Was this translation helpful? Give feedback.
This is a known issue in the iOS Sandbox environment. The Sandbox environment can be unreliable and sometimes doesn't return purchase results properly.
As mentioned in the comments:
Solutions
1. Use v14+ with onPurchaseSuccess callback (Recommended)
In v14+, use the
useIAPhook with callbacks: