Host the page in any native app
Documents @snap4id-sdk/embed-protocol 1.0.0 · protocol 1.0
Without React Native, your app implements the host side of the bridge itself. It is a small, well-defined job: a WebView, a script injected at document start, a message handler, and your store code. The contract is the bridge protocol; field-level details are in bridge messages. Platform walk-throughs: iOS and Android.
TypeScript hosts can use @snap4id-sdk/embed-protocol directly (parseWebToHost, createHostToWeb,
hostShimSource, deliverScript). Other languages use the JSON Schemas it ships under schema/ and the shim text on
the platform pages.
What your host does
Section titled “What your host does”- Load only Snap4ID. Open
https://snap4.id/embed/{partnerId}(or/embed/{partnerId}/job/{jobId}to reopen a job) full screen. Allow main-frame navigation and accept messages fromhttps://snap4.idonly; open other links outside the WebView or not at all. - Inject the shim at document start. A short script, before any page script, defines
window.Snap4IdHost. Its only stack-specific part is the line that posts to your native code (webkit.messageHandlers…on iOS, your JavaScript object on Android). If your WebView injects it a moment late, the page waits up to 1.5 s. - Receive messages. Each page message arrives as one JSON string:
{ v: 1, id, type, payload, replyTo? }. Validate it; answer an invalid one that expected a reply witherror { code: 'invalid_message' }. - Send messages by running the shim’s deliver function with the JSON string:
window.__snap4idHostDeliver(json). The shim queues messages until the page is ready. - Answer
helloat once with yourhello(replyTo= the page hello’sid):protocolVersion: '1.0',platform,appVersion, the user’sconsent,capabilities. Check the page’strustModematches your setup. Then send the price: the page’shellonames your product per store (productIds, the ids you gave Snap4ID at onboarding; your app configures none). Look up the id for your store and answerprice.result { products }(replyTo= the page hello’sid;products: {}when your store has no price), which the page shows on its order button. Never hold yourhellofor the store. - Sell on
purchase.request. Buy the consumableproductIdbound to thepaymentRef(StoreKitappAccountToken, PlayobfuscatedProfileId) and keep the purchase unfinished. Then, by who checks purchases:- Snap4ID or our verifier server: answer
purchase.result { status: 'succeeded', receipt }; the page has the receipt checked; - your own backend: send the receipt to your backend; after it unlocked the job, answer
purchase.result { status: 'succeeded' }without a receipt (on failure:failedwith areason). Cancelled, pending and failed purchases answercancelled,pending,failed.
- Snap4ID or our verifier server: answer
- Finish after the unlock. The page had the receipt checked: when
job.completedarrives for the job. Your own backend: when it answered success. Aduplicate_purchaseerror names a purchase to finish and refund. - Deliver. Store
job.completedidempotently byjobIdand copy the files (links expire after 30 days): receiving the files. Handleartifact.save/artifact.shareif you granted them. - Navigate. Show
stepChanged.titlein your header; while the page reportedcanGoBack: true, the system back gesture sendsback; close oncloseand on a fatalerror. - Grant camera and files. Camera permission for
https://snap4.idand a file chooser for the photo library. - Recover at every start. Unlock purchases the store still holds unfinished (resend an unsolicited
purchase.resultwhen a pending one resolves while the page is open), and reopen paid jobs you have not delivered: the page sendsjob.completedagain.
Rules 6–11 are the ones that protect a paid photo; see payments and trust and delivery and recovery.
Flutter and other stacks
Section titled “Flutter and other stacks”Use a WebView that can inject a user script at document start and expose a JavaScript channel to native code
(for Flutter, for example, flutter_inappwebview). Build the shim with that channel’s post call as the
stack-specific line, and deliver messages by evaluating window.__snap4idHostDeliver(json). Everything else in the
list above is the same.
