-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
How I can get the subscription status? #2631
Comments
You can use the availablePurchases method to get |
@yhostc getAvailablePurchases returns the all purchases being IAP or Subscriptions, right? Edit: I found the "onlyIncludeActiveItems" on docs. This solves the issue of not getting a expired subscribe, right? |
I'm finding this quite confusing. getAvailablePurchases is only documented as a function returned by the useIAP hook. Nothing is said in the docs about what it does. But according to its type, It doesn't accept any parameter. Internally it calls a getAvailablePurchases function accepting an object with several config parameters like onlyIncludeActiveItems (which has a default value of true). That function is also exported, although no reference is written to it in the docs. So I'm not sure if it's intended to be used (maybe for backwards compatibility?) but if it is, it should return only active items unless specified false explicitely. Finally, there is this section in the troubleshooting page. I don't get if this is a warning for iOS only but it leads me to think that there is no way of knowing for certain if a user has an active subscription from the app. Because getAvailablePurchases is going to return an empty array anyway... or maybe not? If you try the newly published IapExample app based on react native 0.72, you can see some confusing behaviour. Just buy a subscription and quit the app. You have now an active subscription. Open the app again and go to the Subscriptions page so the finishTransaction function is called, and quit again. Can anyone in the know shed some light on this? |
@jordibuj After reading the implementation, both functions has the same name, but they are not the same. The one from the getAvailablePurchases from useIAP is calling the getAvailablePurchases that you can import direcly form reac-native-iap import. But the useIAP hook instead return directly the value, its being setted inside setAvailablePurchases from useIAP hook. look the useIAP definition:
on the second import, notice the If you go to the definition of getAvailablePurchases , will be the same file as the one that you can import directly. From this, i don't know whats happening actually, but maybe the visualization is changing because you seeing the value through Not sure if that answer the confusion, but was what i could find. |
For update if someone in the future see this about my doubt: I found my answer. When importing the props don't say nothing because JSDocs of the function is not properly configured. But the description of the props are there in the definition: https://github.com/dooboolab-community/react-native-iap/blob/e67a52e/src/iap.ts#L464 It says is IOs Only this parameter. I think i will need to test buying my own subscription on my app and let the time pass to see how this function behave on android by default, since is being hard to find this info on other issues or docs.
|
How I can get the subscription status in 2024? |
1: Retrieve all purchases from the user. You gonna receive an array of purchases (Be sure to be connected to the store). Example:
|
but await getAvailablePurchases() nothing return |
Oh, that's a nice question. And you half correct, as I am half correct as well. That's because we thinking about distincts "getAvailablePurchases" functions. And I should leave this explicit. The first The second In resume:
I don't know why, but I suppose that must be for flexibility purposes, in case you want to create a logic that is not connected to a hook, not forcing you to use inside components. |
I updated my example to be less confusing |
@Vittor-Javidan thank you for all your replies, much appreciated. But it's method work? Example your code:
=> [Error: An unknown error occurred]
=> [] may be I need special way for buy subscription or finishTransaction that package return.
Thanks. |
When you call If your goal is retrieve the available subscriptions to allow the user to buy them, the code will be another. Because you will need to have a component that will represent your store inside your app. Inside that component you gonna at least need: 1: A hook to connect and disconnect the store. In that case, all you need are inside the |
|
The current purchase and purchase error hooks are already given on documentation. For example:
|
How I can get the subscription status?
The text was updated successfully, but these errors were encountered: