Question

Setting Up a perfect Listener

  • 3 August 2023
  • 2 replies
  • 104 views

Badge +3
CollectionReference<Map<String, dynamic>> usersRef =FirebaseFirestore.instance.collection("data");
Future<void> purchaseGoldPackage(Package package) async {  try {    await Purchases.purchasePackage(package).then((customerInfo) async {      await Purchases.syncPurchases();      usersRef          .doc(        userID,      )          .update({        'status': 'gold',      });    });  } catch (e) {}}

 

The code above is how i set a listener for a new customer subscription,  then calling firestore to update a fieldValue “status” from ‘free’ to ‘gold’, which is how multiple devices get notified a purchase was made and the subscription is active.

This works 5 out of 10 times,  which means i maybe half way there,  

The issue is firestore update method dont get called  half the time, leaving user with multiple devices hanging. which means the listener i set up for firestore which updates the UI of user devices wont get triggered, forcing users to restart app to see subscription changes, even though users still get what they paid for.

could someone please tell me if i set my RC listener the wrong way ? and if i don’t need to involve firestore sdk to get multiple devices to update app UI as soon as a purchase was successful


thanks!


2 replies

Badge +3
CollectionReference<Map<String, dynamic>> usersRef =FirebaseFirestore.instance.collection("data");
Future<void> purchaseGoldPackage(Package package) async{try{await Purchases.purchasePackage(package).then((customerInfo) async{await Purchases.syncPurchases();usersRef.doc(userID).update({'status': 'gold'});});} catch (e) {}}

 

The code above is how i set a listener for a new customer subscription,  then calling firestore to update a fieldValue “status” from ‘free’ to ‘gold’, which is how multiple devices get notified a purchase was made and the subscription is active.

This works 5 out of 10 times,  which means i maybe half way there,  

The issue is firestore update method dont get called  half the time, leaving user with multiple devices hanging. which means the listener i set up for firestore which updates the UI of user devices wont get triggered, forcing users to restart app to see subscription changes, even though users still get what they paid for.

could someone please tell me if i set my RC listener the wrong way ? and if i don’t need to involve firestore sdk to get multiple devices to update app UI as soon as a purchase was successful


thanks!

 

**** Had to repost this, the formatting was terrible from the original post*****

Userlevel 4
Badge +6

Hey @Notorious Dev ,

 

We have a useful document which goes over how to. set up a listener for subscription updates so the status of your app is always correct.

Using the links above, perhaps you could use our recievedUpdated listenter to trigger the firestore update, that work each time we receive an update so there shouldnt be a discrpenecy between the data from RC and what is sent to Firebase.

 

Let me know if that helps! 

Reply