Kotlin
Use this guide to integrate Doo Payment SDK to your Android app. You can use the following app demo as a reference with your Doo Payment credentials to test the setup.
Requirements
- Android 10.0 (API level 29) and above
- Android Gradle Plugin 7.3.1
- Gradle 7.5.1+
- AndroidX
1. Build checkout page on your app
1.1 Add the Doo Payment dependency
To start integrating the Doo Payment SDK, add the following dependency to the dependencies
block of your build.gradle
file:
dependencies {
// Doo Payment Android SDK
implementation 'io.hyperswitch:hyperswitch-sdk-android:+'
}
1.2 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");
PaymentSession needs to be initialised in onCreate method of your FragmentActivity
For an open-source setup, use the following parameters:
val paymentSession = PaymentSession(applicationContext, "YOUR_PUBLISHABLE_KEY", "YOUR_CUSTOM_BACKEND_URL", "YOUR_CUSTOM_LOG_URL")
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.
2. 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 Doo Payment Android SDK into your app. You can now customize the payment sheet to match the look and feel of your app.