-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
requestPurchase Does Not Return Error or Success Status #2700
Comments
I have faced a similar issue. iOS version: 17.3.1. |
I am facing similar problem in requestSubscription It does not enter the useEffect of currentPurchase, it is sent undefined and therefore the purchase is not detected Versión de iOS: 17.0.1 |
I'm having the same issue. |
I faced same problem. |
### Summary This PR addresses an issue with the `currentPurchase` status not updating correctly in the library after a successful in-app purchase. The problem occurs because the `purchaseListener` is only connected once when the app is first connected, and not after that. This requires users to repeat the purchase process by killing the app. ### Problem Description After a successful in-app connection, the store purchase completes, but the `currentPurchase` status does not update. This is likely due to the `purchaseListener` being connected based on the `connected` value inside `useEffect`. The `connected` value changes from `false` to `true` only when the app first connects, and not subsequently, preventing proper subscription to the current order status. ### Solution To resolve this, I added code inside the `endConnection` method to set `connected` to `false`. This ensures that every subscription updates correctly by changing `connected` to `true` when accessing the order page and to `false` when accessing `endConnection`. This approach has been tested and works as expected on both iOS and Android. ### Related Issue This issue appears to be related to the following issue: [#2700](#2700). ### Conclusion I hope this PR helps everyone experiencing this issue. Thank you for considering this improvement.
### Summary This PR addresses an issue with the `currentPurchase` status not updating correctly in the library after a successful in-app purchase. The problem occurs because the `purchaseListener` is only connected once when the app is first connected, and not after that. This requires users to repeat the purchase process by killing the app. ### Problem Description After a successful in-app connection, the store purchase completes, but the `currentPurchase` status does not update. This is likely due to the `purchaseListener` being connected based on the `connected` value inside `useEffect`. The `connected` value changes from `false` to `true` only when the app first connects, and not subsequently, preventing proper subscription to the current order status. ### Solution To resolve this, I added code inside the `endConnection` method to set `connected` to `false`. This ensures that every subscription updates correctly by changing `connected` to `true` when accessing the order page and to `false` when accessing `endConnection`. This approach has been tested and works as expected on both iOS and Android. ### Related Issue This issue appears to be related to the following issue: [#2700](hyochan/react-native-iap#2700). ### Conclusion I hope this PR helps everyone experiencing this issue. Thank you for considering this improvement.
// Function to handle purchase
const handlePurchase = async productId => {
if (purchaseInProgress) {
// If purchase already in progress, return
return console.log('purchase already in progress');
}
try {
setPurchaseInProgress(true); // Set purchase in progress state to true
console.log("--------87")
const purchase = await RNIap.requestPurchase({sku: productId}); // Purchase the product
console.log("--------89")
if (!purchase || purchase.purchaseState !== 'purchased') {
// If purchase state is not purchased, show error alert
Alert.alert(
'Purchase Failed',
'There was an error processing your purchase',
);
} else {
// If purchase successful, show alert
Alert.alert('Purchase Successful',
You have purchased ${productId}
);}
setPurchaseInProgress(false); // Reset purchase in progress state
} catch (error) {
setPurchaseInProgress(false); // Reset purchase in progress state
Alert.alert(
'Purchase Failed',
'There was an error processing your purchase',
);
console.error('Purchase error:', error);
}
};
hello this is my function and when i click on subscribe button this function hit. And also, open sandbox popup with my products but when I entered my sandbox credentials popup hide for some time but again show and i don't got any result or my
console.log("--------89") ,that time.
if have ant one solution then please response me
Thanks
The text was updated successfully, but these errors were encountered: