0

我可以使用 FlutterInappPurchase 从 Play 商店获取产品数据,但无法进行购买。关注详情;

我正在使用flutter_inapp_purchase @2.2.0

我在模块的 go page 上分享了它,但我想吸引更多的观众。因为我解决不了资源不足的问题。

我的代码的工作过程;

  • 购买过程在对话框中进行。
  • 我从我的 API 服务中读取了对话框单独的小部件和用于购买的信息(productId 等)。
  • 我将这些数据放入List<IAPItem> _items = []initStates 的变量中,然后连接插件。
  • 记录我打印以确保我打印。我确信我可以从 API 中提取数据!
Setting.productLists:: [io.kr.english.course.purchase.all.3, io.kr.english.course.purchase.all.2, io.kr.english.course.purchase.all.1]
  • 返回consumerAllItems日志
I/flutter ( 3947): consumeAllItems error: PlatformException(consumeAllItems, refreshItem, No purchases found)
  • 但是后来我的_getProduct()功能起作用了,我可以在日志屏幕上看到产品。
    • 样品退货产品数据日志;
SUBSCRIPTION_ID:: productId: io.kr.english.course.purchase.all.1, price: 1.19, currency: TRY, localizedPrice: ₺1,19, title: 1 Aylık (Keyrote), description: 1 Aylık eğitim paketi, introductoryPrice: , introductoryPricePaymentModeIOS: , subscriptionPeriodNumberIOS: null, subscriptionPeriodUnitIOS: null, introductoryPricePaymentModeIOS: null, introductoryPriceNumberOfPeriodsIOS: null, introductoryPriceSubscriptionPeriodIOS: null, subscriptionPeriodAndroid: P1M, introductoryPriceCyclesAndroid: , introductoryPricePeriodAndroid: , freeTrialPeriodAndroid: , iconUrl: , originalJson: {"skuDetailsToken":"AEuhp4Ibjcl0f_I9C1Apvz79Dzgbd_tPs3Rn4vxtBF2dpLKwsnJYvyTR10Gc_CvI7Z2C","productId":"io.kr.english.course.purchase.all.1","type":"subs","price":"₺1,19","price_amount_micros":1190000,"price_currency_code":"TRY","subscriptionPeriod":"P1M","title":"1 Aylık (Keyrote)","description":"1 Aylık eğitim paketi"}, originalPrice: {"skuDetailsToken":"AEuhp4Ibjcl0f_I9C1Apvz79Dzgbd_tPs3Rn4vxtBF2dpLKwsnJYvyTR10Gc_CvI7Z2C","pr
  • 当我触摸按钮时,我进行了购买;它说“糟糕;找不到您尝试购买的商品”,当我触摸绿色的“确定”按钮时,日志如下;
W/ProxyBillingActivity( 3947): Activity finished with resultCode 0 and billing's responseCode: 4
W/BillingHelper( 3947): Couldn't find purchase lists, trying to find single data.
W/BillingHelper( 3947): Received a bad purchase data.
W/BillingHelper( 3947): Couldn't find single purchase data as well.
E/DoobooUtils( 3947): Error Code : 4
I/flutter ( 3947): purchase-error: responseCode: 4, debugMessage: , code: E_ITEM_UNAVAILABLE, message: That item is unavailable.

产品已附加并在 google play 中处于活动状态。

我无法解决的资源并不多。提前感谢您的帮助,我希望它是描述性的。


如果我需要共享与我在互联网上找到的相同的代码,您可以在下面关注它们。

将 iAP 连接到服务

Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await FlutterInappPurchase.instance.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    var result = await FlutterInappPurchase.instance.initConnection;
    print('result: $result');

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });

    try {
      String msg = await FlutterInappPurchase.instance.consumeAllItems;
      print('consumeAllItems: $msg');
    } catch (err) {
      print('consumeAllItems error: $err');
    }

    _conectionSubscription = FlutterInappPurchase.connectionUpdated.listen((connected) {
      print('connected: $connected');
    });

    _purchaseUpdatedSubscription = FlutterInappPurchase.purchaseUpdated.listen((productItem) {
      print('purchase-updated: $productItem');
    });

    _purchaseErrorSubscription = FlutterInappPurchase.purchaseError.listen((purchaseError) {
      print('purchase-error: $purchaseError');
    });

    await this._getProduct();
  }

获取产品

Future _getProduct() async {
    List<IAPItem> items = await FlutterInappPurchase.instance.getSubscriptions(_productLists);
    for (var item in items) {
      print('SUBSCRIPTION_ID:: ${item.toString()}');
      this._items.add(item);
    }

    setState(() {
      this._items = items;
      this._purchases = [];
    });
  }

购买产品

Future _buyProduct(IAPItem item) async{
    log.just("_buyProduct.item.id:: ${item.productId.toString()}");
    try {
      PurchasedItem purchased = await FlutterInappPurchase.instance.requestSubscription(item.productId);
      log.just("_buyProduct.purchased:: ${purchased.toString()}");
      String msg = await FlutterInappPurchase.instance.consumeAllItems;
      log.just("_buyProduct.msg:: $msg");
    } catch (error) {
      log.just('_buyProduct.catch:: $error');
    }
  }

初始化状态

  @override
  void initState() {
    super.initState();

    _productLists = [];
    for(var i = 0; i < widget.pricingItemData.length; i++){
      _productLists.add(widget.pricingItemData[i]['product_id'].toString());
    }

    log.just('Setting.productLists:: ${_productLists.toString()}');

    initPlatformState();

    _pageController = new PageController(initialPage: 0);
    selectedIndex = 0;
  }

购买操作代码

this._buyProduct(this._items[selectedIndex]);

颤振医生-v

[√] Flutter (Channel beta, v1.17.0-3.2.pre, on Microsoft Windows [Version 10.0.18362.778], locale en-US)
    • Flutter version 1.17.0-3.2.pre at C:\src\flutter
    • Framework revision 2a7bc389f2 (10 days ago), 2020-04-21 20:34:20 -0700
    • Engine revision 4c8c31f591
    • Dart version 2.8.0 (build 2.8.0-dev.20.10)


[!] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc2)
    • Android SDK at C:\Users\fatih\AppData\Local\Android\Sdk
    • Platform android-29, build-tools 30.0.0-rc2
    • ANDROID_HOME = C:\Users\fatih\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.0.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code (version 1.44.2)
    • VS Code at C:\Users\fatih\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.9.1

[√] Connected device (3 available)
    • Venus GO   • 2811389118001055 • android-arm    • Android 8.1.0 (API 27)
    • Chrome     • chrome           • web-javascript • Google Chrome 81.0.4044.129
    • Web Server • web-server       • web-javascript • Flutter Tools

! Doctor found issues in 1 category.
4

1 回答 1

0

FlutterInappPurchase.instance.requestSubscriptions 方法在 android 上需要第二个参数:

/// 请求订阅Androidor iOS

/// 结果将在purchaseUpdated监听器或purchaseError监听器中接收。

/// ///注意第二个参数是必需的Android。///

/// 与 [requestPurchase] on 相同iOS

未来 requestSubscription(String sku, { String oldSkuAndroid, int prorationModeAndroid, String developerIdAndroid, String accountIdAndroid, }) async {

if (_platform.isAndroid) {
  return await _channel
      .invokeMethod('buyItemByType', <String, dynamic>{
    'type': EnumUtil.getValueString(_TypeInApp.subs),
    'sku': sku,
    'oldSku': oldSkuAndroid,
    'prorationMode': prorationModeAndroid ?? -1,
    'developerId': developerIdAndroid,
    'accountId': accountIdAndroid,
  });

} else if (_platform.isIOS) {
  return await _channel.invokeMethod(
    'buyProduct', <String, dynamic>{
    'sku': sku,
  });
}

throw PlatformException(
    code: _platform.operatingSystem, message: "platform not supported");

}

于 2020-11-24T20:21:27.650 回答