queryPastPurchases method

Future queryPastPurchases({
  1. bool first = false,
  2. bool refresh = false,
})

Implementation

Future queryPastPurchases({bool first = false, bool refresh = false}) async {
  if (await connection.isAvailable()) {
    if (Platform.isAndroid || refresh) {
      if (restored) {
        delegate.logEvent('${payInType ?? ''}票据为空清空本地缓存');
        SpUtil.putString(RechargeConfig.inappToken, '');
        SpUtil.putString(RechargeConfig.inappSign, '');
        SpUtil.putString(RechargeConfig.inappOrderId, '');
        SpUtil.putString(RechargeConfig.inappPrice, '');
        SpUtil.putString(RechargeConfig.inappCode, '');
        restored = false;
      } else {
        restored = true;
        await connection.restorePurchases();
      }
    } else if (!first) {
      InAppPurchaseStoreKitPlatformAddition iosAddition = connection
          .getPlatformAddition<InAppPurchaseStoreKitPlatformAddition>();
      PurchaseVerificationData? verificationData =
          await iosAddition.refreshPurchaseVerificationData();
      if (verificationData != null) {
        SpUtil.putString(RechargeConfig.inappToken,
            verificationData.serverVerificationData);
        await checkInPayPurchase(
            verificationData.serverVerificationData, '', '',
            first: true, refresh: true);
        // await checkInPayPurchaseVip(
        //     verificationData.serverVerificationData, '', '',
        //     first: true,
        //     refresh: true);
      } else {
        delegate.logEvent('${payInType ?? ''}票据为空清空本地缓存');
        SpUtil.putString(RechargeConfig.inappToken, '');
        SpUtil.putString(RechargeConfig.inappSign, '');
        SpUtil.putString(RechargeConfig.inappOrderId, '');
        SpUtil.putString(RechargeConfig.inappPrice, '');
        SpUtil.putString(RechargeConfig.inappCode, '');
      }
    }
  }
}