[in_app_purchase] Android “You already own this item” and errors out

Version: in_app_purchase: ^0.6.0

After buying a few consumables i am now locked out and greeted with this error:

Screen Shot 2021-05-16 at 11 09 41 AM

I have cleared the playstore cache and storage and still am unable to make a consumable purchase.

After click ok the error i get in the console is

E/flutter ( 6032): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 'package:in_app_purchase_android/src/in_app_purchase_android_platform.dart': Failed assertion: line 157 pos 7: 'purchase is GooglePlayPurchaseDetails': On Android, the `purchase` should always be of type `GooglePlayPurchaseDetails`.
E/flutter ( 6032): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
E/flutter ( 6032): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter ( 6032): #2      InAppPurchaseAndroidPlatform.completePurchase (package:in_app_purchase_android/src/in_app_purchase_android_platform.dart:157:7)
E/flutter ( 6032): #3      InAppPurchase.completePurchase (package:in_app_purchase/in_app_purchase.dart:186:38)
E/flutter ( 6032): #4      _AndroidLargePurchaseScreenState._listenToPurchaseUpdated.<anonymous closure> (package:how_to_think/screens/andriod_large_purchase.dart:130:22)
E/flutter ( 6032): <asynchronous suspension>
E/flutter ( 6032): 

The line in the app thats its erring on is

 if (purchaseDetails.status == PurchaseStatus.error) {
          await _iap.completePurchase(purchaseDetails);  // HERE 
          showToast("An error has occurred processing your payment");

I have tried to make the purchase params both ways and still get that error

      final purchaseParam = GooglePlayPurchaseParam(
        productDetails: prod,
        applicationUserName: null,
      //final PurchaseParam purchaseParam = PurchaseParam(productDetails: prod);

  ║ A new version of Flutter is available!                                     ║
  ║                                                                            ║
  ║ To update to the latest version, run "flutter upgrade".                    ║

[✓] Flutter (Channel beta, 2.1.0-12.2.pre, on Mac OS X 10.15.7 19H1030 darwin-x64, locale en)
    • Flutter version 2.1.0-12.2.pre at /Users/jparrack/phil/flutter
    • Framework revision 5bedb7b1d5 (9 weeks ago), 2021-03-17 17:06:30 -0700
    • Engine revision 711ab3fda0
    • Dart version 2.13.0 (build 2.13.0-116.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/jparrack/Library/Android/sdk
    • Platform android-30, build-tools 29.0.2
    • ANDROID_HOME = /Users/jparrack/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.2.5)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 182.5215

[✓] VS Code (version 1.53.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (3 available)
    • sdk gphone x86 (mobile)    • emulator-5554                        • android-x86    • Android 11 (API 30) (emulator)
    • iPhone 12 Pro Max (mobile) • BE0DF70C-94D9-4120-B5A5-53F9FA755D84 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 90.0.4430.212

• No issues found!

1 thought on “[in_app_purchase] Android “You already own this item” and errors out

  1. I do not have the same signing configs for release and debug.

    They have to be the same for in app billing to work on Android. Your ‘developer build’ APK should be signed with the same credentials as the APK you have submitted to your production/alpha channel.
    This is most probably the reason why you see the Error code 5.

    Well, somehow the ‘launch purchase’ flow still works even with different credentials, but that must be the reason why your purchases can’t be consumed. Most probably this is also why items couldn’t be consumed automatically.

    When you have an unconsumed purchase (on Google Play servers), you can’t buy another same product.

    Google doesn’t block devs for testing, even aggressively.

    What you should try is:

    1. set you debug build signingConfig to your release credentials;
    2. call await InAppPurchase.instance.restorePurchases(); during the initialization;
    3. inside your purchaseStream listener, for all items (you may want to print them) call:

    // Acquire the InAppPurchaseAndroidPlatformAddition instance.
    InAppPurchaseAndroidPlatformAddition androidAddition = InAppPurchase.instance.getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
    // Consume an Android purchase.
    BillingResultWrapper billingResult = await androidAddition.consumePurchase(purchase);

Comments are closed.