Restoring Purchases

Providing information in the UI for users during a restore purchase.

How purchases are restored and requirements around what you need to do can vary by platform. In this guide, we walk through the basics to make sure you correctly enable customers' ability to restore purchases easily in your app.

Apple

On Apple devices, Apple asks you to explicitly provide the functionality to start the restore purchase process somewhere in your app.

📘

Nami processes the receipt for your app each time the app comes to the foreground. If there are any active purchases, they should be activated by this receipt check process.

Nami Paywalls support adding a Restore Purchases button directly to your paywalls.

You may also start the process of restoring purchases by calling the following method.

NamiPurchaseManager.restorePurchases()

📘

When using Linked Paywalls, if you have a button for Restore Purchases please call the method above to trigger the restoration process.

Reacting to the Restore Purchase Process

🚧

Apple does not present any UI to the user during the Restore Purchase process.

The Nami SDK provides a method for registering a callback that will allow you to respond to different states that occur during the Restore Purchase process, and provide information in your UI to let the user know what has occurred.

There are 3 states you can react to during the process:

  • started
  • finished
  • error

👍

Nami Best Practice

We recommend presenting messages in the correct language in your app's UI for at least the finished and error states.

The code sample below shows how to present a message in the UI to the user letting them know whether any purchases were found and restored during the Restore Purchases process.

It also informs the user if there was an error during the process so they know to try again.

The registerRestorePurchasesHandler returns 2 sets of purchases:

  • oldPurchases - Purchases that were active on the device before the restore purchases process started.
  • newPurchases - All purchases active on the device after the restore purchases process completed.
NamiPurchaseManager.registerRestorePurchasesHandler { state, newPurchases, oldPurchases, error in
  // For Nami Paywalls made with the Paywall Creator, present
  // any alerts from this view controller
  let presentAlertFromVC = NamiPaywallManager.currentNamiPaywallViewController()
                                                     
  switch state {
    case .started:
      // optionally react to start of restore purchases
    case .finished:
      // additionally may want to check that there are more items in
      // newPurchases than oldPurchases
      if oldPurchases != newPurchases {
        // present message to user that purchases were successfully restored
      } else {
        // present message to user that no purchases were found 
      }
    case .error:
      // present message to user that an error occurred
}

For Linked Paywalls the restore purchases call can also trigger the restore purchases handler. See the example below.

NamiPurchaseManager.restorePurchases() { state, newPurchases, oldPurchases, error in
  switch state {
    case .started:
      // optionally react to start of restore purchases
    case .finished:
      // additionally may want to check that there are more items in
      // newPurchases than oldPurchases
      if oldPurchases != newPurchases {
        // present message to user that purchases were successfully restored
      } else {
        // present message to user that no purchases were found 
      }
    case .error:
      // present message to user that an error occurred
  }
}

Did this page help you?