Untitled

mail@pastecode.io avatar
unknown
swift
a year ago
1.5 kB
4
Indexable
Never
  /// After restoring, it checks to see whether the user is actually subscribed or not.
  ///
  /// This is accessed by both the transaction manager and the restoration manager.
  @MainActor
  func processRestoration(
    restorationResult: RestorationResult,
    paywallViewController: PaywallViewController
  ) async {
    let hasRestored = restorationResult == .restored
    var successfulRestore = hasRestored

    if !Superwall.shared.dependencyContainer.delegateAdapter.hasPurchaseController {
      await refreshReceipt()
      var isUserSubscribed = false
      if hasRestored {
        await loadPurchasedProducts()
        isUserSubscribed = Superwall.shared.subscriptionStatus == .active
      }
      successfulRestore = hasRestored && isUserSubscribed
    }

    if successfulRestore {
      Logger.debug(
        logLevel: .debug,
        scope: .paywallTransactions,
        message: "Transactions Restored"
      )
      transactionWasRestored(paywallViewController: paywallViewController)
    } else {
      Logger.debug(
        logLevel: .debug,
        scope: .paywallTransactions,
        message: "Transactions Failed to Restore"
      )

      paywallViewController.presentAlert(
        title: Superwall.shared.options.paywalls.restoreFailed.title,
        message: Superwall.shared.options.paywalls.restoreFailed.message,
        closeActionTitle: Superwall.shared.options.paywalls.restoreFailed.closeButtonTitle
      )
    }
  }