getCurrentSubs method

Future<AWOrder?> getCurrentSubs(
  1. AwPlatformType type
)

返回当前有效的订阅中订阅期限最长的

Implementation

Future<AWOrder?> getCurrentSubs(AwPlatformType type) async {
  var orderRes = await AWPurchase.getOrderList(type);
  if (false == (orderRes?.result ?? false)) {
    return null;
  }
  final orderList = orderRes?.data ?? [];
  if (orderList.isEmpty) {
    return null;
  }
  AWOrder? currentSubs;
  if (type == AwPlatformType.ios) {
    int expireTime = 0;
    for (var order in orderList) {
      if (order.productType == IosProductType.renewable) {
        if ((order.expireTime ?? 0) >= expireTime) {
          //筛选最后到期的一个
          currentSubs = order;
        }
      }
    }
  }
  if (type == AwPlatformType.android) {
    int expireTime = 0;
    for (var order in orderList) {
      if (order.paymentType == AndroidProductType.subs) {
        if ((order.expireTime ?? 0) >= expireTime) {
          //筛选最后到期的一个
          currentSubs = order;
        }
      }
    }
  }
  return currentSubs;
}