Tag Archives: flutter_inapp_purchase error

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

Problem description: Flutter_inapp_purchase payment repository, error occurred when clicking to buy the managed item;

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 Events (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.

The error is obvious: you already have this item, indicating that the current account logged into Google Play has already purchased this item.
Solutions:
Change your Google Play account directly and clear the Google Account cache (clear the Google Play cache). To buy again, sometimes you need to restart the phone.

This problem usually occurs on the ios side, but if it does occur in Google, it can be solved according to the above method. However, it is important to note that when using the library, the code looks like this:

FlutterInappPurchase.instance.clearTransactionIOS();

/// google order confirmation operation.
/// If the purchase transaction is not confirmed within a further 3 days, the user will automatically receive a refund, along with
// Google Play will revoke that purchase transaction
if (Platform.isAndroid) {
  FlutterInappPurchase.instance
      .acknowledgePurchaseAndroid(productItem.purchaseToken);
  FlutterInappPurchase.instance
      .consumePurchaseAndroid(productItem.purchaseToken);
}

The screenshot is as follows:

Please have such code. FlutterInappPurchase.instance .consumePurchaseAndroid(productItem.purchaseToken); That means consume it, or else it will always be there and report errorCode = 7.

The source code in the Flutter_inapp_Purchase payment repository is as follows: See the red comment.

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

Keep in mind that google-enabled phones can sometimes get weird with lots of accounts and caches (clear the Goole Play cache), so it’s best to switch accounts, clear the cache, and restart the phone.