Docs
SDK

Callbacks

Every callback the SDK calls, its arguments, what its return value means and in which order things happen.

Callbacks are options of present, embedded screens and auto placements. The web component has properties and events instead (see Web component).

Signatures

onPurchase?: (args: { packageId: string; product?: ProductInfo; answers: Answers }) => Promise<boolean | void> | boolean | void;
onRestore?: () => Promise<boolean | void> | boolean | void;
onAction?: (args: { actionId: string; answers: Answers }) => Promise<boolean | void> | boolean | void;
onAnswer?: (args: { fieldId: string; value: string | string[] | undefined; answers: Answers }) => void;
onClose?: () => void;
onSkip?: (args: { reason: 'frequency_cap' | 'audience' | 'holdout' }) => void;
onOpenUrl?: (url: string) => void;
onError?: (error: unknown) => void;
onResult?: (args: { placement: string; result: PurchaseResult }) => void; // auto placements only

product is your own ProductInfo for that package, if you passed products. Mobile has no onResult option on present: its result is closed or skipped, and an embedded screen's onFinish receives the same result. onClose and onSkip work as on web (below), and are also called for auto placements and embedded screens.

CallbackReturn value
onPurchasetrue (on web also nothing): purchased. false: cancelled. Throw: failed. May be async.
onRestoretrue (on web also nothing): restored. false: nothing to restore. May be async.
onActionfalse keeps the screen open. Anything else closes it. May be async.
onAnswer, onClose, onSkip, onOpenUrl, onError, onResultnone

onPurchase

Run your checkout here. While it runs the screen shows a spinner and ignores taps.

  • Return true: the SDK records a purchase and present finishes with purchased and the packageId. On web, returning nothing counts as true.
  • Return false (the user cancelled): a cancel is recorded and the screen stays open.
  • Throw: a purchase error is recorded, the screen stays open and onError receives the error.
  • With no onPurchase, a purchase tap calls onError: UIKit: pass onPurchase to handle purchase buttons on web, Miniwall: pass onPurchase in PresentOptions to handle purchase buttons on mobile.

onRestore

The Restore purchases button only appears when you pass onRestore. Return false to say nothing was restored: the screen stays open. Otherwise a restore is recorded and present finishes with restored.

App Store review and Play policy expect a restore option on screens that sell subscriptions. Pass onRestore when the screen sells one.

onAction

Called when a "Run your code" button is pressed. actionId is the ID set in the editor. It runs while the screen is busy. Screen changes ("Go to another screen", "Back to previous screen") do not call it. With no onAction, the screen closes and present finishes with action (an embedded screen's onFinish receives action). On web, mountPaywall never closes the screen.

onAnswer

Called each time a question changes. The value is the option ID, a list of option IDs for multiple choice, the typed text, or nothing once cleared. See Answers.

onClose

On mobile it is called when the user closes the screen (close button, Back, swipe down, a tap outside, a toast timing out): the result is closed. It is not called when the screen ends with a purchase, restore or action. On web it is called whenever a presented screen ends with closed: a close button, Esc, a backdrop click, a toast timing out, or another presentPaywall replacing it. With mountPaywall it is called when the close button is pressed.

onSkip

Called (web and mobile; on mobile reason is a SkipReason on iOS and Android, and a string on React Native and Flutter) when a placement's targeting chose to show nothing. See Targeting attributes.

onOpenUrl

Called with the link a user pressed. The default opens it in a new tab with noopener,noreferrer on web, and in the system browser on mobile. Only http, https, mailto, tel and links that start with a single / reach it. Others call onError.

onError

Receives errors from the renderer, from your own callbacks that throw and from links that were refused. On mobile it also receives linked screens that fail to load.

Load failures of present (and mountPaywall on web) throw or reject instead. In auto placements, embedded screens, the React Paywall component and the web component they go to onError (or the uikit-error event). See Errors.

When your handler never answers

In React Native and Flutter your handler runs in JavaScript or Dart. If it does not answer within 10 minutes (the code was reloaded, or it never replies) the screen is released and treated as "not bought". A store payment sheet can stay open for minutes, so the limit is long. Make the handler always return.

Order for a purchase

  1. The user taps buy: purchase_click is recorded.
  2. onPurchase runs.
  3. A purchase (or cancel, or error) is recorded.
  4. present finishes with purchased, or the screen stays open. An embedded screen stays.

On this page