iOS in app purchase finishing before server returns

I am using the expo in-app purchases library.
Hello everyone! I can’t seem to be able to have finishTransactionAsync() be called after a successful response is got from my server (my server checks if the receipt is valid, if it has been used, and gives the reward).
I have tried to put it in the .then() function after my api call, however, when it gets to it, it says an error saying that I must be connected to the app store for it to complete.

with the current configuration below, it has the same problem with saying that I am no longer connected to the app store when it gets to the finishTransactionAsync function call.

If I run the configuration below without the awaits and asyncs, then it does not return my API call before it completes the transaction, and my backend gets a completed transaction receipt from apple.

Any advice? I have spent a couple days on this and can’t figure it out.

Thank you!

async function IAP(productID) {
await InAppPurchases.connectAsync();
const { responseCode, results } = await InAppPurchases.getProductsAsync(

// Set purchase listener
await InAppPurchases.setPurchaseListener(
async ({ responseCode, results, errorCode }) => {
// Purchase was successful
if (responseCode === InAppPurchases.IAPResponseCode.OK) {
await results.forEach(async (purchase) => {
if (!purchase.acknowledged) {
// Process transaction here and unlock content…
await makeInAppPurchase
.then( (res) => {
//mark as purchase complete
//FIXME might not be waiting for api call to complete. that would be bad.
InAppPurchases.finishTransactionAsync(purchase, true);


} else {
// Else find out what went wrong
if (responseCode === InAppPurchases.IAPResponseCode.USER_CANCELED) {
console.log(“User canceled the transaction”);
} else if (responseCode === InAppPurchases.IAPResponseCode.DEFERRED) {
“User does not have permissions to buy but requested parental approval (iOS only)”
} else {
Something went wrong with the purchase. Received errorCode ${errorCode}
console.log("PRODUCT ID: ", productID);
await InAppPurchases.purchaseItemAsync(productID);

await InAppPurchases.disconnectAsync();