flutterin-app-purchasegoogle-play-consoleflutter-in-app-purchase

in_app_purchase: ^3.2.0 flutter error "You already own this item" after some buy


"Im using in_app_purchase: ^3.2.0 package for my flutter app. I have list the products and make thing good. But issue is im hitting " _inAppPurchase.buyConsumable( purchaseParam: purchaseParam, autoConsume: _kAutoConsume);

"issue is when im trying to buy iteam it work fine unti 9th time after it is shows Error "You already own this item" . im in debug mode. but i want to but consumable item agian and again without any count restriction. also from Order Managment when i refund last purchase then im able to again buy that product 2 time then again got same issue. Also i dont want to put restore purchase button in my app

im try to buy consumable product in my flutter android app multiple time. "


Solution

  • i fixed this but addinf consumePurchase in my code like this
    
     Future<void> _listenToPurchaseUpdated(
          List<PurchaseDetails> purchaseDetailsList) async {
        for (final PurchaseDetails purchaseDetails in purchaseDetailsList) {
          if (purchaseDetails.status == PurchaseStatus.pending) {
            showPendingUI();
          } else {
            if (purchaseDetails.status == PurchaseStatus.error) {
              handleError(purchaseDetails.error!);
            } else if (purchaseDetails.status == PurchaseStatus.purchased ||
                purchaseDetails.status == PurchaseStatus.restored) {
              final bool valid = await _verifyPurchase(purchaseDetails);
              if (valid) {
                unawaited(deliverProduct(purchaseDetails));
              } else {
                _handleInvalidPurchase(purchaseDetails);
                return;
              }
    
              if (Platform.isAndroid) {
                final InAppPurchaseAndroidPlatformAddition androidAddition =
                _inAppPurchase.getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
                await androidAddition.consumePurchase(purchaseDetails);
                debugPrint('Purchase consumed: ${purchaseDetails.productID}');
              }
            }
            if (Platform.isAndroid) {
              if (!_kAutoConsume && purchaseDetails.productID == _kConsumableId) {
                final InAppPurchaseAndroidPlatformAddition androidAddition =
                _inAppPurchase.getPlatformAddition<
                    InAppPurchaseAndroidPlatformAddition>();
                await androidAddition.consumePurchase(purchaseDetails);
                debugPrint('Purchase manually consumed: ${purchaseDetails.productID}');
              }
            }
            if (purchaseDetails.pendingCompletePurchase) {
              await _inAppPurchase.completePurchase(purchaseDetails);
              debugPrint('Purchase completed: ${purchaseDetails.productID}');
            }
          }
        }
      }