This repository demonstrates how to integrate Hyperswitch embeddable components into your application using HyperswitchProvider and ConnectorConfiguration directly.
The embeddable components are:
- Hook:
app/components/useHyperswitch.ts- Custom hook to initialize Hyperswitch - Components:
HyperswitchProviderandConnectorConfiguration(from Hyperswitch SDK) - API Route:
app/api/embedded/hyperswitch/route.ts- Token generation endpoint
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env.localfile with:HYPERSWITCH_API_KEY=your_api_key HYPERSWITCH_PROFILE_ID=your_profile_id HYPERSWITCH_BASE_URL=https://app.hyperswitch.io -
Run the development server:
npm run dev
-
View the demo: Open http://localhost:3000 in your browser.
Use HyperswitchProvider and ConnectorConfiguration directly with the useHyperswitch hook:
'use client';
import { useHyperswitch } from './components/useHyperswitch';
export default function MyPage() {
const { hyperswitchInstance, components, isLoading, errorMessage } = useHyperswitch();
// Extract components for direct usage
const HyperswitchProvider = components?.HyperswitchProvider;
const ConnectorConfiguration = components?.ConnectorConfiguration;
if (isLoading) {
return <div>Loading Hyperswitch Control Center...</div>;
}
if (errorMessage) {
return <div>Error: {errorMessage}</div>;
}
if (!HyperswitchProvider || !ConnectorConfiguration || !hyperswitchInstance) {
return null;
}
return (
<HyperswitchProvider hyperswitchInstance={hyperswitchInstance}>
<ConnectorConfiguration url="https://app.hyperswitch.io" />
</HyperswitchProvider>
);
}The useHyperswitch hook returns:
hyperswitchInstance: The initialized Hyperswitch instancecomponents: Object containingHyperswitchProviderandConnectorConfigurationisLoading: Boolean indicating if the SDK is loadingerrorMessage: String with error message if initialization fails
The API route at app/api/embedded/hyperswitch/route.ts handles token generation. It requires:
HYPERSWITCH_API_KEY: Your Hyperswitch API keyHYPERSWITCH_PROFILE_ID: Your profile IDHYPERSWITCH_BASE_URL: Hyperswitch base URL (default: https://app.hyperswitch.io)
app/
├── components/
│ ├── useHyperswitch.ts # Hook to initialize Hyperswitch
│ └── HyperswitchEmbedded.tsx # Wrapper component (for backward compatibility)
├── api/
│ └── embedded/
│ └── hyperswitch/
│ └── route.ts # API route for token generation
├── page.tsx # Demo page using components directly
├── layout.tsx # Root layout
└── globals.css # Global styles
npm run build
npm start- The
useHyperswitchhook handles client-side SDK loading and initialization - The API route runs on the server and securely handles API keys
- Use
HyperswitchProviderandConnectorConfigurationdirectly for maximum flexibility - All dashboard styling is preserved and ready for merchant presentation