SwiftiSwift
SwiftiSwift

Reputation: 8707

Flutter No Products for In-App-Subscriptions query

Hi I tried everything to query/retrieve subscriptions with Flutter using the official in_app_purchase package but I don't get them.

Everything works fine with iOS. With the same code on Android, it doesn't work.

This is what I get in the console

Purchase etf_info_access_subscription not found

class IAPConnection {
  static InAppPurchase? _instance;
  static set instance(InAppPurchase value) {
    _instance = value;
  }

  static InAppPurchase get instance {
    _instance ??= InAppPurchase.instance;
    return _instance!;
  }
}

class SubscriptionsProvider extends ChangeNotifier {
  List<PurchasableProduct> products = [];
  List<PastPurchase> purchases = [];

  StoreState storeState = StoreState.loading;

  final iapConnection = IAPConnection.instance;

  SubscriptionsProvider() {
    loadPurchases();
  }

Future<void> loadPurchases() async {
    final available = await iapConnection.isAvailable();
    if (!available) {
      storeState = StoreState.notAvailable;
      notifyListeners();
      return;
    }
    final serverAvailable =
        // ignore: use_build_context_synchronously
        await NetworkService.instance.testServerAvailability();
    if (serverAvailable == false) {
      storeState = StoreState.notAvailable;
      notifyListeners();
      return;
    }
    const ids = <String>{storeKeySubscription}; // which is 'etf_info_access_subscription'
    final response = await iapConnection.queryProductDetails(ids);
    for (var element in response.notFoundIDs) {
      debugPrint('Purchase $element not found'); // I always get this printed in Android :(
    }
    products =
        response.productDetails.map((e) => PurchasableProduct(e)).toList();
    debugPrint(products.toString()); // Always empty
    storeState = StoreState.available;
    notifyListeners();
  }
}

These are the dependencies in /app/build.gradle

def billing_version = "5.0.0"

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation("com.android.billingclient:billing:$billing_version")
}

My AndroidManifest.xml permissions:

   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name="com.android.vending.BILLING" />

I also uploaded a build with these onto the play store closed and internal testing successfully but still I can't retrieve products...

I have also created a subscription with the same ID as the app:

enter image description here

Upvotes: 3

Views: 2627

Answers (1)

enc_life
enc_life

Reputation: 5169

There are a few things that can cause this so hard to say exactly but the first things to check are that:

  1. Your app is published on a closed track and you've added a tester. A lot of times developers will try to test before the app is published to a closed track.
  2. The subscription product is in the Active state in the Play Console.
  3. You need to join the testers program in the closed and internal track.

There is a helpful article here screenshots and other reasons why this can happen on iOS and Android: https://community.revenuecat.com/sdks-51/why-are-offerings-or-products-empty-124

Upvotes: 3

Related Questions