For the complete documentation index, see llms.txt. This page is also available as Markdown.

Restoring Purchases

Let users restore their previous non-consumable and subscription purchases on a new device or after reinstalling.

Provide a Restore Purchases button (for example in your settings screen) so users who reinstalled your app or switched devices can regain access to their non-consumable and subscription purchases without paying again.

Trigger a restore

@MainActor func restoreCompletedTransactions(
    completion: ((Result<Void, OnsidePaymentQueueRequestRestoreError>) -> Void)?
)
func restoreTapped() {
    Onside.defaultPaymentQueue().restoreCompletedTransactions { result in
        if case .failure(let error) = result {
            print("Couldn't start restore: \(error)")   // .loginDiscarded
        }
    }
}

Receive restored transactions

Restored purchases are delivered to the same onsidePaymentQueue(_:updatedTransactions:) observer method, with a state of .restored. Handle them exactly like a purchase — unlock content and finish the transaction:

case .restored:
    unlockContent(for: transaction.payment.product.productIdentifier)
    queue.finishTransaction(transaction)

(See Making a Purchase for the full switch.)

Know when the restore finishes

After all restored transactions are delivered, OnsideKit calls one of two optional observer methods. Use them to update your UI (e.g. hide a spinner):

Restore errors

OnsideTransactionsRestoreError:

Case
Cause

.cancelled

The restore was cancelled.

.connectionError

Network failure.

.serviceUnavailable

Server returned 5xx.

.appNotRegistered

The app/install isn't recognized by Onside (HTTP 404).

.internalError

Parsing or other unexpected error.

See the full Error Reference.

Last updated

Was this helpful?