queryPurchases method

Future<PurchasesResultWrapper> queryPurchases(
  1. ProductType productType
)

Fetches recent purchases for the given ProductType.

Unlike queryPurchaseHistory, This does not make a network request and does not return items that are no longer owned.

All purchase information should also be verified manually, with your server if at all possible. See "Verify a purchase".

This wraps BillingClient#queryPurchasesAsync(QueryPurchaseParams, PurchaseResponseListener).

Implementation

Future<PurchasesResultWrapper> queryPurchases(ProductType productType) async {
  // TODO(stuartmorgan): Investigate whether forceOkResponseCode is actually
  // correct. This code preserves the behavior of the pre-Pigeon-conversion
  // Java code, but the way this field is treated in PurchasesResultWrapper is
  // inconsistent with ProductDetailsResponseWrapper and
  // PurchasesHistoryResult, which have a getter for
  // billingResult.responseCode instead of having a separate field, and the
  // other use of PurchasesResultWrapper (onPurchasesUpdated) was using
  // billingResult.getResponseCode() for responseCode instead of hard-coding
  // OK. Several Dart unit tests had to be removed when the hard-coding logic
  // was moved from Java to here because they were testing a case that the
  // plugin could never actually generate, and it may well be that those tests
  // were correct and the functionality they were intended to test had been
  // broken by the original change to hard-code this on the Java side (instead
  // of making it a forwarding getter on the Dart side).
  return purchasesResultWrapperFromPlatform(
      await _hostApi
          .queryPurchasesAsync(platformProductTypeFromWrapper(productType)),
      forceOkResponseCode: true);
}