Solved

addCustomerInfoUpdateListener not working on React Native Android


Badge +1

Hi all,

As far as I can tell from the forums and docs, this is supposed to work in terms of setting some automatic updating of the customerInfo via listeners, but I can’t make it work in my app (React Native android).

 

referring to addCustomerInfoUpdateListener() in this case..

https://www.revenuecat.com/docs/customers/customer-info#listening-for-customerinfo-updates

 

Purchases.getCustomerInfo() works but the listener which is supposed to update once the subscription time is over (5 minutes in test mode), isn’t triggering anything.

 

I’m not sure if this really has been resolved or not and would love for someone to point to some working example that I can understand, besides the docs which are relatively minimal for this use case.

 

The only thing I can think of now is to have a 5 minute setTimeout() in my app but that seems far from ideal.. :/

icon

Best answer by Ryan Glanz 8 May 2024, 19:37

View original

This post has been closed for comments

4 replies

Userlevel 4
Badge +8

Hi,

We have an example app with some more context on how to implement this: https://github.com/RevenueCat/react-native-purchases/blob/e0128b4254d5c5f7e399b8c85fad1495a3ea08db/examples/MagicWeather/src/screens/UserScreen/index.js#L35

I’d suggest taking a look at that and seeing if it matches your implementation.

 

The only thing I can think of now is to have a 5 minute setTimeout() in my app but that seems far from ideal.. :/

Yeah, don’t do that

Badge +1

Thanks. 

I’m working with React Native Android and trying something like this now based on the example you linked to:
 

const getRevCatUserDetails = async () => {

    const customerInfo = await Purchases.getCustomerInfo();

    modifyPaidStatus(customerInfo.activeSubscriptions.length > 0);

  };



  useEffect(() => {

    getRevCatUserDetails();

  }, []);



  useEffect(() => {

    Purchases.addCustomerInfoUpdateListener(getRevCatUserDetails);

    return () => {

      Purchases.removeCustomerInfoUpdateListener(getRevCatUserDetails);

    };

  });

 

Now, if I activate the subscription, see it’s active, then wait 5 minutes or more and click on some button to trigger the check like this:

const handleOnClickItem = async (item: Item) => {
await getRevCatUserDetails();
await getRevCatUserDetails(); //twice on purpose to check if status is really no active

//do stuff with item and trigger other functionality in the code, async
}

 

The subscription still active, and only resets later..
I’m not sure I understand why even after calling the method twice in a row, awaiting it regardless of listeners it should update the status, but the status does not change.. 

I must add that right after the handleOnClickItem() function ends execution, the status DOES update. So I think it’s a delay of some sort from the servers..? Dunno, this behavior seems strange.

Badge +1

Adding that even if I try something like this:

await Purchases.getCustomerInfo();
await Purchases.syncPurchases();

Purchases.getCustomerInfo().then((info) => {
modifyPaidStatus(info.activeSubscriptions.length > 0);
});

it still doesn’t update correctly...

Userlevel 4
Badge +8

Hi,

In this case what is most likely happening is that our backend is not refreshing the receipt within 5 minutes. But the receipt can be updated more quickly if you setup platform server notifications