Repository navigation
feat(vault): Android host and the native path for the card fields - #104
Open
Pradeep-kumar1202 wants to merge 10 commits into
Open
Pradeep-kumar1202 wants to merge 10 commits into
Pradeep-kumar1202 wants to merge 10 commits into
Conversation
Pradeep-kumar1202
force-pushed
the
feat/vault-native-android
branch
from
November 25, 2026 12:05
c2ffeff to
6e60c44
Compare
This was referenced Nov 25, 2026
Pradeep-kumar1202
force-pushed
the
feat/vault-native-android
branch
from
November 30, 2026 04:55
6e60c44 to
223bca7
Compare
Pradeep-kumar1202
added a commit
that referenced
this pull request
Dec 2, 2026
… command can see the old ones The form room applied a settings update from native in a passive effect, which runs a moment after the render commits. A tokenize command handled in that moment saw the previous settings, and so the previous session, as current. The update now runs in a layout effect, while the render commits; from then on form.tokenize() (#79's createDetachedCardForm) waits for the Host to draw the new settings, so the command uses the new session. Not covered here: a command that native code sends before the props update has reached the engine at all. Keeping that order is the native hosts' part (#104, #105).
Pradeep-kumar1202
force-pushed
the
feat/vault-native-fields
branch
from
December 2, 2026 06:38
0a1893a to
8e7517d
Compare
Pradeep-kumar1202
added a commit
that referenced
this pull request
Dec 3, 2026
… command can see the old ones The form room applied a settings update from native in a passive effect, which runs a moment after the render commits. A tokenize command handled in that moment saw the previous settings, and so the previous session, as current. The update now runs in a layout effect, while the render commits; from then on form.tokenize() (#79's createDetachedCardForm) waits for the Host to draw the new settings, so the command uses the new session. Not covered here: a command that native code sends before the props update has reached the engine at all. Keeping that order is the native hosts' part (#104, #105).
Pradeep-kumar1202
force-pushed
the
feat/vault-native-fields
branch
from
December 3, 2026 05:50
9344dfa to
f9f1768
Compare
Pradeep-kumar1202
force-pushed
the
feat/vault-native-android
branch
from
December 3, 2026 05:51
8f28874 to
5bc745b
Compare
Pradeep-kumar1202
force-pushed
the
feat/vault-native-fields
branch
from
December 3, 2026 06:33
f9f1768 to
0e0785c
Compare
Pradeep-kumar1202
added a commit
that referenced
this pull request
Dec 3, 2026
… command can see the old ones The form room applied a settings update from native in a passive effect, which runs a moment after the render commits. A tokenize command handled in that moment saw the previous settings, and so the previous session, as current. The update now runs in a layout effect, while the render commits; from then on form.tokenize() (#79's createDetachedCardForm) waits for the Host to draw the new settings, so the command uses the new session. Not covered here: a command that native code sends before the props update has reached the engine at all. Keeping that order is the native hosts' part (#104, #105).
Each field becomes a native view whose content runs in the vault's own JavaScript engine, when the app was rebuilt with this code, is on the new architecture and on a tested React Native version. Everywhere else the fields render in plain JavaScript as before. android/: the engine, forms, the field view and two modules. src/native/: the availability rule, the native form and field, and the choosers the package root now exports. createCardForm goes through the chooser too.
…ut the engine The merchant's React Native now sees a focused card field as its focused text input, so tapping outside a field and Keyboard.dismiss() close the keyboard as they do for the plain fields. The native view passes the blur and focus commands on to the field in the vault's engine. android/build.gradle compiles a stub (one empty package, no bundle) when the app is below React Native 0.82, on the old architecture, or sets HyperswitchVault_nativeFields=false. The app still builds and the fields render in plain JavaScript.
…ew on Android To find what was touched, the merchant's React Native walks down the Android views under the finger and takes the id of the deepest one. VaultFieldView let that walk go into the child hosting the vault engine's surface, so it came back with an id from the vault's engine. Both engines number their views from the same small integers, so the merchant's engine pressed whichever of its own views had that number: a button elsewhere on the screen, or another field. VaultFieldView now implements ReactCompoundViewGroup: interceptsTouchEvent returns true and reactTagForTouch returns the view's own id, so the walk stops at the field. The vault's engine still gets the touch through its own root view. Tested on the Android emulator, RN 0.82, 0.83, 0.84, 0.85, 0.86 (also a release build with R8), 0.87 and 0.88: main flow, keyboard, dark mode and vault API checks pass, and the merchant's engine sees no card text.
…a tokenize already delivered, scan card in the engine The vault's engine is a Hermes instance. In an app built with hermesEnabled=false React Native's Gradle plugin leaves the Hermes libraries out, so the first card field crashed the app. build.gradle now compiles the stub (plain fields) when Hermes is off, and VaultEngine.get catches any failure to create the engine, logs its class name, never retries, and the form falls back to the plain fields. A command that reached the bundle and then timed out (90 s), or whose form closed or engine stopped, is refused with "delivered": true. A tokenize may have saved the card by then; the merchant's side reports unknown_outcome for it, as the plain path does when a request is cut off. The comment that called 90 s longer than the vault's network timeouts was wrong: tokenize has none. When the app has @juspay-tech/react-native-hyperswitch-scancard, its package is added to the engine by class name, as react-native-svg's is, so the number field's scan button works on the native path.
…eact Native internals loaded only on the native path The chooser gives its ref one handle for the life of the form (src/native/handle.mjs). A native form that fails and switches to the plain fields no longer leaves a caller holding a dead handle: the payment-methods SDK reads the ref once, so every tokenize() after a fallback was refused with "The card form is not open." The handle forwards each call to the form mounted at that moment, and confirmPayment answers unsupported_configuration on the native path instead of being missing. tokenizeResultOf maps a refusal marked delivered to unknown_outcome, and builds its results with VaultResult's own helpers. fieldView.mjs and focus.mjs require React Native's internal files the first time a native field renders, not when the vault's root is imported. Imported at the top they ran in every app, and on the web (hyperswitch-client-core bundles the vault for a browser) they throw while loading.
…s back to the plain fields Every VAULT_FORM_ERROR after mount means the vault's form is gone (a crash in its root, a stopped engine, settings it cannot read), and so is whatever was typed. The native form then left blank fields and a tokenize() that blamed the payer. It now takes the same fallback as before mount, and a VAULT_FIELD_ERROR takes the whole form there too. In development builds a warning says so, with no text from the vault's engine. Android: invalidate() runs on React Native's background thread, so it now reads and closes the opened forms on main, where they change; a form asked for after that is not opened.
… plain field would On the plain path a field's outer view has no width of its own: in a column it stretches, and in a row it shrinks to its content. The native view filled its parent's width, so a field placed straight in a row (S2SDemo's saved-card CVC, styles.container.width 68 next to a flex: 1 selector) took the whole row and squeezed the selector to a sliver. When the box (styles.container) has a fixed width and the root sets no width or flex, the native view now takes the box's width plus its horizontal margins and the root's horizontal padding and border: the plain outer view's width. Otherwise it fills, as before.
…ain fallback, and a Jest mock In the merchant's engine the card fields now run only on the native path, so the card never sits in the merchant's JavaScript. Where the native path cannot run (no native module: the app was not rebuilt, an over-the-air update onto an older build, Expo Go, unit tests; the old architecture; a build without the bundle; a protocol mismatch; React Native outside 0.82 to 0.88), and when a native form does not start or stops, the form no longer switches to plain fields. It draws no field (the merchant's own content inside it still draws), calls the new onError prop once with unsupported_configuration and a message saying why, refuses every tokenize() with the same code and message, and says why on the console in a development build. The reasons name the app's setup only, never text from the vault's engine. The payment-methods SDK already passes unsupported_configuration on to the merchant. Inside an SDK's own engine (__HYPERSWITCH_SDK_ENGINE__) the plain fields still render: that engine is already separate from the merchant's. Android: the opt-out HyperswitchVault_nativeFields is removed (a build that still sets it is told it is ignored). An unsupported build still compiles the stub, and now warns that the card fields are not available in it, and why. Jest: the package ships an opt-in mock at "@juspay-tech/react-native-hyperswitch-vault/jest" (placeholder fields, a fixed test token, mockTokenizeResult()). The package never loads it itself: a run-time "is this a test?" switch could be flipped by other code in an app. The hosted bundles are unchanged (rebuilt: same bytes); only a comment in protocol.mjs changed.
…ields, one reason per failure, settings on save - Split screen (Android): VaultEngine follows the Activity that owns the vault's React host, the last one resumed. Pause and destroy reach React Native only for that Activity; when another followed Activity is still in front, the host moves to it. React Native 0.82 to 0.88 asserts on a pause from any other Activity, which ended the app with two vault screens open at once. - Detached fields stay native only: in the app's own engine a card field outside a <CardForm> draws nothing (with a development-build message), and the root createDetachedCardForm refuses (no field, tokenize() gives unsupported_configuration). Both still work in an SDK's own engine. - One failure, one answer: a save that never reached the vault's engine gives unsupported_configuration with the reason the form reports to onError (did not start, stopped, or a field stopped; the first reason only), as every later save does. - Settings on a save: new settings go to native as the render that made them commits (a layout effect), so a render React drops never reaches the form. Android attaches the settings a save was accepted with, and refuses, unsent, a save queued during startup whose settings changed before it could run (tokenization_failed, try again). The VaultCommand spec lists `settings`. - The hosted entry sets __HYPERSWITCH_SDK_ENGINE__ again, in the PR whose availability check reads it. Tests: a save that never reached the engine agrees with onError and later saves; a save refused because its settings changed is an ordinary, retryable failure.
Pradeep-kumar1202
force-pushed
the
feat/vault-native-android
branch
from
December 3, 2026 06:34
5bc745b to
79c5305
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The native path for the vault's card fields, on Android, and the JavaScript that chooses it.
In an app rebuilt with this code, on the new architecture, with Hermes, and on a tested React Native version (0.82 to 0.88), each card field becomes a native view whose content runs in the vault's own JavaScript engine. The card number and CVC are typed into that engine and never reach the merchant's. Everywhere else there are no card fields: the form reports
unsupported_configurationand why (see "When the native path cannot run").The merchant's code does not change: same components, same props, same events, same
tokenize()result. One optional prop is new:onError, called when the card fields cannot run.createDetachedCardForm: one card across separate React rootsEach is based on the one before it. Merge order: #79, #103, #104, #105, then the release pull request (README, release notes, version 2.0.0). Labelled
DO NOT MERGEuntil the stack is ready.Why
Today the fields are React Native text inputs in the merchant's engine, beside every npm package the merchant installed. hyperswitch-web keeps each field in an iframe from the SDK's domain. This is the React Native equivalent: one engine boundary per form.
How it works
In the merchant's engine (
src/native/)choosers.mjsCardFormand the four fields. A form renders the native path, or (since 2 Dec) a refusing form that draws no field and reports why; a field follows its formhandle.mjsCardFormgives its ref, for the life of the form. It forwards each call to the form mounted at that moment, so a form that stops (and is replaced by the refusing form) keeps answering a caller that kept the handle (the payment-methods SDK reads the ref once)availability.mjs,rule.mjsNativeCardForm.mjsonReady/onChange, and gives the same handle (tokenize,reset,focus)NativeField.mjsout.mjsstyles.rootgo on the native view, the rest goes inside. Also reads answers back: a tokenize that already reached the vault's engine and then got no answer isunknown_outcome, never "failed"fieldView.mjsfocus.mjscreateCardForm()renders the chooser too.fieldView.mjsandfocus.mjsreach React Native internals by path; they arerequired only when a native field first renders, so they never load in apps on the plain path or on the web.In native code (
android/)VaultEngine.kthyperswitch-vault-fields.bundlefrom the app's assets; packager access and developer support are off in every build type. A fixed package list: React Native's own, react-native-svg's and scan card's when the app has them (found by class name), and the hosted package. If the engine cannot be created, the failure is logged by class name, remembered, never retried, and every form falls back to the plain fieldsVaultForm.ktdeliveredHyperswitchVaultFormsModule.ktHyperswitchVaultHostedModule.ktHyperswitchVaultFieldViewManager.ktReactCompoundViewGroup), so a tap on a field never resolves to a view of the other enginesrc/stub/andbuild.gradleWhen the native path cannot run (since 2 Dec: no plain fallback)
onErroronce withunsupported_configurationand a reason naming the cause (never text from the vault's engine), refuses everytokenize()with the same code and message, and says why on the console in a development build. Inside an SDK's own engine (__HYPERSWITCH_SDK_ENGINE__) the plain fields render: that engine is already separate.hermesEnabled=false: the engine is a Hermes instance and the app would have no Hermes library), the library compilessrc/stub(one empty package, no bundle), so the app still builds, and the Gradle log warns that the card fields are not available in it, and why. There is no opt-out:HyperswitchVault_nativeFieldsis ignored, with a warning.Files
android/(7 Kotlin files, the stub, build files),src/native/(9 files),src/specs/(3 Codegen specs),react-native.config.js,test/native.test.mjssrc/standalone-entry.mjs(root exports bound to the choosers),src/createCardForm.mjs,src/hosted/protocol.mjsandroots.mjs(names shared by both JavaScript sides),rollup.config.mjs(React Native's own files stay external),package.json(codegenConfig,files, test script)BUNDLE-PROVENANCE.mdImpact on existing merchants
unsupported_configuration("rebuild the app"). This is a breaking change (hence 2.0.0): apps outside the supported setup lose card fields until they move to it.jest.mock('@juspay-tech/react-native-hyperswitch-vault', () => require('@juspay-tech/react-native-hyperswitch-vault/jest')).reset,focusandclearbehave as the plain fields do (see Testing).What the native path protects, and what it does not
It protects the card number and CVC from code in the merchant's JavaScript that reads or records inputs: a compromised package, a session-replay or analytics SDK. It does not protect against native code in the app, or against code in the merchant's engine written to attack the vault: such code can force the plain fallback, or change the settings it passes (point
customEndpointsat its own server, or swapsdkAuthorization). Stopping that needs a design change, not this pull request.Testing
Since 2 Dec (native fields only): unit tests 91/91; the refusing form checked on a stand-in React Native with React's test renderer (no native module, React Native 0.81, a form that does not start, a form that stops:
onErroronce,tokenize()refused with the same message, the merchant's label still drawn, no text from the vault's engine); the Jest mock rendered. Not yet on a device. The results below were run before 2 Dec, with the plain fallback and the opt-out switch.Unit tests in the vault:
yarn test, 89 pass at this head (11 new here: the rule, what crosses to the other engine, thedeliveredmapping, the one handle, and the fixed-width box).On a device: Android 17 emulator, the app installs only the payment-methods SDK, the vault and react-native-svg (the live merchant's setup), with the merchant's screen unchanged. On this code, React Native 0.86, release builds:
clear(),reset(),focus()HyperswitchVault_nativeFields=falseUpdating props for Surface, nosdkAuthorizationhermesEnabled=falseEvery React Native version, on this code (the whole stack, both platforms, release builds, one row at a time): 35 of 35 rows pass.
Device logs after the flows: no
Updating props for Surfaceline and nosdkAuthorizationin any of the 80 Android captures, nor on iOS 0.86 and 0.88 (read right after their runs).Not tested
Tested since the review (26 Nov, React Native 0.86.3, native and plain paths): the form's first
onChangebefore typing, accessibility labels on the fields,onReady, the cardholder name field, rotation and back, background and back (the card is kept and tokenizes), memory with one form open (+42 MB) and the time to draw the fields (+0.2 s). The merchant's demo app (S2SDemo, React Native 0.87.1, its own code unchanged): a saved card's CVC and a new card with the name on it, both typed into the native fields; both payments succeeded, and the device log held no card number,sdkAuthorizationor client secret.Not in this PR
HyperswitchVaultFormon the native path: it still renders plain fields in the merchant's engine (open: port it, or make it refuse).Note for the reviewer
VaultEngine.deliver); Android merges same-named events on one view, so the field event turns that off (canCoalesce); the merchant's React Native must be told a card field is focused, or the keyboard cannot be closed from outside (focus.mjs); and React Native's touch search must not walk into the vault's views, or a tap presses another view of the merchant's screen (VaultFieldViewimplementsReactCompoundViewGroup).fieldView.mjsis hand-written view config. React Native normally generates it from the spec with a Babel plugin when the app is built; this package ships built JavaScript, so the plugin never sees it. It must matchsrc/specs/HyperswitchVaultFieldViewNativeComponent.tsand the view manager.VAULT_FIELD_ERROR, or a form error after the form is up, now stops the form instead of leaving empty boxes (since 2 Dec it reportsunsupported_configuration; before, it switched to plain fields), andHyperswitchVaultFormsModule.invalidate()reads the open forms on the main thread (16300bd). A native field whose box has a fixed width (styles.container.width) took the whole row; it now takes the width the plain field would (223bca7, found in S2SDemo's saved-card CVC).Pressableof the merchant's screen has not been checked on a device.