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

How to check which plan is user subscribed to #727

Closed
sidpauhal opened this issue Sep 23, 2019 · 9 comments
Closed

How to check which plan is user subscribed to #727

sidpauhal opened this issue Sep 23, 2019 · 9 comments
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS ❓ question Further information is requested 🚶🏻 stale Stale

Comments

@sidpauhal
Copy link

Version of react-native-iap

"react-native-iap": "^3.4.4",

Version of react-native

"react-native": "0.60.5",

Platforms you faced the error (IOS or Android or both?)

both

I have added monthly autorenewal subscription plans in Google play dashboard
Silver, Gold, Platinum

I am subscribing users like this
const products = await RNIap.requestSubscription('gold_membership');

I want to check which plan is user subscribed to and display in app that he is a Gold or silver member.

As mentioned in docs RNIap.getAvailablePurchases(); returns all purchases

but I want to check which subscription plan is user currently subscribed to.

Any help, guidance ?

@kevinetore
Copy link

@sidpauhal This could be interesting.

@hyochan hyochan added 🙏 help wanted Extra attention is needed 📱 iOS Related to iOS ❓ question Further information is requested labels Sep 25, 2019
@sidpauhal
Copy link
Author

sidpauhal commented Sep 26, 2019

@kevinetore In android I am doing like this

const itemSkus = Platform.select({
	ios: [
		'silver_membership', 'gold_membership', 'platinum_membership'
	],
	android: [
		'silver_membership', 'gold_membership', 'platinum_membership'
	]
});

const purchases = await RNIap.getAvailablePurchases();
if(purchases !== null && purchases.length > 0){
	let current_plan = 'free';
	for (var i = 0; i < itemSkus.length; i++) {
		for (var j = 0; j < purchases.length; j++) {
			if(purchases[j].productId == itemSkus[i] && purchases[j].autoRenewingAndroid == true){
				current_plan = purchases[j].productId;
				break;
			}
		}
		if(current_plan != 'free'){
			break;
		}
	}
	this.update_subscription(current_plan);
}

I think this is not possible in IOS
Any help?
If it is not possible in IOS I will try another lib
react-native-in-app-utils

@kevinetore
Copy link

kevinetore commented Sep 27, 2019

@sidpauhal Why wouldn't it be possible in iOS? If I'm correct I think you'd only need to figure out something for autoRenewingAndroid on iOS. Other than that you should be fine. I don't have much experience with react-native-iap yet, currently doing some research on how to implement IAP. Also, this answer might help.

@sidpauhal
Copy link
Author

@kevinetore @hyochan can we get product id from ios receipt
I have to check which plan is user susbcribed to?

something like this
const renewalHistory = receipt.latest_receipt_info
const expiration = renewalHistory[renewalHistory.length - 1].expires_date_ms
if(expiration > Date.now()){
current_active_plan = receipt.product_id
}

@hyochan
Copy link
Owner

hyochan commented Nov 24, 2019

@sidpauhal I am not sure about this. However, I've been saving receipt and productId together in my backend database so I didn't have any situation like this.

@stale
Copy link

stale bot commented Feb 22, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the 🚶🏻 stale Stale label Feb 22, 2020
@stale
Copy link

stale bot commented Mar 23, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Mar 23, 2020
@hanishcodebrew
Copy link

I am looking for the same answer in Android. Please help.

@daba-faith
Copy link

@sidpauhal I am not sure about this. However, I've been saving receipt and productId together in my backend database so I didn't have any situation like this.

Receipt is always different everytime a user tries to purchase, even when the user is already subscribed to the product, a new receipt is generated 🥲, how do we go about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS ❓ question Further information is requested 🚶🏻 stale Stale
Projects
None yet
Development

No branches or pull requests

5 participants