Cards & Wallets · Mobile SDK · UI Components

Save Card box

The SaveCardBox component
The SaveCardBox component

The SaveCardBox component is used to determine whether the user wants to save their card details.

It is optional and can be replaced by your own implementation, which should call PaymentProcessor.setSaveCard to set the switch state and PaymentProcessor.canSaveCards to check whether the user can save the card.

Parameters

ParameterDescription
modifierThe modifier to be applied to the layout.
fontSizeThe font size of the text.
fontWeightThe font weight of the text.
defaultStateThe default state of the switch.

Example usage

Compose Multiplatform

Kotlin
SaveCardBox(
  modifier = Modifier,
  fontSize = 16.sp,
  fontWeight = ComponentFontWeight.BOLD,
  defaultState = false,
)

Android View

XML
<com.accesspaysuite.mobilesdk.ui.save.SaveCardView
  android:id="@+id/saveCards"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />
Kotlin
val saveCards = findViewById<SaveCardView>(R.id.saveCards)
saveCards.init(
  state = SaveCardState(),
  onCheck = { isChecked ->
      // Handle the switch state change
  }
)

iOS

Create the controller representable
Swift
import SwiftUI
import mobilesdk

struct SaveCardBoxControllerRepresentable: UIViewControllerRepresentable {

  @Binding var state: SaveCardState

  init(state: Binding) {
      self._state = state
  }

  func makeUIViewController(context: Context) -> UIViewController {
      return SaveCardBoxController().make()
  }

  func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
      SaveCardBoxController().update(state: state)
  }
}
Create the SaveCardsBox view
Swift
import SwiftUI
import mobilesdk

struct SaveCardsBox: View {

  @Binding var state: SaveCardsState

  init(state: Binding) {
      self._state = state
  }

  var body: some View {
      SaveCardBoxControllerRepresentable(state: $state)
  }
}
Use the SaveCardsBox view
Swift
import SwiftUI
import mobilesdk

struct PaymentView: View {

  @State private var state = SaveCardsState()

  var body: some View {
      SaveCardsBox(
          state: $state
      )
  }
}