The RNIap.getPurchaseHistory
always return an empty array. Does not matter if I call on app start or after purchase was made.
In componentDidMount
I do the following:
async componentDidMount() {
await RNIap.initConnection();
this.purchaseUpdateSubscription = purchaseUpdatedListener(
async purchase => {
try {
// send purchase to the server
const savedPurchase = await savePurchase(purchase);
// finish transaction if server returned truthly value
if (savedPurchase) {
await RNIap.finishTransaction(purchase, true);
// always returns en empty array
console.log('Purchase history', await RNIap.getPurchaseHistory())
}
} catch (e) {
console.log('Error: ', e);
}
}
});
}
buyProduct
function:
buyProduct = async productId => {
try {
await RNIap.requestPurchase(productId, false);
} catch (e) {
console.warn('Error: ', e);
}
};
When the purchase is made I receive the message:
You're all set.
Your purchase was successful
[Environment: Sandbox].
Maybe the problem can be in another place not related to the codebase?
Stumbled upon what I believe might be a solution for you:
Wrap RNIap.getPurchaseHistory() around initConnection() and an endConnection() call. Perhaps also give RNIap.finshTransaction more time to finish before requesting the purchase history to make sure the latest purchases are included.