Integration Guide

This SDK allows you to embed the Hyperswitch connector configuration directly into your React 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-embeddedarrow-up-right

Prerequisites & Compatibility

Before you begin, ensure your environment meets the following requirements:

  • Runtime: Node.js (v18+)

  • Framework: React (v18.x - 20.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

    • ✅ Create React App

Step 1: Client Installation

Since the package is currently hosted on GitHub (not yet on the public npm registry), you must install it by pointing your package.json to the specific repository.

  1. Open your package.json file.

  2. Add the following line to your dependencies object:

  3. Run the installation command in your terminal:

Step 2: 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.

The flow is: Frontend → requests session → Your Backend → requests token (using API Key) → Hyperswitch API

2.1. Create the Token Endpoint

Create a route (e.g., /embedded/hyperswitch) in your backend application (Node/Express example below).

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.

Step 3: Frontend Integration (React)

Now, configure the React application to load the SDK and consume the token from your new backend endpoint.

3.1. Import Components

Import the necessary modules. Note that Tailwind CSS is used for styling in this example.

3.2. Implement the Component

The core logic relies on the loadHyperswitch function. This function takes a fetchToken callback.

Key Concept: The fetchToken function is "lazy." It is called:

  1. When the component first mounts.

  2. Automatically whenever the SDK detects the session has expired (auto-refresh).

API Reference

loadHyperswitch(options)

Initializes the SDK logic.

  • options.fetchToken () => Promise<string | undefined>:

    • Required. A function that retrieves a fresh JWT from your backend.

    • Should return the JWT string on success.

    • Should return undefined on failure.

<HyperswitchProvider>

Context provider that holds the authentication state.

  • hyperswitchInstance: The object returned by loadHyperswitch.

<ConnectorConfiguration>

The UI Component that renders the settings form.

  • url (string): The base URL for the Hyperswitch Dashboard API.

    • Sandbox: https://app.hyperswitch.io/api

    • Default: http://localhost:9000 (Used for local development)

Last updated

Was this helpful?