isProductPurchased static method

Future<BaseResponse> isProductPurchased(
  1. String productId
)

Checks whether a product is actively purchased or not.

With calling isProductPurchased method of the SDK you can check whether a product is purchased or not. Once you query a product with productId, a boolean response comes back.

True means that the product is purchased. After consumption, it will respond a false value. These are accepted as purchased:

  • Purchased but not consumed consumable products.
  • Non-consumable products.
  • Ongoing subscription products.

productId Id of the product to be checked.

Callbacks boolean and GenericError in case of failure.

Implementation

static Future<BaseResponse> isProductPurchased(String productId) async {
  List<Object?>? response = await _channel
      .invokeMethod('isProductPurchased', {"productId": productId});
  BaseResponse result = new BaseResponse(false, null);
  if (response != null) {
    if (response[0] != null) {
      result = new BaseResponse(response[0].toString() == "true", null);
    }
    if (response[1] != null) {
      GenericError error =
          GenericError.fromJson(json.decode(response[1]!.toString()));
      result = new BaseResponse(false, error);
    }
    return result;
  }
  return result;
}