iaphub / react-native-iaphub

The easiest way to implement IAP (In-app purchase) in your React Native app.
https://www.iaphub.com/
MIT License
319 stars 21 forks source link

'undefined' being returned by `await Iaphub.restore()` #71

Closed millisecond closed 3 years ago

millisecond commented 3 years ago

Trying to test the restore functionality on Android for my new app and getting an odd undefined from restore.

Inside an async function initiated by a user click I'm calling restore() like this:

let transactions = await Iaphub.restore();
console.log("transactions", transactions);

The result is coming across as "undefined", which a quick google search says can happen when an async function just doesn't return anything but not sure what I could be doing wrong here as there are no args to restore and purchases generally are working great.

My test sequence:

Expected that I'd receive a transaction array I can process.

iaphub commented 3 years ago

Hey @millisecond,

The restore method isn't returning any transactions, so it's totally normal you're having undefined. I'm closing the issue but you can still reply if you need additional information.

millisecond commented 3 years ago

In general it seems like empty array or null would be a better return value, but in the test case I outlined shouldn't there be a transaction returned? There's an active purchase for the device, purchasing a new sub doesn't work because there's another active sub and restore also doesn't work. A user in this scenario would be totally stuck.

iaphub commented 3 years ago

It is normal the restore method isn't returning anything (as you can see on the example of our README) but it does a lot of things.

When you do a restore the receipt of the user is refreshed and a few things will happen depending on the situation:

Please note as well that if you're doing the restore with a different user id, the user_id_update webhook will be triggered: https://www.iaphub.com/docs/webhooks/user-id-update

millisecond commented 3 years ago

OK, cool. I was going off the function docs on restore() and that wasn't clear to me. But it's working now if I call getActiveProducts() after getting undefined from restore().

Thanks!