For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Fetch a customer's saved payment methods without rendering any UI, and even confirm one-click payments headlessly.

Customize the payment experience using Headless functions

1. Initialize the Hyperswitch SDK

Initialize Hyperswitch once using your publishable key and profile ID. Reuse the same initialized instance throughout your application.

import { Hyperswitch } from "@juspay-tech/react-native-hyperswitch";

const hyperPromise = Hyperswitch.init({
      publishableKey: 'pk_snd_xxxxxxxx',   // from Hyperswitch dashboard
      profileId: 'pro_xxxxxxxx',           // your profile id
      // environment: 'SANDBOX',           // 'PROD' (default) | 'SANDBOX' | 'INTEG'
    });

2 Get sdk_authorization from your Backend

Call your payment-creation endpoint. Its JSON response must contain sdk_authorization.

const response = await fetch('https://your-server.com/create-payment-intent', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ amount: 6500, currency: 'USD', customer_id: 'cust_123' }),
});

const { sdk_authorization } = await response.json();

Important: Never include your Hyperswitch secret API key in the React Native application. The payment must be created from your backend.

3. Initialize your Payment Session or useHook inside HyperElements

Create a payment session by passing the latest sdk_authorization returned by your backend to initPaymentSession.

4. Get the Customer Saved Cards

Each returns a CustomerLastUsedPaymentMethod | null, e.g.:

Typical pattern (from the example flow): if lastUsed?.payment_method === 'card' and requires_cvv, show CardCVCElement to collect CVC, then confirm headlessly.

4.1 Headless confirm (one-click payment)

The id must reference a mounted CardCVCElement, as the native SDK uses its CVC value to complete the payment confirmation. The method returns a PaymentResult, identical to the one returned by the PaymentElement.

Last updated

Was this helpful?