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);
}

截图如下:

请确有这样的代码。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<String> consumePurchaseAndroid(String token, { String developerPayload }) async {
  if (_platform.isAndroid) {
    String result =
        await _channel.invokeMethod('consumeProduct', <String, dynamic>{
      '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 缓存导致的奇怪现象,直接换账号,清缓存,重启手机才是上策。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值