Search code examples
iosflutterdartin-app-purchaseflutter-in-app-purchase

Trouble with queryProductDetails() in flutter package in_app_purchase


I am trying to add subscriptions to my app for IOS. The code I am using works on android but not for IOS whenever I use final ProductDetailsResponse response = await InAppPurchase.instance .queryProductDetails({'standard', 'family'}); it always returns an empty array when it shouldn't. I think it has something to do with Apple having subscription groups but I'm not to sure. Here's the full function for a better understanding:

  Future<bool> makePurchaseIos(String productId) async {

    late ProductDetails standardPlan;
    late ProductDetails familyPlan;

    final ProductDetailsResponse response = await InAppPurchase.instance
        .queryProductDetails({'standard', 'family'});

    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Got the following products: ${response.productDetails}"),
            ));

    for (ProductDetails product in response.productDetails) {
      if (product.id == 'standard') {
        standardPlan = product;
      } else if (product.id == 'family') {
        familyPlan = product;
      }
    }

    ///

    ProductDetails selectedProduct;
    if (productId == "standard") {
      selectedProduct = standardPlan;
    } else {
      selectedProduct = familyPlan;
    }

    final PurchaseParam purchaseParam =
        PurchaseParam(productDetails: selectedProduct);
    await InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam);
    print(selectedProduct);
    return true;
  }

Whenever I try to press subscribe it returns the empty array which means the response from queryProductDetails() function is nothing. I do not know why this would be happening though as I am definitely giving it the correct subscription ID's


Solution

  • On the clients computer they had told me they had set up the banking, taxes and agreed to the terms and conditions. It turned out they hadn't so that's where it was going wrong however Apple does not give you an actual error message to inform you of this. If you have the same error double check the steps I have mentioned are done.