Solved

How to use syncPurchases() in React Native

  • 3 January 2022
  • 2 replies
  • 24 views

Badge

I migrated my app to RC, however my previous users are having the sync problem.

Previously, I was not using a back-end for the subscriptions, so I was using the client-side receipt validation on iOS (React Native IAP package).

I am trying to sync my previous users, but a little bit confused about the steps;

if (isSubscribedInOldSystem && !isSubscribedInRevenueCat) {

Purchases.syncPurchases();

}

 

1 - What should I provide to the syncPurchases() function?

2 - If I need to provide the receipt, should I provide full receipt? or just the receipt body? I mean, I was using this validation method;

const receiptBody = {
'receipt-data': receipt, // Should I provide this to RC?
password: 'PASSWORD',
};

await IAP.validateReceiptIos(receiptBody, false)
.then(response => {
try {
const renewalHistory = response.latest_receipt_info;
const expirationDate = renewalHistory[0].expires_date_ms;
const isExpired = Date.now() > expirationDate;

if (!isExpired) {
setIsUserHasReceiptOLD(true);
}
} catch (error) {
}
})
.catch(e => {
});

 

Thank you in advance,

Best,

Uğur

icon

Best answer by tina 7 January 2022, 20:30

View original

2 replies

Userlevel 4
Badge +9

Hey @Ugur Genc 

I’ll answer your questions in-line below:

1 - What should I provide to the syncPurchases() function?

You don’t need to provide anything to the syncPurchases() function. You can just call that method as is and RevenueCat will sync the receipt from the device to our servers. The only thing you need to handle is figuring out if the customer has a subscription in your old subscription system.

 

2 - If I need to provide the receipt, should I provide full receipt? or just the receipt body? I mean, I was using this validation method;

No receipt necessary. If you are already collecting receipts in your backend, you can always perform a server side migration and send the receipt to us directly. For more information: https://docs.revenuecat.com/docs/migrating-existing-subscriptions#importing-existing-data 

 

Badge

Thank you, Tina for the tips. Now, it works really well.

Reply