getPurchaseHistory method

Future<List<PurchasedItem>?> getPurchaseHistory()

Retrieves the user's purchase history on Android and iOS regardless of consumption status.

Purchase history includes all types of products. Identical to getAvailablePurchases on iOS.

Implementation

Future<List<PurchasedItem>?> getPurchaseHistory() async {
  if (_platform.isAndroid) {
    final dynamic getInappPurchaseHistory = await _channel.invokeMethod(
      'getPurchaseHistoryByType',
      <String, dynamic>{
        'type': _TypeInApp.inapp.name, // describeEnum 대신 name 속성 사용
      },
    );

    final dynamic getSubsPurchaseHistory = await _channel.invokeMethod(
      'getPurchaseHistoryByType',
      <String, dynamic>{
        'type': _TypeInApp.subs.name, // describeEnum 대신 name 속성 사용
      },
    );

    return extractPurchased(getInappPurchaseHistory)! +
        extractPurchased(getSubsPurchaseHistory)!;
  } else if (_platform.isIOS) {
    dynamic result = await _channel.invokeMethod('getAvailableItems');

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