queryProductDetails method
Performs a network query for the details of products available.
Implementation
@override
Future<ProductDetailsResponse> queryProductDetails(
Set<String> identifiers,
) async {
List<ProductDetailsResponseWrapper>? productResponses;
PlatformException? exception;
try {
productResponses =
await Future.wait(<Future<ProductDetailsResponseWrapper>>[
billingClientManager.runWithClient(
(BillingClient client) => client.queryProductDetails(
productList: identifiers
.map(
(String productId) => ProductWrapper(
productId: productId,
productType: ProductType.inapp,
),
)
.toList(),
),
),
billingClientManager.runWithClient(
(BillingClient client) => client.queryProductDetails(
productList: identifiers
.map(
(String productId) => ProductWrapper(
productId: productId,
productType: ProductType.subs,
),
)
.toList(),
),
),
]);
} on PlatformException catch (e) {
exception = e;
productResponses = <ProductDetailsResponseWrapper>[
ProductDetailsResponseWrapper(
billingResult: BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: e.code,
),
productDetailsList: const <ProductDetailsWrapper>[],
),
ProductDetailsResponseWrapper(
billingResult: BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: e.code,
),
productDetailsList: const <ProductDetailsWrapper>[],
),
];
}
final List<ProductDetails> productDetailsList = productResponses
.expand((ProductDetailsResponseWrapper response) {
return response.productDetailsList;
})
.expand((ProductDetailsWrapper productDetailWrapper) {
return GooglePlayProductDetails.fromProductDetails(
productDetailWrapper,
);
})
.toList();
final Set<String> successIDS = productDetailsList
.map((ProductDetails productDetails) => productDetails.id)
.toSet();
final List<String> notFoundIDS = identifiers
.difference(successIDS)
.toList();
return ProductDetailsResponse(
productDetails: productDetailsList,
notFoundIDs: notFoundIDS,
error: exception == null
? null
: IAPError(
source: kIAPSource,
code: exception.code,
message: exception.message ?? '',
details: exception.details,
),
);
}