tokenizeCard

suspend fun tokenizeCard(foragePanEditText: ForagePANEditText, reusable: Boolean = true): ForageApiResponse<String>

Tokenizes a card via a ForagePANEdit Text Element.

  • On success, the object includes a ref token that represents an instance of a Forage PaymentMethod. You can store the token in your database and reference it for future transactions, like to call checkBalance or to create a Payment in Forage's database.

  • On failure, for example in the case of unsupported_bin, the response includes a list of ForageError objects that you can unpack to programmatically handle the error and display the appropriate customer-facing message based on the ForageError.code.

// Example tokenizeCard call in a TokenizeViewModel.kt
class TokenizeViewMode : ViewModel() {
val merchantId = "mid/<merchant_id>"
val sessionToken = "<session_token>"

fun tokenizeCard(foragePanEditText: ForagePANEditText) = viewModelScope.launch {
val response = forageTerminalSdk.tokenizeCard(
foragePanEditText = foragePanEditText,
reusable = true
)

when (response) {
is ForageApiResponse.Success -> {
// parse response.data for the PaymentMethod object
}
is ForageApiResponse.Failure -> {
// do something with error text (i.e. response.message)
}
}
}
}

Return

A ForageApiResponse object.

Parameters

foragePanEditText

Required. A reference to a ForagePANEditText instance that collects the customer's card number. setPosForageConfig must have been called on the instance before it can be passed.

reusable

Optional. A boolean that indicates whether the same card can be used to create multiple payments. Defaults to true.

Throws

If the PosForageConfig is not set for the provided ForagePANEditText instance.


Tokenizes a card via a magnetic swipe from a physical POS Terminal.

  • On success, the object includes a ref token that represents an instance of a Forage PaymentMethod. You can store the token for future transactions, like to call checkBalance or to create a Payment in Forage's database.

  • On failure, for example in the case of unsupported_bin, the response includes a list of ForageError objects that you can unpack to programmatically handle the error and display the appropriate customer-facing message based on the ForageError.code.

// Example tokenizeCard(PosTokenizeCardParams) call in a TokenizePosViewModel.kt
class TokenizePosViewModel : ViewModel() {
val merchantId = "mid/<merchant_id>"
val sessionToken = "<session_token>"

fun tokenizePosCard(foragePinEditText: ForagePINEditText) = viewModelScope.launch {
val response = forageTerminalSdk.tokenizeCard(
PosTokenizeCardParams(
forageConfig = ForageConfig(
merchantId = merchantId,
sessionToken = sessionToken
),
track2Data = "<read_track_2_data>" // "123456789123456789=123456789123",
// reusable = true
)
)

when (response) {
is ForageApiResponse.Success -> {
// parse response.data for the PaymentMethod object
}
is ForageApiResponse.Failure -> {
// do something with error text (i.e. response.message)
}
}
}
}

Return

A ForageAPIResponse object.

Parameters

params

Required. A PosTokenizeCardParams model that passes the PosForageConfig, the card's track2Data, and a reusable boolean that Forage uses to tokenize the card.

Throws

If the PosForageConfig is not set for the provided ForagePANEditText instance.