Issue
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);
}
}
}
Solution
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_adspurchase.You need to add
in_app_purchaseas a dependency in yourpubspec.yamlfile:
dependencies:
in_app_purchase: ^0.3.1 # For newer versions, check the Pub page.
- In your Flutter app, you now need to import
'package:in_app_purchase/in_app_purchase.dart':
import 'package:in_app_purchase/in_app_purchase.dart';
- To load your product, you can use the following code:
// 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.
- You need to follow the steps explained in the example's README. You will need to create a
remove_adsSKU ID instead of what they mention because their SKU IDs only apply to the example.
Answered By - creativecreatorormaybenot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.