Skip to content

feat: bind React payment elements to individual widget instances - #25

Merged
ArushKapoorJuspay merged 2 commits into
juspay:mainfrom
ArushKapoorJuspay:feat/multi-widget-support
Nov 25, 2026
Merged

ArushKapoorJuspay merged 2 commits into
juspay:mainfrom
ArushKapoorJuspay:feat/multi-widget-support

Conversation

@ArushKapoorJuspay

@ArushKapoorJuspay ArushKapoorJuspay commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Support multiple React payment widgets by registering callbacks and routing the existing ref.current.confirmPayment() method through the widget mounted by that component.

  • Generate a selector-safe container ID once per component with crypto.randomUUID(), stored in a ref. Retain the random fallback when the API is unavailable and preserve explicitly supplied IDs.
  • Register callbacks on the same widget instance that is mounted.
  • Update options without recreating the widget.
  • Destroy the owned widget during cleanup.
  • Return the existing sdk_not_ready error when confirmation is called before initialization completes, avoiding a null result that breaks merchant error handling.

How did you test it?

  • UUID simplification: ReScript and production builds passed; all three React integration tests passed. Browser probes verified distinct stable widget IDs, callback isolation, and cleanup in StrictMode with randomUUID() available, missing, and throwing.
Screen.Recording.2026-11-23.at.9.28.58.PM.mov
Screen.Recording.2026-11-23.at.9.23.53.PM.mov
Screen.Recording.2026-11-23.at.8.51.34.PM.mov
Screen.Recording.2026-11-23.at.8.51.04.PM.mov

Usage Notes

Requires the companion SDK changes: juspay/hyperswitch-web#1887. The existing ref.current.confirmPayment() signature remains unchanged; confirmation now targets the component's own widget.

Pass payment-method restrictions through options.allowedPaymentMethods:

<PaymentElement
  ref={paymentRef}
  options={{
    allowedPaymentMethods: [
      {
        paymentMethod: "wallet",
        paymentMethodTypes: [
          { paymentMethodType: "google_pay" },
          { paymentMethodType: "apple_pay" },
          { paymentMethodType: "paypal" },
        ],
      },
    ],
  }}
/>

To show all eligible wallets, omit paymentMethodTypes:

<PaymentElement
  ref={paymentRef}
  options={{
    allowedPaymentMethods: [{ paymentMethod: "wallet" }],
  }}
/>

Only methods returned by the backend and eligible for the current environment can render. Omitting the allowlist or passing null allows all available methods; an empty array allows none. paymentMethodTypes: [] excludes that family. Updates replace the previous allowlist, including its nested type arrays.


Version Update

  • I have bumped the package version in package.json and package-lock.json to 2.12.0 following semantic versioning.

Checklist

  • I ran npm run re:build and verified the build artifacts.
  • I reviewed the code for style, readability, and consistency.
  • I verified the changes are backward compatible (if applicable).
  • I tested this change in a real or simulated consuming project.
  • I updated documentation, README, or usage examples if necessary.

@ArushKapoorJuspay
ArushKapoorJuspay force-pushed the feat/multi-widget-support branch from 19d08db to 7236160 Compare November 23, 2026 16:21
@ArushKapoorJuspay
ArushKapoorJuspay merged commit ab78a51 into juspay:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants