Skip to content

Component details

Documents @snap4id-sdk/app-embed 1.0.0

createSnap4IdClient(config) once per app process; it throws ConfigurationError (configuration_invalid) for a bad config. The fields that shape your integration (all fields: component API):

Field Meaning
partnerId from onboarding
purchases 'built-in', or your own store code
onVerifyPurchase present ⇒ your own backend checks purchases (your own backend); absent ⇒ the page has them checked (Snap4ID, or our verifier server)
onCompleted(completion) at least once per paid job until it resolves
onError(error) typed errors: error codes
namespace one per signed-in user, so each keeps their own jobs and purchases
theme, copy optional theme and text overrides
origin default https://snap4.id; leave it unset in release builds

Call client.start() at every app start: it attaches the store listeners and runs recovery. For a background task before any UI, await recover(config) does the same headless.

The product is the in-app purchase item you create in your store (App Store Connect, Google Play Console). You give its id to Snap4ID at onboarding, one per store; your app configures nothing. The page names the product and asks the component for its store price, which it shows on its order button:

  1. The page’s hello carries your ids from your partner configuration: { "ios": "pl.example.app.idphoto", "android": "pl.example.app.idphoto" }.

  2. The component answers the hello at once, then looks up the price of the id for its store (the built-in store through expo-iap; your own store code through getPrice) and sends it to the page (price.result):

    { "products": { "pl.example.app.idphoto": { "amount_minor": 1999, "currency": "PLN", "display_price": "19,99 zł" } } }

No price (an id missing for this store, a product the store does not know, a store error) ⇒ the page shows the order button without a price, and onError gets the non-fatal price_unavailable naming the id.

  • onStateChange reports the step (capture, processing, payment, done) and a title for your header.
  • Android back goes to the page while it can go back, then onClose({ reason: 'back' }).
  • <Snap4IdResume client> (once, near the root) reopens queued jobs in hidden WebViews one at a time.
  • Done screen and Save / Share: done screen.

The flow opens only https://snap4.id in release builds (plus exact HTTPS origins in trustedOrigins, only for a pre-production Snap4ID you were given). Development builds also allow http://127.0.0.1:<port>, http://10.0.2.2:<port> (Android emulator) and private LAN addresses, so a phone can reach your dev machine. A test release build (e.g. for StoreKit or Play testing against the fake page) can load http://127.0.0.1:<port> and http://10.0.2.2:<port> with allowLocalOrigins: true, never public http or LAN hosts; never set it in a build you ship. Anything else fails with origin_rejected. Messages and navigation are accepted from the allowed origin only. Do not wrap the page in iframes of your own: the origin check sees the main frame only.

The bridge must exist before the page’s first script. The package ships a small native module (autolinked; rebuild after installing) that registers it with AndroidX WebKit addDocumentStartJavaScript. On a WebView without DOCUMENT_START_SCRIPT the page still connects: it waits up to 1.5 s for a late bridge. The component also handles camera capture, the Android file chooser and a lost WebView process (it reloads the job).

onCompleted receives { jobId, orderCode, artifacts }, each artifact { code, title, mimeType, filename, url, expiresAt } (for example the main photo, a print sheet image and PDF, a transparent PNG: the list depends on the document). client.downloadArtifacts(completion) copies them into your app’s storage and rejects until every file is stored, so the component calls onCompleted again. client.files saves or shares a stored file (else a temporary copy of the link); client.downloads lists the stored files. Details and examples: receiving the files.

onBridgeMessage receives the redacted bridge traffic (no receipts, store secrets or signed link query strings). The component writes no bridge traffic to storage; keep persistBridgeLog for development.