dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.74k stars 633 forks source link

not able to make a purchase from amazon app store #1316

Closed andychikhany closed 3 years ago

andychikhany commented 3 years ago

Please use Discussion board if you want get some help out of it. Please report issue if there is a bug.

i understand that Amazon support is still beta but any help would be appreciated...

Version of react-native-iap

"react-native-iap": "^6.0.3",

Version of react-native

"react-native": "0.63.3",

Platforms you faced the error (IOS or Android or both?)

Android amazon fireOS

Expected behavior

user to subscribe

Actual behavior

app get freezes and log show a warning [Error: purchase is not assigned]

Tested environment (Emulator? Real Device?)

Real kindle fire tablet

code snippet

prepIAP = async () => { const productIds = Platform.select({ android: [ 'xxxx.subscription.weekly', 'xxxx.subscription.monthly', 'xxxx.subscription.annually', ] });

    if (__DEV__) {
        await RNIap.setFallbackInstallSourceAndroid(RNIap.InstallSourceAndroid.AMAZON);
      }

    try {
        await RNIap.initConnection()
        const products = await RNIap.getProducts(productIds);
        this.setState({amazonProducts:products})
        this.detectStoreOffers()
    } catch(err) {
        console.warn('error connecting to store',err); // standardized err.code and err.message available
    }
    try {
        RNIap.getPurchaseHistory().catch(()=>{}).then((res)=>{
            try {
                const receipt = res[res.length -1].transactionReceipt
            } catch (error) {

            }
        })
    } catch (error) {

    }

    purchaseUpdateSubscription = RNIap.purchaseUpdatedListener((purchase)=>{
            this.props.doSubscribe(true)
            console.log('777777777777777777777777777777777777777777', purchase)
            this.props.navigation.goBack()
    })

    purchaseErrorSubscription = RNIap.purchaseErrorListener((error)=>{
        if(!(error['responseCode'] === '2')){
            Alert.alert('Error', 'There has been an error with your purchase, error code' + error['code'])
        }
    })

    return () => {
        try{
            purchaseUpdateSubscription.remove()
        }catch(e){

        }

        try{
            purchaseErrorSubscription.remove()
        }catch(e){

        }

        try{
            RNIap.endConnection()
        }catch(e){

        }
    }

}
andychikhany commented 3 years ago

the issue was because im using revenue cat and RNiap in the same function .....