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

React Native & Expo

Integrate OnsideKit into a React Native or Expo app with the @onside-io/react-native-onsidekit package — an Expo module over the native iOS SDK.

The @onside-io/react-native-onsidekit package lets you use OnsideKit from JavaScript/TypeScript in a React Native app that ships to iOS. It is built on the Expo Modules API and mirrors the native API one to one: the same objects and calls as Onside in Swift, with no logic of its own. Products, payments and transactions are native-backed objects, so the Core Concepts and Error Reference pages apply as is.

  • Requires: Expo SDK 58+, React Native 0.88+, Xcode 27+, iOS 17.4+

  • Works with: Expo prebuild / development builds and bare React Native projects

  • Platforms: iOS only — Android is not supported

The package contains native code, so it does not run in Expo Go. Use a development build or a bare React Native project.

The package version always matches the native OnsideKit version it bundles: @onside-io/react-native-onsidekit@3.0.1 contains OnsideKit 3.0.1. The OnsideKit.xcframework ships inside the npm package, so pod install needs no extra sources or network access, and your lockfile pins the exact SDK build. The framework includes its device dSYM, so Xcode adds it to your archive and crash reporters symbolicate OnsideKit frames automatically.

1. Install the package

npm install @onside-io/react-native-onsidekit

2. Configure the iOS project

Add the config plugin to app.json (or app.config.js):

{
  "expo": {
    "ios": {
      "deploymentTarget": "17.4"
    },
    "plugins": [
      [
        "@onside-io/react-native-onsidekit",
        {
          "callbackScheme": "myapp-onside",
          "applePayMerchantId": "merchant.com.yourcompany.app",
          "storeKitConfigurationPath": "./TestProducts.storekit"
        }
      ]
    ]
  }
}
Option
Required
What the plugin does

callbackScheme

Yes

Registers the scheme in CFBundleURLTypes and adds onside to LSApplicationQueriesSchemes. Prebuild fails if it's missing or empty.

applePayMerchantId

No

A merchant ID or an array of IDs, added to the com.apple.developer.in-app-payments entitlement. See Apple Pay.

storeKitConfigurationPath

No

Path (relative to the project root) to a .storekit file. The file is copied into the iOS project and added to the app bundle for local testing.

The plugin also raises the iOS deployment target to 17.4 if it is lower.

Then generate the native project:

  1. Install Expo modules support with npx install-expo-modules. The package depends on expo.

  2. Set the iOS deployment target to 17.4 or later (platform :ios, '17.4' in the Podfile and in the Xcode target).

  3. Run cd ios && pod install.

  4. In Info.plist, add onside to LSApplicationQueriesSchemes and your callback scheme to CFBundleURLTypes — see Initializing the SDK.

  5. Make sure incoming URLs reach React Native Linking, so you can forward them to Onside.handle(url) — see the next step. The React Native 0.88 app template already does this; if you replaced its AppDelegate or SceneDelegate, forward scene(_:openURLContexts:) to RCTLinkingManager.

  6. For Apple Pay, add the merchant ID to the Apple Pay capability of your target — see Apple Pay.

3. Initialize and forward callback URLs

Initialize the SDK once at startup, before any other Onside call, then set the callback scheme and forward every incoming URL to Onside.handle(url). The package does not intercept URLs on its own — forward both the URL the app was launched with and URLs received while it runs:

Onside.handle(url) resolves to false for URLs that are not OnsideKit callbacks, so you can route those yourself. Calling any Onside API before initialize() is undefined behavior.

initialize takes the same options as the native call — see Initializing the SDK:

4. Observe the payment queue

Register the transaction listener early — at startup, before the first purchase — so transactions left unfinished in a previous session are delivered too. Keep a long-lived reference to the queue object (for example, in a module-level variable): the native observer is removed when the JS object is garbage-collected.

See The Payment Queue & Transactions for the transaction lifecycle and why every purchased, restored, or failed transaction must be finished.

5. Fetch products

makeProductsRequest returns a request object that reports through events. Keep a reference to it until it finishes:

invalidProductIdentifiers and unsupportedProductIdentifiers list the identifiers that were not returned. See Fetching Products.

6. Make a purchase

add resolves once the payment is accepted into the queue — not when the purchase completes. The result arrives through updatedTransactions. If the user is not logged in, the login flow is presented automatically. See Making a Purchase.

Other features

Restore purchases — restored transactions arrive through updatedTransactions; the end of the restore is reported by queue events:

Login & account — await Onside.requestLogin(), await Onside.logout(), await Onside.presentPaymentMethodsManager(). See Authentication and Managing Payment Methods.

Delegate options — the native OnsideDelegate is configured with plain values:

Payment queue delegate — approve or veto purchases; handlers may be async. A missing handler, or one that throws, counts as true:

See Handling Storefront & Price Changes.

External login — return your app's account token, or null to fall back to the regular login. See External Login:

Appearance — await Onside.appearance().setThemeMode('dark') ('auto' | 'light' | 'dark', or null to reset). See Appearance & Theming.

Attribution & events — await Onside.getAttributionMetadata() resolves to { referer: string | null }; await Onside.track(event, parameters) sends an analytics event. OnsidePredefinedEvent and OnsidePredefinedEventParameter hold the predefined names. See Attribution and Event tracking.

Signed in-app purchase history — await Onside.makeSignedInAppsHistoryRequest() resolves to a request object with the same start() / didReceive / didFail / didFinish shape as the products request; didReceive delivers { dataBase64, string }. See Signed In-App Purchase History.

Installation id & source — publishers that emit the current value and every change:

Onside.installationSource emits 'appStore' | 'onside' | 'unknown' (or null). See Debugging & installationId.

Local testing — pass storeKitConfigurationName to initialize, and await Onside.resetLocalTestingState() to clear local purchase history. See Local Testing.

Errors

Native errors reach JavaScript as string codes that match the native enum cases (.loginDiscarded → 'loginDiscarded'). A code the package version doesn't know maps to 'unknown'.

  • Rejected promises — add, restoreCompletedTransactions, requestLogin, presentPaymentMethodsManager, getAttributionMetadata and makeSignedInAppsHistoryRequest reject with an error whose code property holds the code.

  • Request events — didFail on products and signed-history requests, and the queue's restoreCompletedTransactionsFailed, receive the code as their argument.

  • Failed transactions — transaction.error holds the code.

Where
Type
Codes

requestLogin

OnsideLoginErrorCode

loginDiscarded

queue.add

OnsideAddPaymentErrorCode

loginDiscarded, rejectedAfterLogin, notSupportedForExternalLogin, applePayRequired, internalError

queue.restoreCompletedTransactions

OnsideRestoreRequestErrorCode

loginDiscarded, internalError

restoreCompletedTransactionsFailed

OnsideTransactionsRestoreErrorCode

cancelled, connectionError, appNotRegistered, serviceUnavailable, internalError

transaction.error

OnsidePaymentTransactionErrorCode

cancelled, presentationFailed, internalError

presentPaymentMethodsManager

OnsidePaymentMethodsManagerErrorCode

loginDiscarded, notSupportedInLocalTesting, notSupportedForExternalLogin, presentationFailed

Products didFail

OnsideProductsRequestErrorCode

cancelled, connectionError, appNotRegistered, invalidProductIdentifier, serviceUnavailable, internalError

getAttributionMetadata

OnsideAttributionMetadataErrorCode

connectionError, appNotRegistered, serviceUnavailable, internalError

Signed history

OnsideSignedInAppsHistoryErrorCode

notLoggedIn, notSupportedInLocalTesting, cancelled, connectionError, appNotRegistered, serviceUnavailable, internalError

Every type also includes unknown. For what each code means, see the Error Reference.

Object lifetime

Products, responses, payments, transactions, requests and the payment queue are native-backed shared objects. A native object lives while its JS object is reachable:

  • Keep the payment queue in a long-lived variable — when it is collected, its transaction observer and delegate are removed.

  • Keep requests referenced until didFinish or didFail.

  • Remove listeners you no longer need with subscription.remove() or removeAllListeners(eventName).

See Threading & Object Lifetime for the native rules.


API Reference

Onside

Member
Description

initialize(options?: { disableSSLPinning?: boolean; storeKitConfigurationName?: string | null }): Promise<void>

Initialize the SDK. Call once, before anything else.

isInitialized(): Promise<boolean>

Whether initialize has been called.

setCallbackScheme(scheme: string | null) / getCallbackScheme()

The URL scheme the Onside app returns to.

setApplePayMerchantIdentifier(id: string | null) / getApplePayMerchantIdentifier()

Apple Pay merchant ID.

handle(url: string): Promise<boolean>

Forward an incoming URL; false if it isn't an OnsideKit callback.

setDelegate(delegate: OnsideDelegate | null)

Login method, region hint, window level, orientation override.

setExternalLoginDelegate(delegate: OnsideExternalLoginDelegate | null)

Supply an external account token.

appearance().setThemeMode(mode: 'auto' | 'light' | 'dark' | null)

Global theme.

requestLogin(): Promise<void>

Present the login flow.

logout(): Promise<void>

End the current session.

presentPaymentMethodsManager(): Promise<void>

Show the saved-cards manager.

makeProductsRequest(ids: string[]): OnsideProductsRequest

Create a products request.

makeSignedInAppsHistoryRequest(): Promise<OnsideSignedInAppsHistoryRequest>

Create a signed purchase-history request.

defaultPaymentQueue(): OnsidePaymentQueue

The shared payment queue.

getAttributionMetadata(): Promise<OnsideAttributionMetadata>

Attribution metadata.

track(event: string, parameters: Record<string, OnsideEventParameterValue>): Promise<void>

Send an analytics event.

installationId, installationSource

Publishers: subscribe(listener) returns a subscription with remove().

resetLocalTestingState(): Promise<void>

Reset local-testing purchase history.

OnsidePaymentQueue

Member
Description

add(payment: OnsidePayment): Promise<void>

Start a purchase. Resolves when the payment is enqueued.

finishTransaction(transaction): Promise<void>

Finish a purchased, restored or failed transaction.

restoreCompletedTransactions(): Promise<void>

Restore non-consumables and subscriptions.

getTransactions(): Promise<OnsidePaymentTransaction[]>

Unfinished transactions in the queue.

getStorefront(): Promise<OnsideStorefront | null>

The current storefront.

setDelegate(delegate: OnsidePaymentQueueDelegate | null)

shouldContinue / shouldContinueAfterLogin handlers.

Events

updatedTransactions, removedTransactions, restoreCompletedTransactionsFinished, restoreCompletedTransactionsFailed, didChangeStorefront.

Types

  • OnsideProduct — productIdentifier, localizedTitle, localizedDescription, iconUrl, price, subscriptionGroupIdentifier (the localized group name, not a stable identifier), subscriptionPeriod. See Models.

  • OnsidePayment — new OnsidePayment(product); product, appAccountToken.

  • OnsidePaymentTransaction — id, transactionIdentifier, originalTransactionIdentifier, payment, transactionState ('purchasing' | 'purchased' | 'restored' | 'failed' | 'unknown'), storefront, error, isSame(other).

  • OnsideStorefront — id, countryCode.

  • OnsidePrice — value, currencyCode; OnsidePeriod — unit ('day' | 'week' | 'month' | 'year' | 'unknown'), numberOfUnits.

All types are exported from the package with full TypeScript definitions.

Common issues

  • Cannot find native module 'OnsideKit' — you are running in Expo Go, or the native project wasn't rebuilt after installing the package. Run npx expo prebuild (or pod install) and rebuild the app.

  • Prebuild fails with `callbackScheme` must be configured — add the callbackScheme option to the config plugin.

  • The app crashes at launch with "UIScene life cycle is required" — apps built with the iOS 27 SDK must use the scene-based life cycle. Use Expo SDK 58 or later, whose app template already adopts it.

  • Login or payment never returns to the app — the scheme in setCallbackScheme doesn't match the one in Info.plist, or incoming URLs aren't forwarded to Onside.handle(url).

  • Transactions from a previous session never arrive — the updatedTransactions listener was added too late, or the queue object was garbage-collected. Register it at startup and keep a reference.

Last updated

Was this helpful?