irfan
irfan

Reputation: 102

React Native | react-native-iap

It is the first time that I use react-native-iap in my project. I installed the library without any problems. I have a few questions.

  1. My code block is below for a single product purchase. Is this usage right now?
import * as RNIap from 'react-native-iap';

const itemSkus = Platform.select({
    ios: ['stackoverflow_ex'],
    android: ['stackoverflow_ex']
});

export default class Buy extends Component {

    state= {
        products:[],
        count:0
    }

    async componentDidMount() {
        try {
            const products: Product[] = await RNIap.getProducts(itemSkus);
            this.setState({ products });
        } catch(err) {
            console.warn(err); // standardized err.code and err.message available
        }
    }

    requestPurchase = async (sku: string) => {
        try {
            await RNIap.requestPurchase(sku, false);
            this.setState({ count:this.state.count+1 });
        } catch (err) {
            console.warn(err.code, err.message);
        }
    }

    click = () => {
        this.requestPurchase('stackoverflow_ex') 
    }

    render() {
        const {item} = this.props;
        return (
            <TouchableOpacity onPress={() => this.click()} />
        );
    }
}
  1. How do I get a return from the 'RNIap.requestPurchase (sku, false)' function? For example: const result = RNIap.requestPurchase (sku, false);
  2. The above code works to a certain extent for IOS. Clicking 'Apple Home Page' comes to the payment process. Nothing happens after filling it there. Not doing in Count + 1. Is it because it says 'Ready to Submit' next to the product I added to Apple Connect? Will Apple approve this product? Should I wait for him?
  3. Products are coming in iOS. The empty list on Android is returning. Should I upload it to open beta and try it?

Upvotes: 2

Views: 3073

Answers (2)

ninjaboy
ninjaboy

Reputation: 300

From the first glance, I would say that at least initConnection is missing. The best way to make sure the code is done correctly check out example in the github: https://github.com/dooboolab/react-native-iap/blob/master/IapExample/App.js

Upvotes: 0

Amila Dulanjana
Amila Dulanjana

Reputation: 1914

For android you need to upload your apk in Google play. if not then you cannot test Google play billing in your application. What you can do is upload the apk and do a release under Internal test track. It will take 2-3 days for the review process. After that you can do the testing.

For more read please check this link

Upvotes: 1

Related Questions