应用内购买在升级到 in_app_purchase 3.1.7 后出现错误,报告提供的令牌为空。

huangapple go评论78阅读模式
英文:

In app purchase give error offer token is null after upgrade package to in_app_purchase 3.1.7

问题

我已在我的Flutter应用中实施了非消耗性应用内购买。在升级应用内购买包后,购买对话框未显示,并出现以下错误:

PlatformException(INVALID_OFFER_TOKEN,产品monthly的优惠券令牌为null,无效。请确保只传递属于该产品的优惠券令牌。要获取产品的优惠券令牌,请获取产品。获取产品的示例可以在此处找到:https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase/README.md#loading-products-for-sale,null,null)

我的基本套餐中没有任何优惠券。感谢任何帮助。

英文:

I have implemented non consumable in app purchase in my flutter app. after upgrade in app purchase package purchase dialog not shown and its give me below error:

PlatformException(INVALID_OFFER_TOKEN, Offer token null for product monthly is not valid. Make sure to only pass offer tokens that belong to the product. To obtain offer tokens for a product, fetch the products. An example of how to fetch the products could be found here: https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase/README.md#loading-products-for-sale, null, null)

I don't have any offer with my base plan.
Any help is appreciated.

答案1

得分: 2

我已找到解决方案。要解决与Flutter中的应用内购买库相关的问题,您可以使用库的版本3.1.5。

在最新版本3.1.7的应用内购买库中,它在内部依赖于版本为^0.3.0+8的in_app_purchase_android库。在此版本中,提供的令牌是强制的,这可能会导致与无论您是否在Play Store中添加了令牌都会出现无效令牌的问题。

为了避免这些问题,您可以明确使用应用内购买库的版本3.1.5。这个版本不应该有强制的提供令牌要求,可以帮助解决问题。

确保在依赖项部分下更新您的pubspec.yaml文件,加入以下行:

dependencies:
  in_app_purchase: 3.1.5

保存文件后,运行flutter pub get来获取指定版本的库并解决问题。

通过使用应用内购买库的版本3.1.5,您应该能够避免与强制提供令牌要求相关的问题。

英文:

I have found a solution. To resolve the issue related to the in-app purchase library in Flutter, you can use version 3.1.5 of the library.

In the latest version, 3.1.7 of the in-app purchase library, it internally relies on the in_app_purchase_android library with a version of ^0.3.0+8. In this version, the offer token is mandatory, which can cause issues with invalid offer tokens, whether or not you have added a token in the Play Store.

To avoid these issues, you can specifically use version 3.1.5 of the in_app_purchase library. This version should not have the mandatory offer token requirement and can help resolve the problem.

Make sure to update your pubspec.yaml file with the following line under the dependencies section:

dependencies:
  in_app_purchase: 3.1.5

After saving the file, run flutter pub get to fetch the specified version of the library and resolve the issue.

By using version 3.1.5 of the in_app_purchase library, you should be able to avoid the problems related to the mandatory offer token requirement.

答案2

得分: 1

我建议使用从queryProductDetails返回的产品详细信息。我遇到过相同的问题,这个方法解决了它。

以下是一个示例,请确保将其中的产品ID更改为正确的值。

Future<void> purchaseSubscription() async {
  final productDetailsResponse = await InAppPurchase.instance.queryProductDetails({YOUR_PRODUCT_ID});
  final productDetails = productDetailsResponse.productDetails.firstOrNull;

  if (productDetails != null) {
    final purchaseParam = PurchaseParam(productDetails: productDetails);
    await InAppPurchase.instance.buyNonConsumable(purchaseParam: purchaseParam);
  }
}
英文:

I would recommend using the product details returned from queryProductDetails. I had the same issue and that fixed it.

Here is an example, be sure to update it with the correct product id.

Future&lt;void&gt; purchaseSubscription() async {
  final productDetailsResponse = await InAppPurchase.instance.queryProductDetails({YOUR_PRODUCT_ID});
  final productDetails = productDetailsResponse.productDetails.firstOrNull;

  if (productDetails != null) {
    final purchaseParam = PurchaseParam(productDetails: productDetails);
    await InAppPurchase.instance.buyNonConsumable(purchaseParam: purchaseParam);
  }
}

huangapple
  • 本文由 发表于 2023年6月19日 15:29:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76504487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定