Skip to content
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

Open
pixlerSanjay opened this issue Mar 7, 2024 · 4 comments
Open

requestPurchase Does Not Return Error or Success Status #2700

pixlerSanjay opened this issue Mar 7, 2024 · 4 comments

Comments

@pixlerSanjay
Copy link

// 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

@pixlerSanjay pixlerSanjay changed the title requestPurchase Endpoint Does Not Return Error or Success Status requestPurchase Does Not Return Error or Success Status Mar 7, 2024
@janisievins
Copy link

I have faced a similar issue.
Error message: The operation couldn’t be completed. (SKErrorDomain error 2.)

iOS version: 17.3.1.
react-native-iap version: 12.10.8

@joomoodle
Copy link

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
Versión reaccionar-nativa-iap: 12.12.2

@jko12130
Copy link

jko12130 commented Jun 7, 2024

I'm having the same issue.

@nej1044
Copy link
Contributor

nej1044 commented Jul 18, 2024

I faced same problem.
Does anyone know how to fix this or what may be causing this?

hyochan pushed a commit that referenced this issue Aug 4, 2024
### 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.
dev-arrow added a commit to dev-arrow/react-native-iap that referenced this issue Nov 25, 2024
### 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants