Question

Does syncPurchases return anything?

  • 1 December 2023
  • 3 replies
  • 68 views

Badge +1

Just switched to RevenueCat and added some code (React Native) to sync past purchases. It works great, but synced customers don’t have all of the attributes I’ve set up for new purchases.

First thought was to check if syncPurchases returns something, and use that to call Purchases.setAttributes.

purchaseInfo = await Purchases.syncPurchases();
if(purchaseInfo){
console.log(purchaseInfo);
}

For me, it’s only returning “undefined”. Does it return something if there’s a valid receipt? If not, can I just throw in a Purchases.setAttributes before or after calling syncPurchases, so that these synced users get the proper identifiers?


3 replies

Userlevel 4
Badge +6

Hey @dcollins,

`syncPurchases` should return a customerInfo object back, regardless of if the user has made purchases or not. Additionally, I’d probably recommend calling setAttributes before syncPurchases - subscriber attributes are only synced with RevenueCat servers when Purchases.configure() is called, app backgrounded, and when purchases are made or restored so doing it in this order should allow the new attributes to sync with RevenueCat along with the past purchases. 

 

Badge +1

Hey @kaitlin

Thanks for the reply! I’ll definitely add the setAttributes before sync - thank you.

Unfortunately, it still looks like syncPurchases doesn’t return anything. I guess it doesn’t matter as much if I’m adding the setAttributes ahead of time… but just for your reference, the following code returns “nope” every time for me:

 

const customerInfo = await Purchases.syncPurchases();

if(customerInfo){

console.log(customerInfo);

} else {

console.log('nope')

}

Badge +1

Just a follow-up if anyone stumbles across this;

After adding setAttributes before sync, my app constantly throws the error:

Error - There is no singleton instance. Make sure you configure Purchases before trying to get the default instance.

 

I modified my code so that configuring of Purchases and any relevant RC code only happens in an HOC that wraps the app. Still get this error, so I’ll be reverting the addition of setAttributes before sync and anything else.

Reply