如何修复 'yourAPI is not defined'

How to fix 'yourAPI is not defined'

我最近在做react-native-iap。 在工作时,我 运行 遇到了这个问题。 'yourAPI is not defined'

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'?

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