The Android Payment Sheet SDK includes built-in card scanning powered by the device camera and on-device ML Kit text recognition. When a user taps the scan button in the payment sheet, the SDK requests camera access, scans the card, and automatically populates the card number and expiry fields. No additional configuration is required.
Add camera permission
Add the following permission to your app's AndroidManifest.xml. The SDK handles the runtime permission request automatically, but the permission must be declared in your manifest or the OS will not grant access.
<uses-permission android:name="android.permission.CAMERA" />onScanCard
All payment sheet composables include an optional onScanCard callback. It is called when the user taps the scan button, before the scanner opens. Use it for analytics or logging — it does not affect scanning behavior.
| Parameter | Type | Required | Description |
|---|---|---|---|
onScanCard | () -> Unit | No | Called when the user initiates a card scan. Defaults to {}. |
Scanned card details are populated automatically. Results are returned through the existing onTokenized callback, the same as manual entry.
// AndroidManifest.xml
// <uses-permission android:name="android.permission.CAMERA" />
CompletePaymentSheet(
applicationId = "YOUR_APPLICATION_ID",
environment = PaymentSheetEnvironment.SANDBOX,
amount = 1000L,
onDismiss = { /* dismiss */ },
onCancel = { /* cancel */ },
onScanCard = {
// optional: log or track that the user initiated a card scan
},
onTokenized = { token ->
// token.id — use this to create a Payment Instrument via the Finix API
}
)