Headless SDK
Juspay Hyperswitch is designed to facilitate the integration and management of payment-related functionalities in a decoupled or headless architecture with flexibility to customize your checkout UI.
Customize the payment experience using Headless functions
1. Initialize the Hyperswitch SDK
Initialize Juspay Hyperswitch Headless SDK onto your app with your publishable key. To get a Publishable Key please find it here.
Standard Implementation
// Source Hyperloader on your HTML file using the <script /> tag
hyper = Hyper.init("YOUR_PUBLISHABLE_KEY",{
customBackendUrl: "YOUR_BACKEND_URL",
//You can configure this as an endpoint for all the api calls such as session, payments, confirm call.
});Advanced / Extended Configuration (Beta / Upcoming)
In platform setups or custom deployment environments (e.g., dedicated backend, custom telemetry, or asset routing), you can pass an extended configuration object to Hyper:
const hyper = Hyper.init({
publishableKey: "YOUR_PUBLISHABLE_KEY",
profileId: "YOUR_PROFILE_ID",
platformPublishableKey: "pk_platform_xxxx", // Required for platform or connected account setups
customConfig: {
customEndpoint: "https://dev.hyperswitch.io/api", // Primary Hyperswitch API base URL
overrideCustomBackendEndpoint: "https://sandbox.hyperswitch.io", // Custom backend API endpoint
overrideCustomConfirmEndpoint: "https://sandbox.hyperswitch.io", // Custom payment confirm calls endpoint
overrideCustomSDKConfigEndpoint: "https://config.example.com/api", // Custom SDK config fetch endpoint
overrideCustomLoggingEndpoint: "https://logs.example.com/logs", // Custom beacon/telemetry logging endpoint
overrideCustomAssetsEndpoint: "https://assets.example.com", // Custom static assets endpoint
},
});2. Create a PaymentIntent
Make a request to the endpoint on your server to create a new Payment. The clientSecret returned by your endpoint is used to initialize the payment session.
3. Initialize your Payment Session
Initialize a Payment Session by passing the clientSecret to the initPaymentSession
paymentIntentClientSecret (string)
Required. Required to use as the identifier of the payment.
4. Craft a customized payments experience
Using the paymentSession object, the default customer payment method data can be fetched, using which you can craft your own payments experience. The paymentSession object also exposes a confirmWithCustomerDefaultPaymentMethod and confirmWithLastUsedPaymentMethod function, using which you can confirm and handle the payment session.
4a. Confirm using Customer Default Payment Method:
Payload for confirmWithCustomerDefaultPaymentMethod(payload)
confirmParams (object)
Parameters that will be passed on to the Hyper API.
redirect (string)
Can be either 'always' or 'if_required'
By default, confirmWithCustomerDefaultPaymentMethod() will always redirect to your return_url after a successful confirmation. If you set redirect: "if_required", then this method will only redirect if your user chooses a redirection-based payment method.
id (string)(optional)
The id used when creating the CardCVCElement.
ConfirmParams object
return_url(string)
The url your customer will be directed to after they complete payment.
4b. Confirm using Last Used Payment Method:
Payload for confirmWithLastUsedPaymentMethod(payload)
confirmParams (object)
Parameters that will be passed on to the Hyper API.
redirect (string)
Can be either 'always' or 'if_required'
By default, confirmWithLastUsedPaymentMethod() will always redirect to your return_url after a successful confirmation. If you set redirect: "if_required", then this method will only redirect if your user chooses a redirection-based payment method.
id (string)(optional)
The id used when creating the CardCVCElement.
ConfirmParams object
return_url(string)
The url your customer will be directed to after they complete payment.
5. Add CVC Collection (Non PCI Approach)
The CardCVCElement renders a secure iframe to collect the customer's CVC without exposing sensitive data to your application. You can follow the React Integration.
Last updated
Was this helpful?

