Client-Side Implementation

Get the SDKAnchorIcon

Add the following in your app-level build.gradle:

  1. Kotlin
  2. Groovy
dependencies { implementation("com.braintreepayments.api:card:5.2.0") }
  1. Groovy
dependencies { implementation 'com.braintreepayments.api:card:4.49.1' }

InitializationAnchorIcon

Collect card data from your UI to construct a Card. Then, create a CardClient with a Tokenization Key or Client Token and call tokenize() to get a nonce that can be sent to your server:

  1. Kotlin
class MyActivity : AppCompatActivity() { private fun tokenizeCard() { val card = Card( number = "4111111111111111", expirationMonth = "12", expirationYear = "2028", cvv = "123" ) val cardClient = CardClient( context = this, authorization = "[TOKENIZATION_KEY or CLIENT_TOKEN]" ) cardClient.tokenize(card) { cardResult -> when (cardResult) { is CardResult.Success -> { // send cardResult.nonce.string to your server } is CardResult.Failure -> { // handle error } } } } }
Collect card data from your UI to construct a Card. Then, create a BraintreeClient with a ClientTokenProvider or Tokenization Key. Construct a CardClient and call tokenize to get a nonce that can be sent to your server:
  1. Kotlin
  2. Java
class MyActivity: AppCompatActivity() { private lateinit var braintreeClient: BraintreeClient private lateinit var cardClient: CardClient private fun tokenizeCard() { val card = Card() card.number = "4111111111111111" card.expirationDate = "09/2018" braintreeClient = BraintreeClient(this, ExampleClientTokenProvider()) cardClient = CardClient(braintreeClient) cardClient.tokenize(card) { cardNonce, error -> // send cardNonce.string to your server } } }