如何修复“未定义您的API”

时间:2019-08-02 13:30:45

标签: javascript react-native react-redux in-app-purchase

我现在正在研究react-native-iap。 在工作时,我遇到了这个问题。 “未定义您的API”

import RNIap, {
  purchaseErrorListener,
  purchaseUpdatedListener,
  type ProductPurchase,
  type PurchaseError
} from 'react-native-iap';

class RootComponent extends Component<*> {
  purchaseUpdateSubscription = null
  purchaseErrorSubscription = null

  componentDidMount() {
    this.purchaseUpdateSubscription = purchaseUpdatedListener((purchase: ProductPurchase) => {
      console.log('purchaseUpdatedListener', purchase);
      const receipt = purchase.transactionReceipt;
      if (receipt) {
        yourAPI.deliverOrDownloadFancyInAppPurchase(purchase.transactionReceipt)
        .then((deliveryResult) => {
          if (isSuccess(deliveryResult)) {

            if (Platform.OS === 'ios') {
              RNIap.finishTransactionIOS(purchase.transactionId);
            } else if (Platform.OS === 'android') {
              // If consumable (can be purchased again)
              RNIap.consumePurchaseAndroid(purchase.purchaseToken);
              // If not consumable
              RNIap.acknowledgePurchaseAndroid(purchase.purchaseToken);
            }
          } else {
            // Retry / conclude the purchase is fraudulent, etc...
          }
        });
      }
    });

    this.purchaseErrorSubscription = purchaseErrorListener((error: PurchaseError) => {
      console.warn('purchaseErrorListener', error);
    });
  }

  componentWillUnmount() {
    if (this.purchaseUpdateSubscription) {
      this.purchaseUpdateSubscription.remove();
      this.purchaseUpdateSubscription = null;
    }
    if (this.purchaseErrorSubscription) {
      this.purchaseErrorSubscription.remove();
      this.purchaseErrorSubscription = null;
    }
  }
}

在这里我不确定“ yourAPI.deliverOrDownloadFancyInAppPurchase”是什么? 请帮助,任何了解'yourAPI'的人吗?

1 个答案:

答案 0 :(得分:0)

这实际上是您的api :)这意味着在通过本机应用程序内购买购买产品时,您要调用api(后端)。在游戏中的四个示例中,您可以通过应用内购买向游戏玩家出售入门包,首先,用户需要为此入门包向Google Play或应用商店支付价值。并且您应该知道此操作是否成功完成,并且应该将此入门工具包提供给用户。为此,您应该像backendApi.sold(purchase.transactionReceipt).then((result) => {});

这样的监听器中进行呼叫