Integration Reference
Learn how to integrate Hyperswitch embeddable components into your React application using the SDK provider pattern for secure connector configuration management.
Integration Reference
This SDK allows you to embed Hyperswitch Control Center functionality, such as connector configuration, payments and refunds, directly into your application. It uses a provider pattern to manage authentication sessions via JWTs, ensuring your API keys never leak to the client.
Repository URL: https://github.com/juspay/hyperswitch-control-center-embedded
Demo URL: https://app.hyperswitch.io/hsdemo/?flow=embedded_components
Prerequisites & Compatibility
Before you begin, ensure your environment meets the following requirements:
Runtime: Node.js (v18+)
Framework: React (v18.x and v19.x)
Hyperswitch Credentials:
API-Key(Can be generated via Control Center)Profile-ID(The specific merchant profile you are configuring)
Support:
✅ Vite
✅ Webpack
✅ Next.js (App Router requires a Client Component, see Server-side rendering (Next.js) below)
✅ Create React App
Environments
The url option is the base URL of the Control Center that serves the components. The embedded token must be issued by the same environment as the url you render the component with. A sandbox token will not work with the production url, and vice versa.
Environment
Component url
Token API base URL
Sandbox
https://app.hyperswitch.io
https://app.hyperswitch.io/api
Production
https://live.hyperswitch.io
https://live.hyperswitch.io/api
Step 1: Backend Setup (Server-Side)
Security Warning: Never expose your Hyperswitch API-Key on the frontend. You must create a backend endpoint that acts as a proxy
Frontend → requests session → Your Backend → requests token (using API Key) → Hyperswitch API
Step 1.1: Create the Token Endpoint
Create a route (e.g., /embedded/hyperswitch) in your backend application.
Required Headers for Hyperswitch Call:
api-key: Your secret API key.
X-profile-id: The specific profile ID you want the embedded component to access. The token is scoped to this profile.
The Hyperswitch API responds with a JSON body containing the embedded token in the token field:
Step 2: Choose Your Integration Method
You must choose one:
Core (JavaScript Only / HTML)
React Integration
2A: HTML-JS Integration
2A.1 Install the package:
2A.2 Import the SDK in Your Application
Import (ES Module):
OR
Import (CommonJS):
2A.3: Example app.js Implementation
To remove a component, call component.destroy() (for example, payments.destroy()).
2B: React Integration
2B.1 Install the package:
The core package is installed as a dependency.
2B.2 Import the SDK in Your Application
2B.3 Example app.js Implementation
Key Concept: fetchToken is called as soon as loadHyperswitch() runs, and again automatically whenever the session expires. Wrapping loadHyperswitch() in a useState initializer (as below) ensures the instance, and therefore the initial token request, is created only once.
Server-side rendering (Next.js)
The components render their content in the browser only. In frameworks with server components, such as the Next.js App Router, render them inside a Client Component by adding the 'use client' directive at the top of the file:
You can then import this Client Component from any Server Component page.
Components
Connector Configuration
Core name: connectors | React: <ConnectorConfiguration />
A self-serve interface for your users to select payment processors, enter credentials and manage connector settings.
Payments
Core name: payments | React: <Payments />
Renders the payments list and payment details views.
List view: All payments for the profile, with search and filters.
Detail view: Full details of a single payment, including status, amounts, attempts and associated refunds.
Actions available from the payment detail view:
Refund
Payment status is succeeded or partially_captured
Issue a full or partial refund for the payment
Capture
Payment status is requires_capture
Capture a payment that was authorized with manual capture
Void
Payment status is requires_capture
Cancel an authorized payment before it is captured
Refunds
Core name: refunds | React: <Refunds />
Renders the refunds list and refund details views.
List view: All refunds for the profile, with search and filters.
Detail view: Full details of a single refund, including its status and amount.
Modals
Modals opened inside a component (for example, the Refund, Capture and Void dialogs) are displayed over the full host page by default. While a modal is open, the SDK stretches the component's iframe across the window and locks page scrolling, and restores both when the modal closes.
To keep modals inside the component, set fullPageModals to false:
Full-page modals rely on position: fixed. If an ancestor of the mount point has a CSS transform, filter, perspective or contain, or creates a stacking context below other page content, the modal can be clipped or covered. Set fullPageModals to false in that layout.
Customizing the appearance
Pass a theme configuration as initConfig to loadHyperswitch() to match the components to your brand. The theme applies to every component created from that instance.
All fields in initConfig are optional. Omitted fields use the default Control Center theme. See MerchantTheme (initConfig) in the API Reference below for the full list.
Content Security Policy
If you have deployed a Content Security Policy, include the Control Center origin (https://app.hyperswitch.io for sandbox, https://live.hyperswitch.io for production) in your frame-src directive.
API Reference
1. loadHyperswitch(options)
Initializes the SDK logic and returns a Hyperswitch instance. fetchToken is invoked immediately.
fetchToken
() => Promise<string | undefined>
Yes
Retrieves a fresh embedded token from your backend. Return the token string on success, or undefined on failure.
initConfig
MerchantTheme
No
Theme customization object. See MerchantTheme (initConfig) below.
2. HyperswitchProvider
Context provider that holds the authentication state.
hyperswitchInstance: The object returned by loadHyperswitch.
The React package also exports a useHyperswitchInstance hook that returns the instance from the nearest provider.
3. ConnectorConfiguration
The UI Component that renders the connector settings form. Accepts the component props listed under Payments and Refunds below.
url (string): The base URL of the Control Center that serves the component.
Sandbox: https://app.hyperswitch.io
Production: https://live.hyperswitch.io
Default (if omitted): http://localhost:9000 (local development only)
4. Payments and Refunds
<Payments /> renders the payments list and payment details. <Refunds /> renders the refunds list and refund details. In the core SDK, create them with hyperswitch.create('payments', options) and hyperswitch.create('refunds', options).
All components (ConnectorConfiguration, Payments, Refunds, and core hyperswitch.create(...) options) accept:
url
string
Base URL of the Control Center that serves the component. Defaults to http://localhost:9000 if omitted.
width?
string
Width of the component container. Defaults to 100%.
height?
string
Initial height of the component container. The component resizes to fit its content.
className?
string
Additional class names for the component container.
style?
Partial<CSSStyleDeclaration>
Inline styles for the component container.
fullPageModals?
boolean
Display modals over the full host page. Defaults to true.
onResize?
(dimensions: { width: number; height: number }) => void
Called when the component is resized.
Core component methods:
component.mount(target): Mounts the component to a CSS selector orHTMLElement. Returns the component.component.destroy(): Removes the component from the page and cleans up its event listeners.
5. MerchantTheme (initConfig)
primaryColor?
string
Primary accent color
backgroundColor?
string
Page background color
buttons?.primary?.backgroundColor?
string
Primary button background color
buttons?.primary?.textColor?
string
Primary button text color
buttons?.primary?.hoverBackgroundColor?
string
Primary button hover color
buttons?.secondary?.backgroundColor?
string
Secondary button background color
buttons?.secondary?.textColor?
string
Secondary button text color
buttons?.secondary?.hoverBackgroundColor?
string
Secondary button hover color
TypeScript types HyperswitchInitOptions, ElementOptions and MerchantTheme are exported from @juspay-tech/hyperswitch-control-center-embed-core.
Last updated
Was this helpful?

