flutter, Unable to buy item, Error response code: 7 & flutter_inapp_purchase

问题描述, flutter_inapp_purchase支付库,点击购买受管理的商品时,出现错误;

W/BillingClient(25436): Unable to buy item, Error response code: 7

E/DoobooUtils(25436): Error Code : 7

I/flutter (25436): [price: 65.99, monthPrice: 5.50]

I/flutter (25436): [price: 29.99, monthPrice: 10.00]

I/flutter (25436): [price: 149.99, monthPrice: ]

D/FA      (25436): Logging event (FE): HWPurchaseSelect, Bundle[{source=, ga_event_origin(_o)=app, ga_screen_class(_sc)=MainActivity, ga_screen_id(_si)=-2672549720685398148, purchase_month=lifetime}]

I/flutter (25436): kiit0611==== 3 responseCode: 7, debugMessage: Item is already owned., code: E_ALREADY_OWNED, message: You already own this item.

错误很明显,就是你已经拥有此项目,说明当前google play中登录的账号已经购买过这个商品。

解决方法:

直接更换google play中的账号,清除google 账号的缓存(清除goole play 缓存)。再去购买,有时还需要重启手机。

 

一般这个问题是在ios侧会出现,但是google里面如果出现了就可以按照上面的方法解决。但是有一点要注意,使用这个库时,代码要这样:

FlutterInappPurchase.instance.clearTransactionIOS();

...

/// google订单确认操作,
/// 如果再3天内没有确认购买交易,则用户自动收到退款,同时
/// Google Play会撤销该购买交易
if (Platform.isAndroid) {
  FlutterInappPurchase.instance
      .acknowledgePurchaseAndroid(productItem.purchaseToken);
  FlutterInappPurchase.instance
      .consumePurchaseAndroid(productItem.purchaseToken);
}

截图如下:

flutter, Unable to buy item, Error response code: 7 & flutter_inapp_purchase_第1张图片

请确有这样的代码。FlutterInappPurchase.instance .consumePurchaseAndroid(productItem.purchaseToken);意思就是要消费掉,要不然一直存在就报errorCode = 7.

 

 flutter_inapp_purchase支付库中的源码如下:看红色的注释,就明白了。

/// Consumes a purchase on `Android`.
///
/// No effect on `iOS`, whose consumable purchases are consumed at the time of purchase.
///
/// if you already invoked [getProducts],you ought to invoked this method to confirm you have consumed.
/// that means you can purchase one IAPItem more times, otherwise you'll receive error code : 7
///
/// in DoobooUtils.java error like this:
/// case BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED:
///        errorData[0] = E_ALREADY_OWNED;
///        errorData[1] = "You already own this item.";
///        break;
Future consumePurchaseAndroid(String token, { String developerPayload }) async {
  if (_platform.isAndroid) {
    String result =
        await _channel.invokeMethod('consumeProduct', {
      'token': token,
      'developerPayload': developerPayload,
    });
    return result;
  } else if (_platform.isIOS) {
    return 'no-ops in ios';
  }
  throw PlatformException(
      code: _platform.operatingSystem, message: "platform not supported");
}

 

始终记住,支持google服务的手机,有时会出现很多账号和缓存(清除goole play 缓存)导致的奇怪现象,直接换账号,清缓存,重启手机才是上策。

 

你可能感兴趣的:(flutter, Unable to buy item, Error response code: 7 & flutter_inapp_purchase)