getAvailablePurchases method

Future<List<PurchasedItem>?> getAvailablePurchases()

Get all non-consumed purchases made on Android and iOS.

This is identical to getPurchaseHistory on iOS

Implementation

Future<List<PurchasedItem>?> getAvailablePurchases() async {
  if (_platform.isAndroid) {
    dynamic result1 = await _channel.invokeMethod(
      'getAvailableItemsByType',
      <String, dynamic>{
        'type': _TypeInApp.inapp.name,
      },
    );

    dynamic result2 = await _channel.invokeMethod(
      'getAvailableItemsByType',
      <String, dynamic>{
        'type': _TypeInApp.subs.name,
      },
    );
    return extractPurchased(result1)! + extractPurchased(result2)!;
  } else if (_platform.isIOS) {
    dynamic result = await _channel.invokeMethod('getAvailableItems');

    return extractPurchased(json.encode(result));
  }
  throw PlatformException(
      code: _platform.operatingSystem, message: "platform not supported");
}