Dyneti Checkout Form Builder (Mobile)
Native checkout fields with a built-in DyScan card scanner. Card details are scanned or typed into fields owned by the SDK and sent straight from the device to your vault. Your app receives a token and never receives the raw card values.
How it works
- Vault integration. You choose where tokens are created by passing a vault config such as
BasisTheoryConfig. Every supported vault is included in the SDK. See Vault integrations. - Fields. You create the card fields you need (card number, expiry, CVV, name) and place them in your own layout. The card number field always has a button that opens the scanner.
- Orchestrator. The
DyScanCheckoutobject validates every attached field as the user types, lets the scanner fill them, tells your app when the form is ready to submit, and tokenizes onsubmit.
The SDK includes DyScan and every supported vault integration. Do not add the DyScan pod or package to your app separately.
iOS
Requirements
- iOS 15 or later / Xcode 16.2 or later
- A DyScan API key
- An account with a supported vault (see Vault integrations)
- The access token for the Dyneti package repository
Contact Dyneti to get a DyScan API key and the access token.
Installation
CocoaPods
Add the pod to your Podfile with the Dyneti repository URL. Your app's minimum iOS version must be 15 or later. use_frameworks!
is required.
platform :ios, '15.0'
use_frameworks!
target 'YourApp' do
pod 'DyScanCheckout',
:git => 'https://dyscan@github.com/Dyneti/dyscan-checkout-ios-distribution.git'
end
You do not add a source line: the pod comes directly from the repository URL. Without a :tag, CocoaPods installs the
latest release, and pod update DyScanCheckout moves to newer releases later. To pin a version, add
:tag => '1.0.0' (or the version you want). Then run:
$ pod install
When asked for a password for user dyscan, paste the access token that Dyneti provided.
If 2FA is set up on your GitHub account, this step may fail. In that case, generate a personal access token in GitHub (Settings > Developer settings > Personal access tokens) and use it as the password.
Swift Package Manager
-
In Xcode choose File > Add Package Dependencies.
-
Enter this URL:
https://dyscan@github.com/Dyneti/dyscan-checkout-ios-distribution.git -
When asked for a password for user
dyscan, enter your access token. -
Choose the dependency rule Up to Next Major Version.
-
Add the DyScanCheckout product to your app target.
Camera permission
Add NSCameraUsageDescription (Privacy - Camera Usage Description) to your Info.plist if your app does not already ask
for camera permission. The value is the text shown to the user, for example "To scan your credit card".
Quick start
Every integration has the same shape. Only the vault config changes. DyScanCheckout is @MainActor: call it from the main thread (the compiler enforces
this). Callbacks are delivered on the main thread. The fields are SwiftUI views that attach themselves to the checkout. DyScanCheckout is an
ObservableObject with a published state (a FormState), so a view that reads it updates as the form changes.
import SwiftUI
import DyScanCheckout
struct CheckoutView: View {
@StateObject private var checkout = DyScanCheckout(
dyscanApiKey: "<DYSCAN_API_KEY>",
backend: BasisTheoryConfig(btApiKey: "<BASIS_THEORY_PUBLIC_KEY>") // your vault's config
)
var body: some View {
VStack(spacing: 16) {
CardNumberFieldView(checkout: checkout)
HStack(spacing: 16) {
ExpiryFieldView(checkout: checkout)
CvvFieldView(checkout: checkout)
}
Button("Pay") {
Task {
do {
let token = try await checkout.submit() // runs on the main actor
print(token.token) // send this to your backend
} catch {
print(error)
}
}
}
.disabled(!checkout.state.canSubmit) // true when every field is filled and correct
}
.padding()
}
}
Building your form
Each field is a SwiftUI view that you place anywhere in your own layout. Include only the ones you need. Whatever is on screen is what the SDK validates and submits.
CardNumberFieldView(checkout: checkout) // card number only
Combine as many as you like:
NameFieldView(checkout: checkout)
CardNumberFieldView(checkout: checkout)
HStack {
ExpiryFieldView(checkout: checkout)
CvvFieldView(checkout: checkout)
}
Rules:
- The card number is always required. Show a
CardNumberFieldViewin every form. Your vault may require more fields (see Vault integrations).submitfails with.missingRequiredFieldsuntil they are shown. - A checkout holds one field of each type. Showing a second field of the same type replaces the first, which is cleared.
- A field attaches to the checkout when it appears and detaches (which clears it) when it leaves the screen. So do not put the fields in a
Listor a lazy stack: they remove rows that scroll off screen, and the user would find an empty field on scrolling back. Use aVStackinside aScrollView. - Fields you do not show are not validated and are not sent. Scanning, validation and form state work the same with any subset of fields that includes the card number.
You cannot read a field's value. The form state (checkout.state) exposes only whether each field is valid, empty or touched.
The same fields exist as UIKit views for apps that do not use SwiftUI: CardNumberField, ExpiryField, CvvField and NameField. Add them to your view
hierarchy, pass them to checkout.attach(...), and set checkout.presenter to your view controller so the scanner can open. Contact Dyneti for help with a UIKit
integration.
Field types
| View | Notes |
|---|---|
CardNumberFieldView | Shows the card network logo on the left and the scan button on the right. Formats as you type. |
ExpiryFieldView | Shown as MM / YY. With fourDigitYear: true, MM / YYYY. |
CvvFieldView | 4 digits for American Express, 3 digits for other cards. Until a card number is entered, 3 or 4 digits are valid. |
NameFieldView | Cardholder name. |
Field options
Options are parameters of each view's initializer:
CardNumberFieldView(checkout: checkout, placeholder: "Card number")
ExpiryFieldView(checkout: checkout, fourDigitYear: true) // MM / YYYY instead of MM / YY
CvvFieldView(checkout: checkout, style: myStyle)
CardNumberFieldView(checkout: checkout, firstSixPattern: "^(4|5)") // the first six digits must match a regular expression
| Option | Applies to | Meaning |
|---|---|---|
placeholder | all | Placeholder text. |
style | all | A FieldStyle (see Styling). |
fourDigitYear | ExpiryFieldView | Accept and show a four-digit year. The field is cleared when it changes. |
firstSixPattern | CardNumberFieldView | Regular expression the first six digits must match. |
Validation and submit readiness
DyScanCheckout validates each attached field as the user types and tells your app when the whole form is ready. submit refuses to run until the form is ready.
It throws .missingRequiredFields([...]) if a needed field is not
attached, and .invalidFields([...]) if some field is not valid. A failed submit keeps the field values so the user can
retry.
Styling
Every field view accepts a FieldStyle:
var style = FieldStyle()
style.fontSize = 17
style.fontColor = .label
style.backgroundColor = .systemBackground
style.placeholderFontColor = .secondaryLabel
style.borderColor = .separator
style.showBorder = true
style.fontFamily = "Avenir-Book"
style.height = 48
style.cornerRadius = 8
CvvFieldView(checkout: checkout, style: style)
Share one FieldStyle value across fields to make them match.
| Option | Default | Meaning |
|---|---|---|
showBorder | true | Draws a 1 point border around the field. |
height | 40 pt | Minimum height of the field. |
cornerRadius | 4 pt | Corner radius of the field. |
fontSize, fontColor, fontFamily | 16 pt, adapts to dark mode, system font | Text. Always scales with Dynamic Type, with a custom font family too. |
placeholderFontColor, backgroundColor, borderColor | adapt to dark mode | Field colors. |
validBorderColor, invalidBorderColor | off (nil) | Border color once the value is correct, and when the user leaves the field with an incorrect value. |
validTextColor, invalidTextColor | off (nil) | Text color once the value is correct, and when the user leaves the field with an incorrect value. |
Validation feedback is off until you set a color, and each of the four is independent: style.validBorderColor = .systemGreen.
The container around the fields (background, padding, spacing) is your own layout.
Defaults adapt to light and dark mode. Each field has a VoiceOver label ("Card number", "Expiration date", "Security code", "Name on card"), the card field announces the detected network, and the scan button is labeled "Scan card".
Submitting
let token = try await checkout.submit()
// or
checkout.submit { result in ... }
On success you receive a TokenPayload:
| Property | Meaning |
|---|---|
token | The vault's token. Send it to your backend. |
providerName | Which vault created it, for example "basis_theory". |
metadata | Non-sensitive details the vault returned (see your vault's section). |
formId | The id of the form that produced the token. Optional. |
firstSix | The first six digits of the card number. Optional. |
lastFour | The last four digits of the card number. Optional. |
expMonth | Expiry month, two digits. Optional: nil when no expiry field is attached. |
expYear | Expiry year, four digits. Optional: nil when no expiry field is attached. |
On success the SDK clears every field. A form that has produced a token cannot be submitted again until you call
reset().
checkout.reset() // clears the fields and starts a new form (new formId)
checkout.wipeSensitiveData() // clears the fields only
Errors
| Error | Meaning |
|---|---|
.invalidFields([FieldType]) | Some attached fields are not valid. The list says which. |
.missingRequiredFields([FieldType]) | The card number, or a field your vault needs, is not attached. |
.alreadySubmitted | This form already produced a token. Call reset() to start a new one. |
.submitInProgress | A request is already running. |
.scannerUnavailable | The scanner could not start, for example because the screen is already showing another one. |
.scanCancelled | The user closed the scanner, or reset() was called while it was open. |
.scanFailed(String) | The scanner reported an error (camera error, no permission, authentication error). |
.scanInProgress | A scan is already open. |
.provider(code, message) | The vault rejected the request. code is auth, validation, rateLimited, network, server or unknown. The message never contains card values. |
Vault integrations
Every supported vault is included in the SDK. You do not install anything extra: you choose a vault by passing its config when you create the checkout. Each section below lists the vault's keys, its configuration, the fields it needs, the token details it returns, and its own notes.
Basis Theory
Prerequisites
- A Basis Theory tenant. Use a test tenant while you integrate, with test card numbers such as
4242 4242 4242 4242. - A public application key with only the
token:createpermission. Never put a private or management key in an app. The SDK refuses keys that look private or management.
Setup
Pass BasisTheoryConfig as the backend:
import DyScanCheckout
let checkout = DyScanCheckout(
dyscanApiKey: "<DYSCAN_API_KEY>",
backend: BasisTheoryConfig(btApiKey: "<BASIS_THEORY_PUBLIC_KEY>"))
Options
| Option | Default | Meaning |
|---|---|---|
btApiKey | none (required) | Public application key (token:create only). |
requiredFields | number | Fields that must be shown before the form can be submitted. The card number is always required. |
Fields
Basis Theory only requires the card number, so submit works with whichever fields you show. The expiry and the CVV are sent when they are shown (Basis
Theory calls the CVV cvc). The cardholder name is not sent to Basis Theory.
To collect only the card number, show only the number field:
@StateObject private var checkout = DyScanCheckout(dyscanApiKey: "<DYSCAN_API_KEY>", backend: BasisTheoryConfig(btApiKey: "<BASIS_THEORY_PUBLIC_KEY>"))
var body: some View {
CardNumberFieldView(checkout: checkout)
}
To insist on more, so that submit fails with .missingRequiredFields when the expiry or the CVV is not shown, set requiredFields:
var vault = BasisTheoryConfig(btApiKey: "<BASIS_THEORY_PUBLIC_KEY>")
vault.requiredFields = [.number, .expiry, .cvv]
Result
token is the Basis Theory token id. metadata has last4, bin, brand, funding, expiration_month and
expiration_year.
Integrating with another vault
Contact Dyneti if the vault you tokenize with is not listed above.
Android
Requirements
- Android API level 21 or later
- Java 17 language level
- Jetpack Compose 1.8.0 (Compose BOM 2025.04.00) or later in your app
- An AndroidX
ComponentActivity(for exampleAppCompatActivity) that hosts your Compose screen - A DyScan API key
- An account with a supported vault (see Vault integrations)
- Nexus credentials
Contact Dyneti to get a DyScan API key and Nexus credentials.
Installation
In your project's settings.gradle, add the Dyneti Maven repository:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven {
credentials { username = "nexusUsername"; password = "nexusPassword" }
url = uri("https://nexus.dyneti.com/repository/maven-releases/")
authentication { basic(BasicAuthentication) }
}
}
}
Replace nexusUsername and nexusPassword with your Nexus credentials. Then add the dependency to your app module's
build.gradle. There is one artifact:
dependencies {
implementation "com.dyneti.android.checkout:dyscan-checkout:1.+"
}
1.+ installs the newest 1.x release each time Gradle resolves dependencies. To pin a version, use an exact one such as
1.0.0.
The checkout library depends on DyScan, so Gradle downloads it from the same repository. Do not add
com.dyneti.android.dyscan:dyscan yourself. If your app already declares it, remove that line, or keep it at exactly
the version the checkout library uses. When two versions are declared, Gradle uses the higher one.
The DyScan library ships its own ProGuard / R8 rules, so you do not need to add any.
Permissions
You do not need to declare any permission. The scanner's manifest declares camera, internet, vibrate and flashlight permissions, and Gradle merges them into your app. The scanner asks the user for camera permission the first time a scan starts.
Quick start
Call the SDK and read its properties from the main thread (the methods are annotated @MainThread). Callbacks are delivered on the main thread. The fields are
composables that attach themselves to the checkout, and rememberFormState returns the FormState as Compose State.
class CheckoutActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { CheckoutScreen() }
}
}
@Composable
fun CheckoutScreen() {
val checkout = remember {
DyScanCheckout(
dyscanApiKey = "<DYSCAN_API_KEY>",
backend = BasisTheoryConfig(btApiKey = "<BASIS_THEORY_PUBLIC_KEY>"),
)
}
val state by rememberFormState(checkout) // a new FormState on every change
val scope = rememberCoroutineScope()
Column(Modifier.padding(24.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
CardNumberFieldView(checkout)
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
ExpiryFieldView(checkout, Modifier.weight(1f))
CvvFieldView(checkout, Modifier.weight(1f))
}
Button(
enabled = state.canSubmit, // true when every field is filled and correct
onClick = {
scope.launch {
try {
val token = checkout.submit() // suspend function, resumes on the main thread
sendToBackend(token.token)
} catch (e: CheckoutException) {
Log.w("checkout", e) // e.error is a CheckoutError
}
}
},
) { Text("Pay") }
}
}
A callback form, checkout.submit { result -> ... }, is also available.
Building your form
Each field is a composable that you place anywhere in your own layout. Include only the ones you need. Whatever is in the composition is what the SDK validates and submits.
CardNumberFieldView(checkout) // card number only
Combine as many as you like:
NameFieldView(checkout)
CardNumberFieldView(checkout)
Row {
ExpiryFieldView(checkout, Modifier.weight(1f))
CvvFieldView(checkout, Modifier.weight(1f))
}
Rules:
- The card number is always required. Show a
CardNumberFieldViewin every form. Your vault may require more fields (see Vault integrations).submitfails withCheckoutError.MissingRequiredFieldsuntil they are shown. - A checkout holds one field of each type. Showing a second field of the same type replaces the first, which is cleared.
- A field attaches to the checkout while it is in the composition and detaches (which clears it) when it leaves, so do not put the fields in a
LazyColumn: it removes rows that scroll off screen, and the user would find an empty field on scrolling back. Use a normalColumn, insideverticalScrollif it must scroll. If you pass a differentcheckoutto a field, the field is rebuilt, which clears it. - Fields you do not show are not validated and are not sent. Scanning, validation and form state work the same with any subset of fields that includes the card number.
You cannot read a field's value. The form state exposes only whether each field is valid, empty or touched.
The same fields exist as classic views for apps that do not use Compose: CardNumberField, ExpiryField, CvvField and NameField in
com.dyneti.android.checkout. Use them in an XML layout (with the attributes dyscanPlaceholder, dyscanFourDigitYear and dyscanFirstSixPattern), pass them
to checkout.attach(...), and set checkout.activity to your activity in onCreate so the scanner can open. Contact Dyneti for help with an XML integration.
Field types
| Composable | Notes |
|---|---|
CardNumberFieldView | Shows the card network logo on the left and the scan button on the right. Formats as you type. |
ExpiryFieldView | Shown as MM / YY. With fourDigitYear = true, MM / YYYY. |
CvvFieldView | 4 digits for American Express, 3 digits for other cards. Until a card number is entered, 3 or 4 digits are valid. |
NameFieldView | Cardholder name. |
Field options
Each composable takes the checkout, then an optional Modifier, then the options:
CardNumberFieldView(checkout, placeholder = "Card number")
ExpiryFieldView(checkout, fourDigitYear = true) // MM / YYYY instead of MM / YY
CvvFieldView(checkout, style = myStyle)
CardNumberFieldView(checkout, firstSixPattern = "^(4|5)") // the first six digits must match a regular expression
| Option | Applies to | Meaning |
|---|---|---|
placeholder | all | Placeholder text. |
style | all | A FieldStyle (see Styling). |
fourDigitYear | ExpiryFieldView | Accept and show a four-digit year. The field is cleared when it changes. |
firstSixPattern | CardNumberFieldView | Regular expression the first six digits must match. |
Validation and submit readiness
DyScanCheckout validates each attached field as the user types and tells your app when the whole form is ready.
submit refuses to run until the form is ready. It throws a CheckoutException whose error is CheckoutError.MissingRequiredFields(fields) if a needed
field is not attached, and CheckoutError.InvalidFields(fields) if some field is not valid. A failed submit keeps the field values so the user can retry.
Styling
Every field composable accepts a FieldStyle:
val style = FieldStyle(
fontSize = 17f,
fontColor = ContextCompat.getColor(context, R.color.text),
backgroundColor = ContextCompat.getColor(context, R.color.surface),
placeholderFontColor = ContextCompat.getColor(context, R.color.hint),
borderColor = ContextCompat.getColor(context, R.color.border),
showBorder = true,
fontFamily = "sans-serif-medium",
height = 48,
cornerRadius = 8,
)
CvvFieldView(checkout, style = style)
FieldStyle is immutable: change it with copy(...) and assign the result. Share one FieldStyle value across fields to make them match.
| Option | Default | Meaning |
|---|---|---|
showBorder | true | Draws a 1 dp border around the field. |
height | 40 dp | Minimum height of the field. |
cornerRadius | 4 dp | Corner radius of the field. |
fontSize, fontColor, fontFamily | 16 sp, adapts to dark mode, system font | Text. fontSize is in sp, so it follows the user's font size setting. fontFamily is anything Typeface.create(family, NORMAL) understands. |
placeholderFontColor, backgroundColor, borderColor | null: adapt to dark mode | Field colors, as @ColorInt Int?. |
validBorderColor, invalidBorderColor | off (null) | Border color once the value is correct, and when the user leaves the field with an incorrect value. |
validTextColor, invalidTextColor | off (null) | Text color once the value is correct, and when the user leaves the field with an incorrect value. |
Validation feedback is off until you set a color, and each of the four is independent: FieldStyle(validBorderColor = ContextCompat.getColor(context, R.color.success)).
The container around the fields (background, padding, spacing) is your own layout.
Defaults adapt to light and dark mode. Each field has a TalkBack label ("Card number", "Expiration date", "Security code", "Name on card"), the card field
announces the detected network, and the scan button is labeled "Scan card". The labels are string resources (dyscan_checkout_number_label and the like) that you
can override in your own strings.xml, for example to localize them.
Submitting
val token = checkout.submit() // suspend function
// or
checkout.submit { result -> ... } // result is a Result<TokenPayload>
submit() is a suspend function: call it from lifecycleScope, viewModelScope or rememberCoroutineScope(), which run on the main thread. It is not
cancellable: once started it returns when the vault answers, so a token that was created is never lost.
On success you receive a TokenPayload:
| Property | Meaning |
|---|---|
token | The vault's token. Send it to your backend. |
providerName | Which vault created it, for example "basis_theory". |
metadata | Non-sensitive details the vault returned (see your vault's section). |
formId | The id of the form that produced the token. Nullable. |
firstSix | The first six digits of the card number. Nullable. |
lastFour | The last four digits of the card number. Nullable. |
expMonth | Expiry month, two digits. Nullable: null when no expiry field is attached. |
expYear | Expiry year, four digits. Nullable: null when no expiry field is attached. |
On success the SDK clears every field. A form that has produced a token cannot be submitted again until you call
reset().
checkout.reset() // clears the fields and starts a new form (new formId)
checkout.wipeSensitiveData() // clears the fields only
The SDK also clears the fields when your app goes to the background.
Errors
A failed submit throws a CheckoutException (or is the failure of the callback's Result). Its error is a CheckoutError:
| Error | Meaning |
|---|---|
CheckoutError.InvalidFields(fields) | Some attached fields are not valid. The list says which. |
CheckoutError.MissingRequiredFields(fields) | The card number, or a field your vault needs, is not attached. |
CheckoutError.AlreadySubmitted | This form already produced a token. Call reset() to start a new one. |
CheckoutError.SubmitInProgress | A request is already running. |
CheckoutError.ScannerUnavailable | The scanner could not start: no activity is set (for the XML views, set checkout.activity), or the activity is finishing or destroyed. |
CheckoutError.ScanCancelled | The user closed the scanner or chose manual entry, or reset() was called or the activity was destroyed while it was open. |
CheckoutError.ScanFailed(message) | The scanner reported an error. message is one of auth_error, camera_error, no_permissions, scan_log_error or unknown. |
CheckoutError.ScanInProgress | A scan is already open. |
CheckoutError.Provider(code, message) | The vault rejected the request. code is Auth, Validation, RateLimited, Network, Server or Unknown. The message never contains card values. |
Vault integrations
Every supported vault is included in the library. You do not add anything extra: you choose a vault by passing its config when you create the checkout. Each section below lists the vault's keys, its configuration, the fields it needs, the token details it returns, and its own notes.
Basis Theory
Prerequisites
- A Basis Theory tenant. Use a test tenant while you integrate, with test card numbers such as
4242 4242 4242 4242. - A public application key with only the
token:createpermission. Never put a private or management key in an app. The SDK refuses keys that look private or management.
Setup
Pass BasisTheoryConfig as the backend:
val checkout = DyScanCheckout(
dyscanApiKey = "<DYSCAN_API_KEY>",
backend = BasisTheoryConfig(btApiKey = "<BASIS_THEORY_PUBLIC_KEY>"))
Options
| Option | Default | Meaning |
|---|---|---|
btApiKey | none (required) | Public application key (token:create only). |
requiredFields | setOf(FieldType.Number) | Fields that must be shown before the form can be submitted. The card number is always required. |
Fields
Basis Theory only requires the card number, so submit works with whichever fields you show. The expiry and the CVV are sent when they are shown (Basis
Theory calls the CVV cvc). The cardholder name is not sent to Basis Theory.
To collect only the card number, show only the number field:
CardNumberFieldView(checkout)
To insist on more, so that submit fails with CheckoutError.MissingRequiredFields when the expiry or the CVV is not shown, set requiredFields:
val vault = BasisTheoryConfig(
btApiKey = "<BASIS_THEORY_PUBLIC_KEY>",
requiredFields = setOf(FieldType.Number, FieldType.Expiry, FieldType.Cvv))
Result
token is the Basis Theory token id. metadata has last4, bin, brand, funding, expiration_month and
expiration_year.
Integrating with another vault
Contact Dyneti if the vault you tokenize with is not listed above.