This guide is aimed at advanced users who want to create adyen integration for their custom android application.
You also need to install Spree Adyen extension before.
Note
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.
Resources
Overview
The integration consists of two main components:
- Spree Adyen: Provides API for your client and receive payment result from Adyen
- Your Android client app: Shows the Drop-in UI and handles payment flow
Step 1: Import the library
Import the compatibility module:
Import the module with Jet Compose
implementation "com.adyen.checkout:drop-in-compose:YOUR_VERSION"
Import without Jet Compose
implementation "com.adyen.checkout:drop-in:YOUR_VERSION"
Step 2: Create a checkout session
Create session using this endpoint.
val sessionModel = SessionModel.SERIALIZER.deserialize(sessionsResponseJSON)
sessionsResponseJSON should contain:
sessionData - available as adyen_data in payment_session API response
id - available as adyen_id in payment_session API response
val sessionModel = SessionModel.SERIALIZER.deserialize(sessionsResponseJSON)
Step 3
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("...")
}
}
see also: https://docs.adyen.com/online-payments/build-your-integration/sessions-flow/?platform=Web&integration=Drop-in&version=6.18.1#create-instance
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)
}
Step 4: Launch and show Drop-in
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 ->
}
}
Step 5: Create the Drop-in launcher
DropIn.startPayment, passing:
dropInLauncher - The Drop-in launcher object
checkoutSession - result of CheckoutSessionProvider.createSession
dropInConfiguration - Your Drop-in configuration
Example:
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)
}
Get payment outcome
- Wait for backend to process the payment
- Continue shopping experience
1. Wait for backend to process the payment
backend will change the state of payment_session to one of the following state
pending - chosen payment method can take a while to complete
completed - payment resulted in success, order completed
canceled - payment canceled, payment is void
refused - payment failed
if succeed - order is processed and completed
if failed - payment can be retried using new payment session