You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purchase window keeps appearing again and again, creating an infinite loop.
I didn't click the purchase button again. It just keeps popping up again and again even after saying it's done.
Expected Behavior
The purchase should be done after being executed once.
Environment:
react-native-iap: ^12.13.1
react-native: 0.73.6
Platforms: iOS Simulator - iPhone SE (3rd generation) (iOS 17.4)
To Reproduce
My code is as follows:
import{Platform,Text,TouchableOpacity,View}from"react-native";import{initConnection,purchaseErrorListener,purchaseUpdatedListener,flushFailedPurchasesCachedAsPendingAndroid,requestPurchase,getProducts,}from"react-native-iap";import{useEffect,useState}from"react";constShop=()=>{const[purchaseUpdateSubscription,setPurchaseUpdateSubscription]=useState(null);const[purchaseErrorSubscription,setPurchaseErrorSubscription]=useState(null);const[products,setProducts]=useState([]);useEffect(()=>{initIAP();return()=>{if(purchaseUpdateSubscription){purchaseUpdateSubscription.remove();setPurchaseUpdateSubscription(null);}if(purchaseErrorSubscription){purchaseErrorSubscription.remove();setPurchaseErrorSubscription(null);}};},[]);constinitIAP=async()=>{try{constinitialized=awaitinitConnection();if(initialized){console.log("initialized");// THIS IS SUCCESSFULLY PRINTEDconstproducts=awaitgetProducts({skus: ["product_id_1","product_id_2","product_id_3","product_id_4","product_id_5"],});setProducts(products);// THIS IS SUCCESSFULLY PRINTEDif(Platform.OS==="android"){// we make sure that "ghost" pending payment are removed// (ghost = failed pending payment that are still marked as pending in Google's native Vending module cache)constflushed=awaitflushFailedPurchasesCachedAsPendingAndroid();console.log(flushed);}constupdatedListener=purchaseUpdatedListener((purchase)=>{console.log("purchaseUpdatedListener",purchase);// THIS IS NEVER GETTING PRINTEDconstreceipt=purchase.transactionReceipt;if(receipt){console.log(receipt);}});setPurchaseUpdateSubscription(updatedListener);consterrorListener=purchaseErrorListener((error)=>{console.log("purchaseErrorListener",error);if(error.code!=="E_USER_CANCELLED"){alert(error.message);}});setPurchaseErrorSubscription(errorListener);}else{alert("Could not initialize payment");}}catch(error){console.log(error);alert(error);}};constpurchase=async(sku)=>{try{constresult=awaitrequestPurchase({
sku,andDangerouslyFinishTransactionAutomaticallyIOS: false,});console.log(result);// THIS IS NEVER GETTING PRINTED}catch(err){console.warn(err.code,err.message);}};return(<>{products.map((product)=>(<TouchableOpacityonPress={()=>purchase(product.productId)}><Text>{product.title}</Text></TouchableOpacity>))}</>);};exportdefaultShop;
The console.log(result) inside purchase method never gets printed
The text was updated successfully, but these errors were encountered:
Description
The purchase window keeps appearing again and again, creating an infinite loop.
I didn't click the purchase button again. It just keeps popping up again and again even after saying it's done.
Expected Behavior
The purchase should be done after being executed once.
Environment:
To Reproduce
My code is as follows:
The
console.log(result)
insidepurchase
method never gets printedThe text was updated successfully, but these errors were encountered: