Kotlin with Node Integration

Integrate hyper SDK to your Kotlin App using hyperswitch-node

Demo App

You can use this demo app as a reference with your Hyperswitch credentials to test the setup.

Requirements

1. Setup the server

Follow the Server Setup section.

2. Build checkout page on your app

2.1 Add the Buildscript Classpath

To start integrating the Hyperswitch SDK, add the following classpath to the buildscript block of your project-level build.gradle file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.hyperswitch:hyperswitch-gradle-plugin:"
    }
}

2.2 Add the Buildscript Classpath

Add the following plugin to the plugins block of your app-level build.gradle file:

plugins {
    // Apply Hyperswitch Plugin
    id 'io.hyperswitch.plugin'
}

2.3 Configure the SDK

Configure the Hyperswitch SDK in your app-level build.gradle file. You can specify the main SDK version and enable optional features:

hyperswitch {
    // Optional: Specify main SDK version (defaults to latest if not specified)
    sdkVersion = "1.1.5"
    
    // Optional features - only add what you need
    enablePaypal = true
    enableKount = true
    enableScanCard = true
    enableKlarna = true
    enableNetcetera3ds = true
    enableSamsungPay = true
    
    // Optional: Override individual feature versions (uses recommended versions if not specified)
    paypalVersion = "0.0.6"
    kountVersion = "0.0.6"
    // scanCardVersion = "0.0.6"  // Will use recommended version
}

2.4 Implement the HyperInterface

Next, implement the HyperInterface in your CheckoutActivity. This involves extending FragmentActivity and implementing the HyperInterface:

class CheckoutActivity : AppCompatActivity(), HyperInterface {
    // ...
}

2.5 Setup the SDK and fetch a Payment

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

val paymentSession = PaymentSession(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 will use this secret to complete the payment process.

3. Complete the payment on your app

Initialise Payment Session

Initialise the payment session with the client_secret:

paymentSession.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
paymentSession.presentPaymentSheet(configuration, ::onPaymentSheetResult)

Final Step

Congratulations! You have successfully integrated the Hyperswitch Android SDK into your app. You can now customize the payment sheet to match the look and feel of your app.

Next step:

Setup Payment Methods

Last updated

Was this helpful?