Android

Integrate Hyperswitch Lite SDK to your Kotlin App

Key Features of Lite SDK

Lightweight Integration

  • Smaller bundle size: 282.84 KB

  • Faster initialization: Streamlined setup process

  • Web-based UI: Uses web components for payment forms

  • Reduced dependencies: Minimal impact on app size

  • Shared Configuration: The Lite SDK the same PaymentSheet.Configuration options as the main SDK, including:

    • Appearance customization

    • Billing details

    • Shipping information

    • Payment method preferences

    • Branding options

Requirements

1. Setup the server

Follow the Server Setup section.

2. Build checkout page on your app

2.1 Add the Dependency

Add the Hyperswitch Lite SDK dependency to your app-level build.gradle file:

dependencies {
    implementation 'io.hyperswitch:hyperswitch-sdk-android-lite:+'
}

2.2 Setup the Lite SDK and fetch a Payment

Set up the Lite SDK using your publishable key. This is essential for initializing a PaymentSession:

import io.hyperswitch.lite.PaymentSession as PaymentSessionLite

val paymentSessionLite = PaymentSessionLite(applicationContext, "YOUR_PUBLISHABLE_KEY")

Fetch a Payment

Request your server to fetch a payment as soon as your view is loaded. Store the client_secret returned by your server. The PaymentSession (Lite) will use this secret to complete the payment process.

3. Complete the payment on your app

Initialize Payment Session

Initialize the payment session with the client_secret:

paymentSessionLite.initPaymentSession(paymentIntentClientSecret)

Handle Payment Result

Handle the payment result in the completion block. Display appropriate messages to your customer based on the outcome of the payment:

private fun onPaymentSheetResult(paymentResult: PaymentSheetResult) {
    when (paymentResult) {
        is PaymentSheetResult.Completed -> {
            showToast("Payment complete!")
        }
        is PaymentSheetResult.Canceled -> {
            Log.i(TAG, "Payment canceled!")
        }
        is PaymentSheetResult.Failed -> {
            showAlert("Payment failed", paymentResult.error.localizedMessage)
        }
    }
}

Present the Payment Page

Create a configuration object to customize the payment sheet and present the payment page:

val configuration = PaymentSheet.Configuration("Your_app, Inc.")

// Present Payment Page (Lite SDK)
paymentSessionLite.presentPaymentSheet(configuration, ::onPaymentSheetResult)

Final Step

Congratulations! You have successfully integrated the Hyperswitch Lite SDK into your app. The Lite SDK provides the same powerful payment processing capabilities with a smaller footprint, making it ideal for apps where bundle size is a concern.

Next step:

Setup Payment Methods

Last updated

Was this helpful?