docs/api-reference/tutorials/adyen-integration-guide-for-android.mdx
The list of available library versions can be found on Official Adyen Documentation for Android integration Current newest version available at the moment of writing the tutorial is 5.13.1. This doc will be referring to the library version as YOUR_VERSION.
The integration consists of two main components:
Import the compatibility module:
implementation "com.adyen.checkout:drop-in-compose:YOUR_VERSION"
implementation "com.adyen.checkout:drop-in:YOUR_VERSION"
Create session using this endpoint.
val sessionModel = SessionModel.SERIALIZER.deserialize(sessionsResponseJSON)
sessionsResponseJSON should contain:
sessionData - available as adyen_data in payment_session API responseid - available as adyen_id in payment_session API responseval sessionModel = SessionModel.SERIALIZER.deserialize(sessionsResponseJSON)
call CheckoutSessionProvider.createSession passing serialized session data (sessionModel) and dropInConfiguration
dropInConfiguration example:
val checkoutConfiguration = CheckoutConfiguration(
environment = environment,
clientKey = clientKey,
shopperLocale = shopperLocale, // Optional
) {
// Optional: add Drop-in configuration.
dropIn {
setEnableRemovingStoredPaymentMethods(true)
}
// Optional: add or change default configuration for the card payment method.
card {
setHolderNameRequired(true)
setShopperReference("...")
}
// Optional: change configuration for 3D Secure 2.
adyen3DS2 {
setThreeDSRequestorAppURL("...")
}
}
environment - enum: live or test
clientKey - client_key from payment_sessions endpoint
shopperLocale - shopper locale in ISO format
// Create an object for the checkout session.
val result = CheckoutSessionProvider.createSession(sessionModel, dropInConfiguration)
// If the payment session is successful, handle the result.
// If the payment session encounters an error, handle the error.
when (result) {
is CheckoutSessionResult.Success -> handleCheckoutSession(result.checkoutSession)
is CheckoutSessionResult.Error -> handleError(result.exception)
}
override fun onDropInResult(sessionDropInResult: SessionDropInResult?) {
when (sessionDropInResult) {
// The payment finishes with a result.
is SessionDropInResult.Finished -> handleResult(sessionDropInResult.result)
// The shopper dismisses Drop-in.
is SessionDropInResult.CancelledByUser ->
// Drop-in encounters an error.
is SessionDropInResult.Error -> handleError(sessionDropInResult.reason)
// Drop-in encounters an unexpected state.
null ->
}
}
DropIn.startPayment, passing:
dropInLauncher - The Drop-in launcher objectcheckoutSession - result of CheckoutSessionProvider.createSessiondropInConfiguration - Your Drop-in configurationExample:
import com.adyen.checkout.dropin.compose.startPayment
import com.adyen.checkout.dropin.compose.rememberLauncherForDropInResult
@Composable
private fun ComposableDropIn() {
val dropInLauncher = rememberLauncherForDropInResult(sessionDropInCallback)
DropIn.startPayment(dropInLauncher, checkoutSession, dropInConfiguration)
}
backend will change the state of payment_session to one of the following state
pending - chosen payment method can take a while to completecompleted - payment resulted in success, order completedcanceled - payment canceled, payment is voidrefused - payment failedif succeed - order is processed and completed if failed - payment can be retried using new payment session