Skip to content

PaymentSheet

Renders a secure tokenization form as a modal sheet. When the buyer submits the form, the SDK tokenizes the payment details and (optionally) runs 3D Secure, returning a PaymentSheetResponse via the onSuccess callback.

Function signature

@Composable
fun CompletePaymentSheet(
    configuration: PaymentSheetConfiguration,
    amount: Long,
    currency: String,
    onCancel: () -> Unit,
    onSuccess: (PaymentSheetResponse) -> Unit,
    onFailure: (FinixErrorCode) -> Unit,
    modifier: Modifier = Modifier,
)
ParameterTypeRequiredDescription
configurationPaymentSheetConfigurationYesApplication credentials, environment, and optional 3D Secure config. See PaymentSheetConfiguration.
amountLongYesTransaction amount in the smallest currency unit (e.g. cents for USD).
currencyStringYesISO 4217 currency code (e.g. "USD").
onCancel() -> UnitYesCalled when the buyer dismisses the sheet or taps cancel.
onSuccess(PaymentSheetResponse) -> UnitYesCalled with a PaymentSheetResponse on successful tokenization. When 3DS is enabled, the response's threeDSResponse is populated; otherwise it is null.
onFailure(FinixErrorCode) -> UnitYesCalled when tokenization or 3DS fails. Receives a FinixErrorCode describing the failure mode.
modifierModifierNoJetpack Compose modifier applied to the sheet container. Defaults to Modifier.

configuration

Pass a PaymentSheetConfiguration carrying your Finix Application ID, environment flag, and (optionally) a ThreeDSConfiguration to enable 3D Secure.

amount / currency

amount is the transaction amount in the smallest currency unit. currency is the ISO 4217 code the amount is denominated in.

onCancel / onSuccess / onFailure

The three required callbacks cover every terminal state of the sheet.

CallbackTriggerReceives
onCancelBuyer dismisses the sheet or taps the cancel buttonnothing
onSuccessTokenization completes (and 3DS succeeds if enabled)PaymentSheetResponse
onFailureTokenization or 3DS failsFinixErrorCode

Dismiss the sheet from all three callbacks to avoid leaving it open after interaction.

Full example

A complete implementation using PaymentSheetConfiguration, 3D Secure, and structured success/failure callbacks.

@Composable
fun CompletePaymentSheet(
    configuration: PaymentSheetConfiguration,
    amount: Long,
    currency: String,
    onCancel: () -> Unit,
    onSuccess: (PaymentSheetResponse) -> Unit,
    onFailure: (FinixErrorCode) -> Unit,
    modifier: Modifier = Modifier,
)

val configuration = PaymentSheetConfiguration(
    applicationId = "APt9MknRZxiDMkeReFPMdr7R",
    environment = PaymentSheetEnvironment.SANDBOX,
    merchantId = null,
    apiUsername = null,
    apiPassword = null,
    threeDSConfiguration = null,
)

CompletePaymentSheet(
    configuration = configuration,
    amount = 1000L,   // $10.00 in cents
    currency = "USD",
    onCancel = { },
    onSuccess = { },
    onFailure = { },
)

CompletePaymentSheet(
    configuration = configuration,
    amount = 1000L,
    currency = "USD",
    onCancel = {
        // buyer dismissed the sheet or tapped cancel
    },
    onSuccess = { response ->
        val tokenId = response.tokenizedResponse.id
        // forward tokenId to your backend to create a Payment Instrument
    },
    onFailure = { error ->
        // see /android/online/errors for FinixErrorCode variants
    },
)

CompletePaymentSheet(
    configuration = PaymentSheetConfiguration(
        applicationId = "APt9MknRZxiDMkeReFPMdr7R",
        environment = PaymentSheetEnvironment.SANDBOX,
        merchantId = "MUxxxxxxxx",
        apiUsername = "USxxxxxxxx",
        apiPassword = "your-api-password",
        threeDSConfiguration = ThreeDSConfiguration(
            isEnabled = true,
            redirectScheme = "myapp",
        ),
    ),
    amount = 1000L,
    currency = "USD",
    onCancel = { },
    onSuccess = { response ->
        val tokenId = response.tokenizedResponse.id
        val threeDsSessionId = response.threeDSResponse?.sessionId
        // forward tokenId (and threeDsSessionId when non-null) to your backend
    },
    onFailure = { error ->
        // surface error.message or branch on error type
    },
)