Reputation: 1331
I am trying to set up paid products in my app.
I have followed all the guides for the Flutter_Inapp_Purchase plugin and they all say:
List<IAPItem> items = await FlutterInappPurchase.getProducts([iapId]);
Where iapId is the "id of my app". All of my other code surrounding this implementation works fine, because when I use 'android.test.purchased' as my iapId string, the test product is found and loaded into the app perfectly. So the issue is the string that I am using maybe, because no other explanation or examples are given about this anywhere.
I have a product in my store called remove_ads
.
So am I using the wrong iapId
here? I can't imagine what else it could be asking for.
Edit:
Purchasing the items.
I have updated the code below, as it had errors already. It now fails at the lines: _verifyPurchase and _deliverPurchase below, as these are not things. The official documentation for this seems to say "you go ahead and work all this stuff out from here", with no indication how to even begin.
Future<Null> _queryPastPurchases() async {
final QueryPurchaseDetailsResponse response = await InAppPurchaseConnection.instance.queryPastPurchases();
if (response.error != null) {
// Handle the error.
}
for (PurchaseDetails purchase in response.pastPurchases) {
_verifyPurchase(purchase); // Verify the purchase following the best practices for each storefront.
_deliverPurchase(purchase); // Deliver the purchase to the user in your app.
if (Platform.isIOS) {
// Mark that you've delivered the purchase. Only the App Store requires
// this final confirmation.
InAppPurchaseConnection.instance.completePurchase(purchase);
}
}
}
Upvotes: 28
Views: 25975
Reputation: 21
In my case i fix this by register the products, subscriptions after by sending my app to testflight.
Because i`ve tested without any version at testflight and the apple store connect dont send any information about products or subscriptions.
Upvotes: 1
Reputation: 91
I have the same problem (specific to IOS). In my case, to receive the Apple products I needed to fill the form o Agreements, Tax and Banking (https://appstoreconnect.apple.com/agreements/). After filling the form and it be approved the products returned.
Upvotes: 9
Reputation: 1025
On Android: In my case I had to publish the app (was enough to publish an internal testing version) in order to see the IPAs. I also cold booted the emulator and reinstalled the app.
Upvotes: 0
Reputation: 651
Had a similar issue, but in my case querying for my store products failed immediately after the app started, but succeeded a little while afterwards.
Using @jeanadam's suggestion, specifically, calling InAppPurchaseConnection.instance.isAvailable()
before querying for products solved the issue in my case.
I find the method name isAvailable()
very confusing, as apparently it doesn't just specify if the relevant store is available or not, but also waits for the store connection to be established.
Upvotes: -1
Reputation: 1262
In my case I had to wait several hours in order for product to become available and appeared in list of products in ProductDetailsResponse
.
Also I believe setting it to Active in Google Play Console also had a role in making it accessible.
Because I've created the product yesterday and only after I set it to Active in the Console and waited some hours it started working.
So if you're sure you did all correct, try to just wait for some time, till Google services start serving your product to your app.
Upvotes: 3
Reputation: 6089
In my case In-App purchase working fine in Android but not worked in ios
After lots of struggle found that bundle id project.pbxproj
in this file is different than I define in runner
this file location is
projectdirectory -> ios -> Runner.xcodeproj
check bundle id that assigns to PRODUCT_BUNDLE_IDENTIFIER
I hope this may save someone time
Upvotes: 1
Reputation: 449
I just had this same problem (notFoundIds) while using flutter plugin in_app_purchase. So two things to be ensured:
Ensure productId is registered in PlayStore/AppStore as specified by plugin readme;
Before calling queryProductDetails, call isAppPurchaseAvailable which will initialise and wait a bit until it is ready, then queryProductDetails will work. Sample code below:
Future<List<ProductDetails>> loadProductsForSale() async {
if(await isAppPurchaseAvailable()) {
const Set<String> _kIds = {APP_PRODUCTID01};
final ProductDetailsResponse response =
await InAppPurchaseConnection.instance.queryProductDetails(_kIds);
if (response.notFoundIDs.isNotEmpty) {
debugPrint(
'#PurchaseService.loadProductsForSale() notFoundIDs: ${response
.notFoundIDs}');
}
if (response.error != null) {
debugPrint(
'#PurchaseService.loadProductsForSale() error: ${response.error
.code + ' - ' + response.error.message}');
}
List<ProductDetails> products = response.productDetails;
return products;
} else{
debugPrint('#PurchaseService.loadProductsForSale() store not available');
return null;
}
}
Future<bool> isAppPurchaseAvailable() async {
final bool available = await InAppPurchaseConnection.instance.isAvailable();
debugPrint('#PurchaseService.isAppPurchaseAvailable() => $available');
return available;
if (!available) {
// The store cannot be reached or accessed. Update the UI accordingly.
return false;
}
}
Upvotes: 6
Reputation: 126684
This answer is somewhat of a recommendation, however, it should take you to your goal.
The Flutter team has recently finished an official plugin for in-app purchases. It is the in_app_purchase
plugin.
I assume that you have already read through the Android Developers guide for configuring your remove_ads
purchase.
You need to add in_app_purchase
as a dependency in your pubspec.yaml
file:
dependencies:
in_app_purchase: ^0.3.1 # For newer versions, check the Pub page.
'package:in_app_purchase/in_app_purchase.dart'
:import 'package:in_app_purchase/in_app_purchase.dart';
// Set literals require Dart 2.2. Alternatively, remove `const` and use `<String>['remove_ads'].toSet()`.
const Set<String> _kIds = {'remove_ads'};
final ProductDetailsResponse response = await InAppPurchaseConnection.instance.queryProductDetails(_kIds);
if (!response.notFoundIds.isEmpty()) {
// Handle the error.
} else {
List<ProductDetails> products = response.productDetails;
for (ProductDetails product in products) {
print('${product.title}: ${product.description} (cost is ${product.price})');
}
// Example: purchasing the first available item.
final PurchaseParam purchaseParam = PurchaseParam(productDetails: products[0]);
InAppPurchaseConnection.instance.buyNonConsumable(purchaseParam: purchaseParam);
}
For more information and instructions, read the plugin's README and checkout the example app.
remove_ads
SKU ID instead of what they mention because their SKU IDs only apply to the example.Upvotes: 22
Reputation: 111
You need to use a reserved SKU for the test: android.test.purchased
When using in_app_purchase:
const List<String> _kProductIds = <String>[
'android.test.purchased'
];
ProductDetailsResponse productDetailResponse =
await _connection.queryProductDetails(_kProductIds.toSet());
Upvotes: 7