Question

checking user subscription status with custom app id

  • 18 August 2023
  • 1 reply
  • 97 views

Badge +1

Hi there,

currently i am trying to implemented revenuecat to my flutter app. it was awesome and going so well. I am using custom app id and get the id from google sign in. To avoid creating anonymous id i implemented :

await Purchases.configure(

PurchasesConfiguration(withAPIKey: <my_api_key>)

..appUserID = "my_app_user_id");

Then User will login with google sign in and i implemented this :

LogInResult result = await Purchases.logIn(<id taken from google sign in>);

and it all going well and behave how it supposed to be. The problem comes when the the app restart and i need to know the user subscription status programatically when the app started, the code is:

await Purchases.logIn(<id taken from google sign in>);

if (customerInfo.entitlements.all["Premium Monthly"]!.isActive ==

true) {//grant premium feature}

and it turns null as the subscription checking is not active. but when i leave the login code behind like this :

if (customerInfo.entitlements.all["Premium Monthly"]!.isActive ==

true) {//grant premium feature}

it works perfectly, but the app id will be as default as "my_app_user_id" not <id taken from google sign in>

the question is does the login code (await Purchases.logIn(<id taken from google sign in>);)only used when user trying to purchase the products only and not called programmatically at the start of the app?

it brings confusion when the app id is default but the subscription is active, and when app id is logged in as  <id taken from google sign in>, subscription will be null.

Thank You

 

 


1 reply

Userlevel 4
Badge +6

Hey @hardi !

 

When you are calling login in this situation, you are essentially switching the account app user ID to a new account (logged in account). In this case, I would recommend waiting till you have the ID wanted from Google, then calling configure with that ID once you get it so you dont need to call the login method. 

it brings confusion when the app id is default but the subscription is active, and when app id is logged in as  <id taken from google sign in>, subscription will be null.

This might be happening due to how the aliasing and customerInfo is transferred for the user once logged in. I recommend referring to this chart to make sure that the process is right using login for the state that your app is in when it is called. 

 

Also, if a user with a subscription is not seen, you can restorePurchases in order to re-sync the receipt on the device and regrant your entitlements. You can do this programatically by calling syncPurchases, so you could also call this for the user when needed. 

Reply