用户如何对本机应用内购买(非第 3 版)做出反应?

How to user react native in-app purchase (NOT version 3)?

我正在尝试使用 react-native-iap(版本 2.4.3)开发一个应用内购买应用。

安装顺利,产品演示 "android.test.purchase" 运行良好。 (它显示带有模拟付款的假签证)。

但是当我在 Google Developer Console -> in-app products -> 中创建 ID 为 item_1 managed products 然后将其添加到我的应用程序,该应用程序显示以下错误:

我们这边出了点问题。请重试。

注 1:应用程序已于 Play Store.

上线

注 2:应用发布为 com.danielemenchetti.inapppurchase

这里我post我的代码:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { Button } from 'react-native';

import * as RNIap from 'react-native-iap';

const items = Platform.select({
  ios: [
   'android.test.purchase'
  ],
  android: [
   'android.test.purchase', 
   'com.danielemenchetti.inapppurchase.item_1' 
  ]
 });


export default class App extends Component {

  constructor(props){
    super(props);
    this.state={
      count:0
    }
  }

  componentDidMount() {
    RNIap.initConnection();
    RNIap.getProducts(items).then((products) => { 
    //handle success of fetch product list
    }).catch((error) => {
      console.log(error.message);
    })

  }


  buyExample = () => { 
    RNIap.buyProduct('android.test.purchased').then(purchase => {
      this.setState({count: this.state.count+1});
      console.log("State: " + this.state.count);

      RNIap.consumePurchase(purchase.purchaseToken);
      console.log(purchase);

    }).catch((error) => {
      console.log("Catch: " + error.message);
    })
  }

  buyItem1 = () => { 
    RNIap.buyProduct('com.danielemenchetti.inapppurchase.item_1').then(purchase => {

      this.setState({count: this.state.count+1});
      console.log("State: " + this.state.count);

      RNIap.consumePurchase(purchase.purchaseToken);
      console.log(purchase);

    }).catch((error) => {
      console.log("Catch: " + error);
    })
  }

  render() {
    return (
      <View style={styles.container}>

        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <View style={{flexDirection:'row',marginTop: 15,}}>
          <View>
            <Button
              onPress={this.buyExample}
              title="Buy Example"
              color="#841584"
              accessibilityLabel="Buy more about this purple button"
            />
          </View>

          <View style={{marginLeft:15}}>
            <Button
              onPress={this.buyItem1}
              title="Buy Item 1"
              color="#841584"
              accessibilityLabel="Buy more about this purple button"
            />
          </View>
        </View>

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

如果real-native-iap使用模块,您只需要填写您在注册产品时创建的product id值。您不必一起写 your package name

测试创建的测试 ID 值是名称的指南。

如果您的产品 ID 是“item_1

const items = Platform.select({
  ios: [
   'android.test.purchase'
  ],
  android: [
   'android.test.purchase', 
   'item_1' 
  ]
 });